How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Parser Library Dll
How to start using .net pdf document parser dll in winforms, web application


To Have Quick Evaluation of .NET XDoc.PDF SDK in Visual C# Console Application











As a leading professional third-party SDK supplier in the field of image and document management, RasterEdge has always been devoted to providing various effective and fully-functional imaging solutions for developers who are working on different .NET developing applications.

This C#.NET PDF document processing toolkit, RasterEdge XDoc.PDF SDK for .NET is one of the most strongly-featured and mature document imaging library toolkits on the market, which is designed to help developers implement PDF-related tasks in their C#.NET applications.

Using this C#.NET PDF document processor control, you can easily and quickly complete PDF document creating and loading, PDF document conversion, PDF content redaction, PDF document annotation, PDF document protection and more in any type of a 32-bit or 64-bit .NET application, including ASP.NET web service and Windows Forms for any .NET Framework version from 2.0 to 4.5.

As you know, there're various reliable PDF document processing features that can be implemented in C#.NET programming. And you may want to have a quick testing on RasterEdge XDoc.PDF after downloading its free trial package online.  To meet your requirement, on this quick to start page, we will tell how to create a C# console application, merge two PDF files, and save into a new PDF file.





A 'Hello World' example using C#


String outputFilePath = @"C:\output.pdf";

//  Create an empty PDF document with 1 page.
PDFDocument doc = PDFDocument.Create(1);
//  Add text "Hello World" at position (100, 100) in the 1st page.
PDFTextMgr mgr = PDFTextHandler.ExportPDFTextManager(doc);
//  First page with page index 0.
int pageIndex = 0;
//  Start location 100, 100. Unit: pixel (in 96 dpi)
PointF position = new PointF(100F, 100F);
//  Set text font.
System.Drawing.Font textFont = new System.Drawing.Font("Arial", 16F, FontStyle.Regular);
//  Set text color.
System.Drawing.Color textColor = System.Drawing.Color.Red;
//  Add text.
mgr.AddString("Hello World", textFont, pageIndex, position, textColor);
//  Save to file
doc.Save(outputFilePath);




Create a complex PDF document


String imageFilePath = @"C:\1.bmp");
String outputFilePath = @"C:\output.pdf";

//  Initial a Document object.
Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);

//  Open document
document.Open();

//  Add a new paragraph with content "This is the 1st page.".
document.Add(new Paragraph("This is the 1st page."));

//  Add a new page and move current position to the next page
document.NewPage();

//  Add a new paragraph with content "This is the 2nd page.".
document.Add(new Paragraph("This is the 2nd page."));

//  Add a new paragraph with content "Sample: add an image.".
document.Add(new Paragraph("Sample: add an image."));
//  Load an image from the source file.
RasterEdge.XDoc.PDF.Builder.Image image = new RasterEdge.XDoc.PDF.Builder.Image(imageFilePath);
//  Add the image to the document.
document.Add(image);

//  Add a new paragraph.
document.Add(new Paragraph("Image Width: " + image.Width + " pt.; Image Height: " + image.Height + " pt."));

//  Add a new paragraph with content "Sample: add a table.".
Paragraph p = new Paragraph("Sample: add a table.");
//  Set before paragraph spacing to 100 points.
p.SpaceBefore = 100;
//  Set after paragraph spacing to 20 points.
p.SpaceAfter = 20;
document.Add(p);

//  Initial a table with 4 columns (4 cells per row)
PdfPTable table = new PdfPTable(4);

//  Add cell to the 1st row
table.AddCell("Row 1, Cell 1");     //  1st cell
table.AddCell("Row 1, Cell 2");     //  2nd cell
table.AddCell("Row 1, Cell 3");     //  3rd cell
table.AddCell("Row 1, Cell 4");     //  4th cell
//  Finish remained columns of the current row, do nothing
//  if there is no remained cell in the row.
table.CompleteRow();

//  Add cell to the 2nd row
table.AddCell("");                  //  1st cell is empty
table.AddCell("Row 2, Cell 2");     //  2nd cell
table.AddCell("");                  //  3rd cell is empty
//  Finish remained columns of the current row.
table.CompleteRow();

//  Add cell to the 2nd row
table.AddCell("");                  //  1st cell is empty
table.AddCell("");                  //  2nd cell is empty
table.AddCell("Row 3, Cell 3");     //  3rd cell
//  Finish remained columns of the current row
table.CompleteRow();

//  Add the table to the document.
document.Add(table);

//  Close document and save to the output file
document.Close();




Create PDF


String outputFilePath = @"C:\output.pdf";

//  Create an empty PDF document with 1 page.
PDFDocument doc = PDFDocument.Create(1);
//  Add text "Hello World" at position (100, 100) in the 1st page.
PDFTextMgr mgr = PDFTextHandler.ExportPDFTextManager(doc);
//  First page with page index 0.
int pageIndex = 0;
//  Start location 100, 100. Unit: pixel (in 96 dpi)
PointF position = new PointF(100F, 100F);
//  Set text font.
System.Drawing.Font textFont = new System.Drawing.Font("Arial", 16F, FontStyle.Regular);
//  Set text color.
System.Drawing.Color textColor = System.Drawing.Color.Red;
//  Add text.
mgr.AddString("Hello World", textFont, pageIndex, position, textColor);
//  Save to file
doc.Save(outputFilePath);




Load PDF


String inputFilePath = @"C:\1.pdf";

//  Create a PDF document object from the file path.
PDFDocument doc = new PDFDocument(inputFilePath);
//  Get page count of the PDF file.
Console.WriteLine("Page Count: {0}", doc.GetPageCount());


String inputFilePath = @"C:\1.pdf";

//  Load a file into MemoryStream.
byte[] dataBytes = File.ReadAllBytes(inputFilePath);
MemoryStream stream = new MemoryStream(dataBytes, 0, dataBytes.Length);

//  Create a PDF document object from the stream.
PDFDocument doc = new PDFDocument(stream);
//  Get page count of the PDF file.
Console.WriteLine("Page Count: {0}", doc.GetPageCount());


String inputFilePath = @"C:\1.pdf";
String encryptedFile = @"C:\encryptFile.pdf";

//  Create an encrypted PDF file from a PDF file.
String userPassword = "1234";
String ownerPassword = "5678";
PasswordSetting psw = new PasswordSetting(userPassword, ownerPassword);
PDFDocument.AddPassword(inputFilePath, encryptedFile, psw);

//  Open the encrypted PDF file by using user password
PDFDocument doc1 = new PDFDocument(encryptedFile, userPassword);
//  Get page count of the PDF file.
Console.WriteLine("Page Count: {0}", doc1.GetPageCount());

//  Open the encrypted PDF file by using owner password
PDFDocument doc2 = new PDFDocument(encryptedFile, ownerPassword);
//  Get page count of the PDF file.
Console.WriteLine("Page Count: {0}", doc2.GetPageCount());




Save PDF


String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.pdf";
Bitmap resImage = new Bitmap(@"C:\1.png");

//  Create a PDF document object from the file path.
PDFDocument doc = new PDFDocument(inputFilePath);

//  Modify the document ...
//  Insert an empty page before the 2nd page.
doc.AddEmptyPage(1);
//  Get the new 2nd page (page index is 1).
PDFPage page = (PDFPage)doc.GetPage(1);
//  Add an image at location (100, 100).
page.AddImage(resImage, new PointF(100, 100));

//  Save the modified document to file.
doc.Save(outputFilePath);


String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.pdf";
Bitmap resImage = new Bitmap(@"C:\1.png");

//  Load a file into MemoryStream.
byte[] dataBytes = File.ReadAllBytes(inputFilePath);
using (MemoryStream inStream = new MemoryStream(dataBytes, 0, dataBytes.Length))
{
    //  Create a PDF document object from the stream.
    PDFDocument doc = new PDFDocument(inStream);

    //  Modify the document ...
    //  Insert an empty page before the 2nd page.
    doc.AddEmptyPage(1);
    //  Get the new 2nd page (page index is 1).
    PDFPage page = (PDFPage)doc.GetPage(1);
    //  Add an image at location (100, 100).
    page.AddImage(resImage, new PointF(100, 100));

    using (MemoryStream outStream = new MemoryStream())
    {
        //  Save the modified document to stream.
        doc.SaveToStream(outStream);
                        
        //  Save data bytes in the MemoryStream to file.
        File.WriteAllBytes(outputFilePath, outStream.ToArray());
    }                    
}