THotPDF.BeginDoc Method

 

THotPDF.BeginDoc

THotPDF

 

Top  Previous  Next

Creates new document

 

Delphi syntax:

procedure BeginDoc ( Initial: boolean = false );

 

C++ syntax:

void __fastcall BeginDoc ( bool Initial = false );

 

Description

BeginDoc starts a new PDF document and creates the first page. In normal usage, call BeginDoc with the default parameter value and then draw on CurrentPage.

A single THotPDF instance can write any number of documents, one after another. EndDoc writes the file and then releases everything that belonged to it: pages, images, fonts, form fields, outlines, document JavaScript, named destinations, page labels, ICC profiles, output intents and the remaining registered resources. The next BeginDoc starts from a clean document, so no content of the previous file carries over into the next one

Properties such as FileName, Version, Compression, PDFACompliance, Author and Title keep their values for the next document, as do page layers, font fallback chains and variable-font axis selections. Anything registered after EndDoc and before the next BeginDoc — for example an output intent added with AddPDFAOutputIntent or a script added through Names — belongs to the next document. CurrentPageNumber, PagesCount and the layout diagnostics of the written document stay readable until the next BeginDoc

EndDoc clears UserPassword and OwnerPassword. Whilst ActivateProtection remains on, set the passwords again before the next BeginDoc; otherwise BeginDoc raises an exception rather than writing a document protected by empty passwords. When a feature of one document raised the PDF version automatically (for example to PDF 1.4 for an output intent), EndDoc puts it back to the value of the Version property

 

Code Example


HPDF := THotPDF.Create( nil );
try
  HPDF.FileName := '.\Output.pdf';
  HPDF.BeginDoc;   // Start PDF document creation
  HPDF.CurrentPage.TextOut( 100, 100, 0, 'Hello World!' );
  HPDF.EndDoc;     // Finish and save PDF document

  HPDF.FileName := '.\Second.pdf';
  HPDF.BeginDoc;   // Same instance, new independent document
  HPDF.CurrentPage.TextOut( 100, 100, 0, 'Second document' );
  HPDF.EndDoc;
finally
  HPDF.Free;
end;

 

See also: EndDoc