officefileapi-118794-pdf-document-api-document-generation.md
This topic describes how to generate a document layout from scratch.
Create a PdfDocumentProcessor object and call one of the PdfDocumentProcessor.CreateEmptyDocument overload methods. This method creates an empty PDF file with no pages.
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
// Create an empty document
processor.CreateEmptyDocument("..\\..\\Result.pdf");
}
Using processor As PdfDocumentProcessor = New PdfDocumentProcessor()
' Create an empty document.
processor.CreateEmptyDocument("..\..\Result.pdf")
End Using
Populate a document with graphic content:
Create a PdfGraphics objectusing one of the PdfDocumentProcessor.CreateGraphics*System methods. Each method creates a graphics context based on a specific coordinate system (page, user, or world).
Call the Draw method for corresponding elements (for example, the PdfGraphics.DrawString overload method draws a text string at the specified location with the specified SolidBrush and Font objects).
Render a page with created graphics by calling the PdfDocumentProcessor.RenderNewPage overload method.
View Example: Generate a Document Layout from Scratch
using DevExpress.Drawing;
using DevExpress.Pdf;
using System.Drawing;
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.
DXSolidBrush black = (DXSolidBrush)DXBrushes.Black;
DXFont font1 = new DXFont("Times New Roman", 32, DXFontStyle.Bold);
graph.DrawString("PDF Document Processor", font1, black, 180, 150);
DXFont font2 = new DXFont("Arial", 20);
graph.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230);
DXFont font3 = new DXFont("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);
}
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Imports System.Drawing
Using processor As PdfDocumentProcessor = 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
Private Shared Sub DrawGraphics(ByVal graph As PdfGraphics)
' Draw text lines on the page.
Dim black As DXSolidBrush = CType(DXBrushes.Black, DXSolidBrush)
Dim font1 As DXFont = New DXFont("Times New Roman", 32, DXFontStyle.Bold)
graph.DrawString("PDF Document Processor", font1, black, 180, 150)
Dim font2 As DXFont = New DXFont("Arial", 20)
graph.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230)
Dim font3 As DXFont = New DXFont("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 Sub
See the following topic for more information on PDF Graphics: PDF Graphics
The PDF Document API provides additional settings to customize document generation. See the sections below.
The PDF Document API component creates a document with embedded fonts by default.
To prohibit embedding all fonts, set the PdfCreationOptions.DisableEmbeddingAllFonts property to true and pass a PdfCreationOptions object containing this setting as a parameter to one of the PdfDocumentProcessor.CreateEmptyDocument overload methods.
Use the PdfCreationOptions.NotEmbeddedFontFamilies property to specify which font families should not be embedded in a document.
Tip
If you get the No usable version of the ICU libraries was found Aborted message when you try to run your application on Linux, register the DXEXPORT_ICU_VERSION_OVERRIDE environment variable and set it to the current library version, as shown below:
export DXEXPORT_ICU_VERSION_OVERRIDE=65.1?
The following compatibility modes are supported:
To create a PDF/A-compatible document, set the PdfCreationOptions.Compatibility property to either PdfCompatibility.PdfA1b, PdfCompatibility.PdfA2b or PdfCompatibility.PdfA3b. Then, call the PdfDocumentProcessor.CreateEmptyDocument overload method and pass a PdfCreationOptions object containing this setting as a parameter.
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
processor.CreateEmptyDocument("..\\..\\Result.pdf", new PdfCreationOptions()
{
Compatibility = PdfCompatibility.PdfA2b
});
}
Imports (PdfDocumentProcessor processor = New PdfDocumentProcessor())
{
Private Function PdfCreationOptions() As processor.CreateEmptyDocument("..\\..\\Result.pdf",Shadows
Compatibility = PdfCompatibility.PdfA2b
End Function
)
}
PDF/A has the following limitations:
The PDF Document API can protect a document with user and owner passwords. These passwords are used to prevent users from accessing or modifying PDF documents. All required settings to protect a document are contained in the PdfEncryptionOptions object, which can be accessed via the PdfSaveOptions.EncryptionOptions property. To encrypt the document with these settings, call the PdfDocumentProcessor.CreateEmptyDocument overload method and pass the PdfSaveOptions object containing these settings as a parameter. See the Document Protection topic for more information.
Use the PdfSaveOptions.Signature property to specify a signature. See the Sign Document topic to learn more.
See Also
How to: Generate a PDF Document Layout with a Watermark from Scratch