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 Generator Library
How to create PDF files in C# ASP.NET, Windows applications

Step by step tutorials to generate PDF files from scratch or other files using C# in .NET ASP.NET, Windows application

In the following list of C# tutorials, you will learn how to create a PDF file programmatically in your C# ASP.NET Web application and Windows application.

  • Generate PDF from Microsoft Office Word, Excel, PowerPoint, Open Office document and rtf, csv, text files
  • Create PDF from multipage TIFF image file or JPG, PNG, bitmap raster image files
  • Generate PDFs from scratch or template with table, paragraph, image, page header & footer, acroform supported

How to create a PDF file programmatically using C#

  1. Download XDoc.PDF Generator C# library
  2. Install C# library to create PDF report file
  3. Step by Step Tutorial

How to generate PDF from other existing files using C#?

Create PDF from Word

In your C# projects, you could easily create PDF file from Microsoft Word document using C#.NET code.

            //convert .docx to .pdf
            DOCXDocument doc = new DOCXDocument(@"C:\demo.docx");
            doc.ConvertToDocument(DocumentType.PDF, @"C:\output.pdf");

Create PDF from multi-page TIFF image file

The C# source code below shows how to generate PDF from multipage TIFF image file. One TIFF page will produce one PDF page.

            TIFFDocument doc = new TIFFDocument(@"C:\demo.tif");
            doc.ConvertToDocument(DocumentType.PDF, @"C:\output.pdf");

Create PDF from image files

You can also generate scanned PDF file from multiple image files.

            Bitmap bmp = new Bitmap(@"C:\demo.jpg");
            List<Bitmap> images = new List<Bitmap>();
            PDFDocument doc = new PDFDocument(images.ToArray());

Create PDF from Open Office files

Create PDF from Open Office document is an easy job using XDoc.PDF C# library. The C# code below will teach how to generate PDF from a .odt file in C# application.

            ODTDocument doc = new ODTDocument(@"C:\demo.odt");
            doc.ConvertToDocument(DocumentType.PDF, @"C:\output.pdf");

Create PDF from Text file

            DocumentConverter.ToDocument(@"C:\demo.txt", @"C:\output.pdf", FileType.DOC_PDF);

Create PDF from CSV

            CSVDocument doc = new CSVDocument(@"C:\demo.csv");
            doc.ConvertToDocument(DocumentType.PDF, @"C:\output.pdf");

Create PDF from RTF

            RTFDocument doc = new RTFDocument(@"C:\demo.rtf");
            doc.ConvertToDocument(DocumentType.PDF, @"C:\output.pdf");

How to generate a PDF report from scratch using C#?

XDoc.PDF for .NET includes a utility class "PDFBuildHandler". You can easily build a PDF file from scratch with class PDFBuildHandler. Like the Microsoft Word document, you can fill in pdf content one by one using PDFBuildHandler. You can easily generate a PDF report file from database. It support text, image, table, listing, chapter, section, Header and Footer, Footnote and Endnote, and Acroform fields.

  1. Create a new PDF file: Create a new pdf file with empty content

  2. Add a paragraph: Add a text paragraph to the new pdf file

  3. Use Font: Create text with font applied

  4. Add an image: Add images to the pdf file

  5. Add a list of text: Add list of text to the pdf document

  6. Add a table: Add a table

  7. Use table template: Use designed table template to add tables to the pdf document

  8. Add a chapter and section: Add chapters and sections to the pdf content

  9. Create Page Header and Footer: Create PDF Page Header and Footer content

  10. Add Footnote and Endnote: Add Footnote and Endnote

  11. Generate form fields: Generate AcroForm fileds, and insert to the PDF document

How to generate a new PDF from existing PDF files in C#?

Merge multiple PDF files

You can generate a new PDF file from multiple existing PDFs.

            String[] inputFilePaths = new String[3] { @"C:\1.pdf", @"C:\2.pdf", @"C:\3.pdf" };

            PDFDocument.CombineDocument(inputFilePaths, @"C:\output-merged-pdf-file.pdf");

Extract pages from existing PDF files

You can also create a new PDF file based on the pages from other existing PDF file.

            PDFDocument doc = new PDFDocument(@"C:\1.pdf");

            List<int> pageIndexes = new List<int>();
            pageIndexes.Add(2);   // The 3rd page.
            pageIndexes.Add(0);   // The 1st page.
            pageIndexes.Add(3);   // The 4th page.

            PDFDocument newDoc = (PDFDocument)doc.GetMultiDocument(pageIndexes);



Using XDod.PDF C# library, you can easily create Adobe PDF files.

  1. Create PDFs from other existing documents, such as Microsoft Office Word, Excel, PowerPoint files, TIFF image file, text, rtf, csv file and JPG, PNG raster image files.
  2. Create PDF from scratch or from template
  3. Create PDF from existing PDF files