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.
The ZIP package also contains all sample projects, and the file with the license agreement.
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 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 package from NuGet instead of adding the DLL manually.
To create PDF documents using the layout engine, add the reference to the BitMiracle.Docotic.Pdf.Layout extension DLL. The engine automatically splits content to pages and provides support for page headers and footers, tables, and paragraphs. You can find the DLL in the ZIP package but we recommend to install the BitMiracle.Docotic.Pdf.Layout package from NuGet instead of adding the DLL manually.
using BitMiracle.Docotic.Pdf;
In VB.NET use this:
Imports BitMiracle.Docotic.Pdf
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,
});
}
For a VB.NET project use this
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
helloPdf()
method from your code. This should produce hello.pdf file and open it in your
default PDF viewer.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.