Using the PDFDocumentService to write to an already existing PDF

Date:2 May 2007
Product/Release:LANSA Integrator
Abstract:Using the PDFDocumentService to write to an already existing PDF.
Submitted By:LANSA Technical Support

How do I write to an already existing PDF document. It doesn't matter how the PDF was created. It could have been created using a third party tool or even the LANSA Integrator itself. What do I need to do to overwrite/amend/add text to the existing PDF document.

Details:

There are 2 aspects to this.

1. The LANSA RDML function will be used dynamically set a field value. The value will be some piece of text (static or dynamic) that the user wishes to insert in the PDF, for example customer name.

The RDML should be based on the following:

Firstly, define a list with the field names containing the text that you wish to use in the PDF document. This List will be exchange in the ADD command.

DEF_LIST NAME(#OUTPUT) FIELDS((#SNAME)) TYPE(*WORKING)
CHANGE FIELD(#SNAME) TO('My Company')

add the field to the List

ADD_ENTRY TO_LIST(#OUTPUT)

Build the ADD command to add a particular content to a section of the PDF document. This section of the PDF will actually IMPORT the already created PDF document and then on a page of the PDF document the text will be added. See XML source in point 2 below.

USE BUILTIN(JSM_COMMAND) WITH_ARGS('ADD CONTENT(MYCONTENT)
SERVICE_LIST(SNAME)') TO_GET(#JSMSTS #JSMMSG #OUTPUT)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)

Note: You need to use a SERVICE_LIST keyword so that the field value is exchanged.

2. The second part is the XML source where the external PDF document is imported and amended with additional text

<content name="mycontent">
	<text x1="382" y1="755" width="150" height="60" style="text-modern" border="" align="left" leading="">
		<phrase style="standard" options="na" value="{SNAME}"/>
		<phrase style="standard" options="na">Phone: 8907 1111</phrase>
		<phrase style="standard" options="na">Fax: 1223 9999</phrase>
	</text>
</content>

Note: In the above XML source there are 3 instances of new text being added. The first line is inserting the contents of a field from a LANSA function; field called SNAME. This is a soft value. The next two are actually literal inserts. It is hard-coded in the XML.