Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.1
  • Create Your First PDF Document with the New PDF Document API

    • 8 minutes to read

    Important

    You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this library in production code.

    Follow this tutorial to get started with the DevExpress PDF Document API for .NET and .NET Framework.

    Create a .NET Application

    1. Start Visual Studio and create a new Console Application project.

    2. Install the DevExpress.Docs.Pdf package.

    Read Tutorial: Choose Between Offline and Online DevExpress NuGet Feeds

    Create a .NET Framework Application

    1. Start Visual Studio and create a new Console Application (.NET Framework) project.

    2. Install the DevExpress.Docs.Pdf package, or add references to the following libraries if you installed the products with the DevExpress Unified Component Installer:

      • DevExpress.Docs.Pdf.v26.1.dll
      • DevExpress.Data.v26.1.dll
      • DevExpress.Drawing.v26.1.dll
      • DevExpress.Printing.v26.1.Core.dll
      • DevExpress.Office.v26.1.Core.dll
      • DevExpress.Docs.Core.v26.1.dll

    Create an Empty PDF Document

    Paste the following code into the Program.Main() method to create a new empty PDF document:

    using DevExpress.Docs.Pdf;
    
    namespace DxPdfGetStarted;
    
    public class Program {
        public static void Main(string[] _) {
            // Create a new PDF document.
            using (PdfDocument pdfDocument = new PdfDocument()) {
            }
        }
    }
    

    Add a Page

    Call the PageCollection.Add method to add a page to the document. You can specify a standard paper size or custom dimensions.

    // Proceed with the code from the previous step...
    // Add an A4 page to the document.
    Page page = pdfDocument.Pages.Add(DXPaperKind.A4);
    

    For more information about page operations, refer to the following help topic: Organize Pages.

    Add Text

    Call the Page.AddTextFragment method to add text to the page. You can pass a simple string with coordinates, or create a TextFragment object to specify font, size, and other formatting options.

    The following code snippet adds a title and a paragraph to the page:

    // Proceed with the code from the previous step...
    // Add a title.
    page.AddTextFragment(new TextFragment
    {
        Text = "Quarterly Sales Report",
        Location = new PointF(50, 770),
        Font = new TextFont("Arial", TextFontStyle.Bold),
        FontSize = 24
    });
    
    // Add a paragraph.
    page.AddTextFragment(new TextFragment
    {
        Text = "This report summarizes sales data " +
            "for Q1 2026.",
        Location = new PointF(50, 730),
        Font = new TextFont("Arial"),
        FontSize = 12
    });
    

    For more information about content operations, refer to the following help topic: Add Content to Pages.

    Add an Image

    Call the Page.AddImageFragment method to add an image to the page. Create an ImageFragment object and specify the image source and position.

    // Proceed with the code from the previous step...
    // Add an image.
    DXImage logo = DXImage.FromFile("logo.png");
    page.AddImageFragment(new ImageFragment(logo)
    {
        Location = new PointF(50, 600),
        Size = new SizeF(200, 100)
    });
    

    Add a Second Page

    Add another page and populate it with content to create a multi-page document:

    // Proceed with the code from the previous step...
    // Add a second page.
    Page page2 = pdfDocument.Pages.Add(DXPaperKind.A4);
    
    page2.AddTextFragment(new TextFragment
    {
        Text = "Sales Breakdown by Region",
        Location = new PointF(50, 770),
        Font = new DXFont("Arial", 18),
        Bold = true
    });
    
    page2.AddTextFragment(new TextFragment
    {
        Text = "North America: $1,250,000",
        Location = new PointF(50, 730),
        Font = new TextFont("Arial"),
        FontSize = 12
    });
    
    page2.AddTextFragment(new TextFragment
    {
        Text = "Europe: $980,000",
        Location = new PointF(50, 710),
        Font = new TextFont("Arial"),
        FontSize = 12
    });
    
    page2.AddTextFragment(new TextFragment
    {
        Text = "Asia Pacific: $670,000",
        Location = new PointF(50, 690),
        Font = new TextFont("Arial"),
        FontSize = 12
    });
    

    Save the Document

    Call the PdfDocument.Save method to save the document to a file:

    // Proceed with the code from the previous step...
    using (FileStream outputStream =
        File.Create("SalesReport.pdf"))
    {
        pdfDocument.Save(outputStream);
    }
    

    The resulting PDF document looks like this:

    A sample PDF document created with the DevExpress PDF Document API

    Complete Code Sample

    The following code snippet contains the complete code sample:

    using DevExpress.Docs.Pdf;
    
    namespace DxPdfGetStarted;
    
    public class Program {
        public static void Main(string[] _) {
            // Create a new PDF document.
            using (PdfDocument pdfDocument = new PdfDocument()) {
                // Add an A4 page to the document.
                Page page = pdfDocument.Pages.Add(DXPaperKind.A4);
    
                // Add a title.
                page.AddTextFragment(new TextFragment
                {
                    Text = "Quarterly Sales Report",
                    Location = new PointF(50, 770),
                    Font = new TextFont("Arial", TextFontStyle.Bold),
                    FontSize = 24
                });
    
                // Add a paragraph.
                page.AddTextFragment(new TextFragment
                {
                    Text = "This report summarizes sales data " +
                        "for Q1 2026.",
                    Location = new PointF(50, 730),
                    Font = new TextFont("Arial"),
                    FontSize = 12
                });
    
                // Add an image.
                DXImage logo = DXImage.FromFile("logo.png");
                page.AddImageFragment(new ImageFragment(logo)
                {
                    Location = new PointF(50, 600),
                    Size = new SizeF(200, 100)
                });
    
                // Add a second page.
                Page page2 = pdfDocument.Pages.Add(DXPaperKind.A4);
    
                page2.AddTextFragment(new TextFragment
                {
                    Text = "Sales Breakdown by Region",
                    Location = new PointF(50, 770),
                    Font = new DXFont("Arial", 18),
                    Bold = true
                });
    
                page2.AddTextFragment(new TextFragment
                {
                    Text = "North America: $1,250,000",
                    Location = new PointF(50, 730),
                    Font = new TextFont("Arial"),
                    FontSize = 12
                });
    
                page2.AddTextFragment(new TextFragment
                {
                    Text = "Europe: $980,000",
                    Location = new PointF(50, 710),
                    Font = new TextFont("Arial"),
                    FontSize = 12
                });
    
                page2.AddTextFragment(new TextFragment
                {
                    Text = "Asia Pacific: $670,000",
                    Location = new PointF(50, 690),
                    Font = new TextFont("Arial"),
                    FontSize = 12
                });
    
                // Save the document.
                using (FileStream outputStream =
                    File.Create("SalesReport.pdf"))
                {
                    pdfDocument.Save(outputStream);
                }
            }
        }
    }
    

    Next Steps

    For more information about the DevExpress PDF Document API for .NET, refer to the following help topics:

    Add Content to Pages
    Add text, images, and other content to PDF pages.
    Organize Pages
    Add, delete, reorder, and rotate pages in a PDF document
    Print PDF Documents
    Print PDF documents from your application