New Forum | Previous | Next | (P-PDF) Developers
Topic: Adding new text to PDF file from Visual Basic
Conf: (P-PDF) Developers, Msg: 82068
Date: 2/25/2003 11:02 PM
I am looking for a VB code example, illustrating a simple way to add arbitrary text at specified positions in a PDF file, using a specified font type and size (e.g. 12-point Courier-Bold), without using Acrobat Forms.
This limitation arises from the fact that forms cannot be used for making multipage documents, each containing different data for the same form, as fields are not automatically renamed when new copies of the same form are added to the PDF document, so that you end up with a number of identical forms with identical data.
Suppose, for example, you have a database table, containing a list of names and addresses of employees, and you want to create a multipage PDF document, where each page contains the name and address of a different employee.
Ideally, you might follow these steps:
a) start up Acrobat;
b) create a new, single-page PDF document, named "Master.pdf";
c) create the following fields: "FirstName", "SecondName", "Address";
d) save the file as "Master.pdf";
e) save a copy of this file as "Addresses.pdf";
f) open both documents in separate PDDoc objects from VB code;
g) create an AcroForm object;
g) read field values for the first employee into the AcroForm Fields;
h) insert the AcroForm page into the second PDF object;
i) repeat the two previous steps for each employee;
j) save the destination file.
The final result is a document with as many pages as the total number of employees plus one (as you started up with a single page, containing an empty form), each containing the same data, i.e. name and address of the last employee.
This is because you have many copies of same form, with identically-named fields, and you have no means to rename fields incrementally in run-time (which is the only way to resolve the omonimity problem).
Therefore, each time you assign a new value to a specific field, say "Address", you are actually updating all occurrences of that field (one per page).
Unfortunately, you cannot create a multipage form with unique name fields (i.e. "Name1" at page 1, "Name2" at page2, etc.), as this would be an endless job, and you might not know in advance how many forms are needed (i.e. the actual number of employees in the table at run-time).
I suppose the only possible solution is not to use AcroForms, but write data text directly into the target document, after mapping the document field positions to a record array, so you know exactly where to write each field data.
Unfortunately, I was unable to produce this behaviour with VB code (in fact, I was unable to locate the PDFEdit and PDEText objects too, which I assume are the required building bricks).
Anyone who can help?