Pdfium.Net SDKPdfium.NET SDK it's a class library based on the PDFium project for viewing, text extracting, navigating and editing PDF files in your .NET projects. Compatibility Pdfium.Net SDK is available for .Net Framework 2.0 - 4.5 on 32 and 64-bit operating systems. SDK has been tested with Windows XP, Vista, 7, 8 and 8.1, and is fully compatible with all of them. The native PDFium.dll library included in this project is a 32-bit and 64-bit version, so your .NET application can be "Any CPU". Getting Started Pdfium.NET SDK provides a number of components to work with PDF files:
ExamplesThe following code example demonstrates how to load PDF document into PdfView control, select all text on same page and extract selected text.
This example requires that you have added the PdfView control to a Form and call the method created in the example from the constructor or another method on the form. The example also requires that pdf document named Test001.pdf are located in the root directory of drive C. public void LoadDocument(){ //Initialize the SDK library //You have to call this function before you can call any PDF processing functions. PdfCommon.Initialize(); //Sets the background color for the control. pdfView1.BackColor = SystemColors.ControlDarkDark; //Open and load a PDF document from a file. pdfView1.LoadDocument(@"c:\test001.pdf"); //Gets the current page pdfView1.CurrentPage = 1; //Selects all text contained in current page. pdfView1.SelectText(0, -1); //Gets selected text from PdfView control string selectedText = pdfView1.SelectedText;} You can work with pdf documents without using any GUI elements. The following code example demonstrates how extract all text from any pdf page without using PdfView control. This example requires that pdf focument named Test001.pdf are located in the root directory of drive C. public void ExtractText(){ //Initialize the SDK library //You have to call this function before you can call any PDF processing functions. PdfCommon.Initialize(); //Open and load a PDF document from a file. var doc = PdfDocument.Load(@"c:\test001.pdf"); //Gets second page from document; var page = doc.Pages[1]; //Gets number of characters in a page or -1 for error. //Generated characters, like additional space characters, new line characters, are also counted. int totalCharCount = page.Text.CountChars; //Extract text string from the page string text = page.Text.GetText(0, totalCharCount);} You can render pdf page as an image to use it in graphical mode. public void RenderPage(){ //Initialize the SDK library //You have to call this function before you can call any PDF processing functions. PdfCommon.Initialize(); //Open and load a PDF document from a file. var doc = PdfDocument.Load(@"c:\test001.pdf"); //Gets second page from document; var page = doc.Pages[1]; //Gets page width and height measured in points. One point is 1/72 inch (around 0.3528 mm) int width = (int)page.Width; int height = (int)page.Height; //Create a bitmap using(var bmp = new Bitmap(width, height)) { //create drawing surface using(var g = Graphics.FromImage(bmp)) { //Render contents in a page to a drawing surface specified by a coordinate pair, a width, and a height. page.Render(g, 0, 0, width, height, Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_ANNOT); } }} The following code example demonstrates how to create new PDF document, import some pages from existing PDF document and save created document to a file. This example requires that pdf focument named Test001.pdf are located in the root directory of drive C. The example also requires that you have write permissions for the root of drive C. public void ImportPages(){ //Initialize the SDK library //You have to call this function before you can call any PDF processing functions. PdfCommon.Initialize(); //Open and load a PDF document from a file. var docSource = PdfDocument.Load(@"c:\test001.pdf"); //Create a new PDF document. var doc = PdfDocument.CreateNew(); //Import some pages to a PDF document. doc.Pages.ImportPages(docSource, "1,5-7", 0); //Saves a copy of PDF document to the specified file name doc.Save(@"c:\test002.pdf", Patagames.Pdf.Enums.SaveFlags.Incremental);} DownloadsTo download the latest Pdfium.Net SDK release, visit the download page. |