PDF Toolkit

Samples

Create a PDF document

Create a PDF document from scratch and add some text and metadata in it

This Code sample requires the PDF Toolkit and is found in: C:\Aquaforest\PDF Toolkit\samples\CreatePDF


using Aquaforest.PDF;
using Aquaforest.PDF.Font;
using System;
    
namespace CreatePDF
{
    class Program
    {
        // Create a PDF document
        static void Main(string[] args)
        {
            PDFDocument doc = new PDFDocument();
            PDFPage page = new PDFPage();
    
            // Add text to page
            PDFPageContentStream contents = new PDFPageContentStream(doc, page);
            contents.BeginText();
            contents.SetFont(PDFType1Font.COURIER_BOLD, 12);
            contents.MoveText(100, 700);
            contents.DrawString("Hello World!");
            contents.EndText();
            contents.Close();
    
            // Add metadata
            PDFDocumentInformation info = new PDFDocumentInformation()
            {
                Author = "Name Surname",
                Subject = "Test",
                Title = "New PDF",
                Keywords = "PDF, OCR, SDK",
                CreationDate = new DateTime(2013, 9, 9),
                Producer = "Aquaforest"
            };
            info.SetCustomMetadataValue("AQUAFOREST_PDF_TOOLKIT", "1.01");
            doc.SetDocumentInformation(info);
                
            // Add page to PDF document
            doc.AddPage(page);
    
            doc.Save(@"..\..\..\documents\output\pdf_out.pdf");
            doc.Close();
        }
    }
}