Back to Devexpress

PdfDocumentProcessor.CreateEmptyDocument() Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-86fd9623.md

latest5.3 KB
Original Source

PdfDocumentProcessor.CreateEmptyDocument() Method

Creates an empty PDF document with no pages.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void CreateEmptyDocument()
vb
Public Sub CreateEmptyDocument

Remarks

Use this method to create an empty document. You can use the document creation API to generate the document layout (e.g., append pages with graphics to the PDF document, generate bookmarks, and attach files) Refer to the following article for more information: Document Generation.

Note

The PDF specification does not describe empty documents. For this reason, most third-party PDF viewers cannot open such files. This does not apply to the DevExpress WinForms PDF Viewer and WPF PDF Viewer, which are less demanding concerning the validity of opened documents, and are capable of opening documents containing no pages.

Example

View Example

csharp
using DevExpress.Pdf;
using System;
using System.Drawing;

static void Main(string[] args)
{
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Create an empty document.
        processor.CreateEmptyDocument("..\\..\\Result.pdf");

        // Create and draw PDF graphics.
        using (PdfGraphics graph = processor.CreateGraphicsPageSystem())
        {
            DrawGraphics(graph);

            // Render a page with graphics.
            processor.RenderNewPage(PdfPaperSize.Letter, graph);
        }
    }
}

static void DrawGraphics(PdfGraphics graph)
{

    // Draw text lines on the page.
    SolidBrush black = (SolidBrush)Brushes.Black;
    using (Font font1 = new Font("Times New Roman", 32, FontStyle.Bold))
    {
        graph.DrawString("PDF Document Processor", font1, black, 180, 150);
    }
    using (Font font2 = new Font("Arial", 20))
    {
        graph.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230);
    }
    using (Font font3 = new Font("Arial", 10))
    {
        graph.DrawString("The PDF Document Processor is a non-visual component " +
                            "that provides the application programming interface of the PDF Viewer.", font3, black, 16, 300);
    }
}
vb
Imports DevExpress.Pdf
Imports System
Imports System.Drawing

Shared Sub Main(ByVal args() As String)

    Using processor As New PdfDocumentProcessor()

        ' Create an empty document.
        processor.CreateEmptyDocument("..\..\Result.pdf")

        ' Create and draw PDF graphics.
        Using graph As PdfGraphics = processor.CreateGraphicsPageSystem()
            DrawGraphics(graph)

            ' Render a page with graphics.
            processor.RenderNewPage(PdfPaperSize.Letter, graph)
        End Using
    End Using
End Sub

Private Shared Sub DrawGraphics(ByVal graph As PdfGraphics)

    ' Draw text lines on the page.
    Dim black As SolidBrush = CType(Brushes.Black, SolidBrush)
    Using font1 As New Font("Times New Roman", 32, FontStyle.Bold)
        graph.DrawString("PDF Document Processor", font1, black, 180, 150)
    End Using
    Using font2 As New Font("Arial", 20)
        graph.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230)
    End Using
    Using font3 As New Font("Arial", 10)
        graph.DrawString("The PDF Document Processor is a non-visual component " & "that provides the application programming interface of the PDF Viewer.", font3, black, 16, 300)
    End Using
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateEmptyDocument() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

office-file-api-in-web-api-app/CS/Controllers/PdfController.cs#L48

csharp
using (PdfDocumentProcessor tempProcessor = new PdfDocumentProcessor()) {
    tempProcessor.CreateEmptyDocument();
    tempProcessor.Document.Pages.Add(processor.Document.Pages[i]);

See Also

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace