This article explains some of the basics to get you up and running to process PDF files in your WinForms, console or ASP.NET applications with Docotic.Pdf library.
The easiest way to get started is to install the BitMiracle.Docotic.Pdf package from NuGet.
Please refer to this quickstart article if you are new to NuGet Manager.
Download the latest release of the Docotic.Pdf library from our site. The library is distributed as a ZIP package.
The ZIP package contains two versions of the library:
The ZIP package also contains help file, all sample projects, and the file with the license agreement.
Extract the downloaded ZIP package to a location of your choice.
Docotic.Pdf samples are located in the Samples folder of the ZIP package. Open SamplesCSharp solution file if you want to use sample code written in C# language. For a VB.NET version please open the SamplesVB.NET solution file.
The same sample code can be cloned or downloaded from our samples repository on GitHub.
Please take a time to review the samples. It should help you to add PDF processing features to your application.
Open Visual Studio IDE. Create a new project or open existing one.
Open the Add Reference dialog and add a reference to BitMiracle.Docotic.Pdf.dll.
Please note that you can add a NuGet reference to BitMiracle.Docotic.Pdf instead of referencing its DLL manually.
To access methods and properties that provide interoperability with types from the System.Drawing namespace and GDI+ you would need to add a reference to the BitMiracle.Docotic.Pdf.Gdi extension DLL. You can find the DLL in the ZIP package or install BitMiracle.Docotic.Pdf.Gdi NuGet package from NuGet.
To convert HTML to PDF (or SVG to PDF) you would need to add a reference to the BitMiracle.Docotic.Pdf.HtmlToPdf extension DLL. The DLL is also in the ZIP package but we recommend to install the BitMiracle.Docotic.Pdf.HtmlToPdf NuGet package from NuGet instead of adding the DLL manually.
To avoid typing full references to the dll, it is best to add following using statement to the already existing ones in your source file
using BitMiracle.Docotic.Pdf;
Imports BitMiracle.Docotic.Pdf
Add the following method to your application source code
private static void helloPdf() { // replace string.Empty with your license key BitMiracle.Docotic.LicenseManager.AddLicenseData(string.Empty); string outputName = "hello.pdf"; // in ASP.NET application please use following line instead: // string outputName = Server.MapPath("hello.pdf"); using (PdfDocument pdf = new PdfDocument()) { // draws "Hello world" on the first page PdfPage firstPage = pdf.Pages[0]; firstPage.Canvas.DrawString(20, 20, "Hello world!"); pdf.Save(outputName); } // opens saved document in default PDF viewer System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = outputName, UseShellExecute = true, }); }
Private Shared Sub helloPdf() ' replace string.Empty with your license key BitMiracle.Docotic.LicenseManager.AddLicenseData(String.Empty) Dim outputName As String = "hello.pdf" ' in ASP.NET application please use the following line instead: ' Dim outputName As String = Server.MapPath("hello.pdf") Using pdf As New PdfDocument() ' draws "Hello world" on the first page Dim firstPage As PdfPage = pdf.Pages(0) firstPage.Canvas.DrawString(20, 20, "Hello world!") pdf.Save(outputName) End Using ' opens saved document in the default PDF viewer System.Diagnostics.Process.Start( New ProcessStartInfo() With { .FileName = outputName, .UseShellExecute = True } ) End Sub
Call helloPdf() method from your code. This should produce hello.pdf file and open it in default PDF viewer.
Conclusion
Now you should be able to develop PDF-related features in your applications using Docotic.Pdf library. This is only the beginning, however. We encourage you to read through the documentation accompanying the library and review samples. You might also want to check out the Bit Miracle blog .