CIB pdf toolbox technical guide (EN)
15. Stationary function, overly of texts, graphics and barcodes
15.3. Implementation notes
The following points out special features of the implementation.
Overlayfunction
Stationery function
General procedure:
- The string of the Property BackgroundFilename is parsed. For each specified page a PropertyInfo object is created and added to a PointerArray. Each PropertyInfo contains the following information:
- An array with PageSettings. This contains the information, behind which page the page of the stationery comes. The index in this array corresponds to the page Main Document. If it contains a -1, it means that the page does not come after the corresponding page of the main document. All other specifications mean that it comes after.
- An index (indicates the number of pages of the stationery document)
- A file name (associated stationery file)
- The parsing is done as follows:
- The information separated by curly brackets (if there are several) is broken down (separator= "}{")
- Position data is read out and stored
- The page numbers (which are optionally in curly brackets), which can be separated by ";" to indicate several pages of the stationery, are split up.
- The file name is determined
- The page specifications are used to fill the array of PageSettings.
- The information within curly brackets is regulated by Prios.
- Depending on the priority, the numbers 0, 1, 2 are first entered in the individual PageSettings of the InfoObjects (-1 default)
- If the arrays of the InfoObjects of a bracket are occupied, they still have to be compared with one another. Higher prios overwrite the lower ones, so that whenever the same position is occupied in 2 PageSetting arrays, the higher number wins and the position of the lower one is occupied with -1.
- First a normal PdfJoin is carried out with the input files, then the background files are processed. Here, the same procedures are run through as for the normal join, except that instead of the method which builds a new PageTree, a method is called which mixes the contents.
- In this method, the property info is run through and checked whether or not the page should be stored based on the page settings.
- If the correct BackgroundPage was found, a new Xobject is created from the background page:
- GetContentstreamAsString() retrieves the content of the page and creates a new dictionary.
- From this a new stream is created and inserted into the main document as a new object.
- This object is converted to a form Xobject by setting the corresponding entries in its dictionary:
- Type /XObject
- Subtype /Form
- BBox corresponds to the MediaBox of the page
- Name must be a name that uniquely identifies the object within the page, so it is necessary to check whether the name already exists and possibly assign a different one
- The Resources Dictionary corresponds to the background page
- Nun muss noch ein neues ContentStream-Objekt erzeugt werden, das auf das neues XObject referenziert und dem Dokument hinzugefügt werden: q XObjectName Do Q
- The reference to this object is then added to the ContentArray of the main page (in front, so that it is in the background)
- The xobjects are managed in an array, so that only one is created for each background page, and can be retrieved from the array when needed
- The annotations of the two pages are merged by adding the references to annotations of the background page to the annotation array of the main page. Possibly /P - entries are removed.
The AcroForms of the second page must also be added to the first.
Overlayfunction
General procedure:
- The content of the property overlay is parsed. The default values are used if no position is specified. The same parser is used and PropertyInfo objects are created.
- These objects contain information about position, width/height (graphic), file name (or text).
- The generated information is managed in an array or from an array. After the join, the main document is merged with the corresponding overlay information.
- For each page of the main document, the PropertyInfo array is searched for elements whose PageSettings are compatible with the current page. If one is found, either the corresponding graphic or the corresponding text must be inserted into the main document.
- For each appropriate indication, the following procedure must be followed in the case of a text:
- You get the content of the page using GetContentstreamAsString(), depending on whether you want the text in front of or behind the content of the page, a new content stream has to be created, in which the new part is placed either in front of or behind the old part:
- q <old contentstream> Q q <contentstream for text to be inserted> Q“
- The ContentStream for the text to be inserted must look as follows:
BT
/F13 12 Tf
288 720 Td
(ABC) Tj
ET
- BT marks the beginning, ET the end
- /F13 is the name of the font to be used
- 12 the font size
- 288 720 are the position data
- ABC is the text to be inserted
- This refers to a font called F13. This font must be referenced in the Resources Dictionary of the page:
/Resources
<< /Font << /F13 23 0 R >>
>>
23 0 obj
<< /Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>>
endobj
- This means that for each font specified in the property overlay, a font object must be created as described above.
- Here too, care must be taken to ensure that the names are unique within the page.
- Implementations for graphics and barcodes will be added in the future.