
Adobe Acrobat SDK
Inserting Text into PDF Documents
Developing Plug-ins and Applications
Creating a new PDF document 63
Creating a new PDF document
You can programmatically create a new PDF document by invoking the
PDDocCreate
method. This
method returns a
PDDoc
object that only contains one COS object, which is a Catalog. For information
about COS objects, see
“Working with Cos Objects” on page 178
.
The following code example creates a
PDDoc
object by invoking
PDDocCreate
method.
Example 4.1
Creating a new PDF document
PDDoc pdDoc ;
pdDoc = DDocCreate();
Creating a new page
You can create a new page by invoking the
PDDocCreatePage
method. However, before invoking this
method, set the page size by creating an
ASFixedRect
object, which represents a rectangle region that
specifies the page size. After you declare an
ASFixedRect
object, you can specify the page size by setting
the
ASFixedRect
object’s
left
,
top
,
right
, and
bottom
attributes.
Next, invoke the
PDDocCreatePage
method and pass the following arguments:
●
A
PDDoc
object that was created.
●
An
ASInt32
value that specifies the page number after which the new page is inserted. Specify
PDBeforeFirstPage
to insert the new page at the beginning of the PDF document.
●
An
ASFixedRect
object that specifies the page size.
This method returns a
PDPage
object. The following code example creates a new page, sets it size, and
inserts it into the PDF document represented by the
PDDoc
object.
Example 4.2
Creating a new page
PDPage pdPage;
ASFixedRect mediaBox;
//Set the page size
mediaBox.left = fixedZero;
mediaBox.top = Int16ToFixed(4*72);
mediaBox.right = Int16ToFixed(5*72);
mediaBox.bottom = fixedZero;
//Create a page and insert it as the first page
PDPagepdPage = PDDocCreatePage(pdDoc, PDBeforeFirstPage, mediaBox);
Creating a container
To insert text into a PDF document, you must create a PDF container. A container contains the modifiable
contents of a PDF page. To create a PDF container, invoke the
PDPageAcquirePDEContent
method and
pass the following arguments:
●
A
PDPage
object.
●
An
ASExtension
object that represents the caller. If you invoke this method from a PDF Library
project, you can pass
NULL
. In contrast, if you invoke this method from a plug-in, you would pass the
gExtensionID
extension.
The
PDPageAcquirePDEContent
method returns a
PDEContent
object, as shown in the following
code example.