The Geo-Registration module can be used in three steps:
Printing a PDF document while wrapping a group of printing instructions with two special instructions that will create a Tag for it.
Setting-up Amyuni PDF Converter post-processing module and open the resulting PDF file.
Attaching a structure tree to the newly created file using the Tags that were created in step 1.
Attaching geo-registration information to the resulting file from step 1 or 2.
Steps 2, 3 and 4 are post-processing steps, since they will take place after a valid PDF file is produced by Amyuni PDF Printer.
In order to set up a group of printing operations as Marked Content, it will be necessary to wrap the operations in two calls to escape commands:
SetMarkedContent( hDC, “Figure”) //...Printing operations...
SetMarkedContent( hDC, “” )
Where SetMarkedContent can be defined as:
#define ESCAPE_SETMARKEDCONTENT 246
void SetMarkedContent( HDC hDC, // Device context for printing.
LPSTR stdStructType // PDF Standard Structure Type (See PDF specification on Chapter 10 Section 1.7.3 for further details) Ex: /Figure /P /Link
) {
switch ( ExtEscape( hDC, ESCAPE_SETMARKEDCONTENT,
(int)((strlen(stdStructType) + 1) * sizeof(stdStructType [0])),
(LPCSTR) stdStructType, 0, NULL ) ) {
default6
// 0 or positive return indicates success.
case -1:
// error occured, closing a layer when none was open
break;
case -2:
// memory allocation error (low memory or invalid string)
break;
}
}
Escape commands are standard Windows API operations commonly used in printing processes.
These function calls will generate the following output inside the PDF file:
Dim pdf
5 0 obj
...
stream
...
/Figure <<MCID 0>> BMC → SetMarkedContent( hDC, “Figure”);
...
EMC → SetMarkedContent( hDC, “” );
...
endstream
endobj
The MCID value is an auto-incremented number (starting at 0) that will be reset for every page. This number will be returned by the function SetMarkedContent(...).
The parameter stdStructType will depend on the intent of the client application that is sending the printing commands. There is a list of possible values on Chapter 10(Document Interchange) of Adobe’s PDF specification. The most commonly used are: /P (paragraph, text, etc) and /Figure (images, polygons, etc).
PDF Layers are a special case of Marked Contents, that is why it is not possible to start a layer, then start a marked content, and then try to close the layer before closing the marked content first. Since both features use the EMC command for termination, if an application tries to call SetLayer(hdc, “”) while a Marked Content is still open, the Marked Content will be closed instead of the corresponding layer. The same applies for the opposite case.
LPTSTR printerName = _T("Amyuni PDF Converter");
// create device context from printer
HDC hDC = CreateDC( NULL, printerName, NULL, NULL );
// get information about the printer
HANDLE hPrinter = NULL;
if ( !OpenPrinter( printerName, &hPrinter, NULL ) || hPrinter == NULL ){
//Handle error
}
// start new document
DOCINFO di;
int nPage = 1;
memset( &di, 0, sizeof(di) );
di.cbSize = sizeof(di);
di.lpszDocName = _T("Tagged PDF");
StartDoc( hDC, &di );
StartPage( hDC );
SetMarkedContent( hDC, "Figure" );
// draw a green rectangle
HBRUSH hbr = CreateSolidBrush( RGB(0, 200, 0) );
RECT rc = { 200, 800, 2000, 200 };
FillRect( hDC, &rc, hbr );
DeleteObject( hbr );
SetMarkedContent( hDC, "" ); // close marked content
EndPage( hDC );
EndDoc( hDC );
Performing post-processing steps on a PDF file using Amyuni PDF Converter requires a group of set-up operations to open the file and validate the product license. The interface IDIDocument provides the necessary methods for this process.
Only methods directly related to preparation for post-processing were included in this diagram.
The PDF specification provides a way to organize Marked Content in form of a tree called Structure Tree. Each Marked Content can be associated to a node on the tree, and it is possible to assign User Properties to each node. The Structure Tree is global for the hole document. Any Marked Content element from any page can be configured at any level of the tree except the root. The root of the tree is an internal object that is not shown in viewer applications. Developers usually add one additional node to serve as a visual root node.
Partial screenshot from Adobe® Acrobat Reader showing a structure tree with a selected node, it's highlighted corresponding figure, and its user properties in a table.
In order to create this tree, Amyuni PDF Converter provides the interface IStructElement and three functions in IDIDocument interface.
Only methods directly related to marked content inside IDIDocument were included in this diagram.
Geo-registration of PDF files requires a specific structure for the data passing from the calling application to Amyuni PDF Converter. This information is structured in the specification of PDF in the following entities.
Only methods directly related to geo-registration inside IDIDocument were included in this diagram.