Adobe PDF / PostScript Support

Top  Previous  Next

Additional PDF and PostScript file support is provided for DTWAIN_AcquireFile and DTWAIN_AcquireFileEx.  When acquiring to PDF files, the application has the option of:

 

Acquiring single or multi-page PDF's,

Setting the PDF page size

Setting the PDF page orientation.

Scaling the image.

Setting PDF author, producer, title, subject, and keywords.

Creating encrypted PDF files using 128-bit or 256-bit AES encryption.

Add text to PDF pages. 

Add searchable text to PDF pages using an OCR engine.

 

Special Note:  The saving of Adobe PDF and PostScript files requires a writeable and accessible temporary directory.  If you are attempting to acquire PDF / PostScript files, and have errors in creating the files, make sure that your temporary directory (usually C:\TEMP, please check your System settings) is writeable and accessible from the computer running the application.  You can also set the temp file directory by calling DTWAIN_SetTempFileDirectory or DTWAIN_SetTempFileDirectoryEx before acquiring images.


The following support functions are available to set the major characteristics of a PDF file:


DTWAIN_SetPDFAuthor

DTWAIN_SetPDFEncryption

DTWAIN_SetPDFAESEncryption

DTWAIN_SetPDFKeywords

DTWAIN_SetPDFOrientation

DTWAIN_SetPDFPageScale

DTWAIN_SetPDFPageSize

DTWAIN_SetPDFProducer

DTWAIN_SetPDFSubject

DTWAIN_SetPDFTitle




Adding additional text to PDF pages


For adding text to a PDF page, the following functions are used:


This function was introduced in versions of DTWAIN before 5.8.  It wil do the basics, but is deprecated as of version 5.8 and higher:


DTWAIN_AddPDFText


Instead of DTWAIN_AddPDFText, use the functions below, as they are more versatile than DTWAIN_AddPDFText.  In addition to this, features such as rotation and skewing the text, and much more flexibility in changing the text characteristics while the images are being acquired are available.


DTWAIN_AddPDFTextElement

DTWAIN_ClearPDFTextElements

DTWAIN_CreatePDFTextElement

DTWAIN_DestroyPDFTextElement

DTWAIN_GetPDFTextElementFloat

DTWAIN_GetPDFTextElementString

DTWAIN_GetPDFTextElementLong

DTWAIN_RemovePDFTextElement

DTWAIN_SetPDFTextElementFloat

DTWAIN_SetPDFTextElementLong

DTWAIN_SetPDFTextElementString


It is most appropriate that these functions are called prior to calling DTWAIN_AcquireFile or DTWAIN_AcquireFileEx.  You can also call these functions before a page is saved by trapping the DTWAIN_TN_FILEPAGESAVING notification and calling the appropriate PDF function(s) in your handler.


Since DTWAIN_AddPDFText is simple in its usage, we will instead look at an example of the functions that utilize DTWAIN_PDFTEXTELEMENT:


Here is a small C / C++ example:


The first set of code can be called before any DTWAIN_SOURCE has been selected:


1) First we need to create a PDF Text Element:


        int page_count;  // "global" page count we will utilize later on

        DTWAIN_PDFTEXTELEMENT TextElement = DTWAIN_CreatePDFTextElement();


2) Now set the position where the text element will be placed, plus the font size, plus the pages that the text element will be displayed:


        // place at PDF x,y position (100, 100)

        DTWAIN_SetPDFTextElementLong(TextElement, 100, 100, DTWAIN_PDFTEXTELEMENT_POSITION); 


        // set font height to 14 points

        DTWAIN_SetPDFTextElementFloat(TextElement, 14.0, 0, DTWAIN_PDFTEXTELEMENT_FONTHEIGHT); 


        // set the pages where the text will be displayed

        DTWAIN_SetPDFTextElementLong(TextElement, DTWAIN_PDFTEXT_ALLPAGES, 0, DTWAIN_PDFTEXT_ALLPAGES); 


Note that we only need to do the above steps once in the code.  All of the text's characteristics are stored in the created text element.


Next, we can select a DTWAIN_SOURCE and add the text element we created above to the DTWAIN_SOURCE:


        DTWAIN_SOURCE source;

        source = DTWAIN_SelectSource();

        //...

        DTWAIN_AddPDFTextElement(source, TextElement);


Now assume that DTWAIN_AcquireFile or DTWAIN_AcquireFileEx was called, and that the file type was either DTWAIN_PDF or DTWAIN_PDFMULTI.


In the notification handler you have set up, let's stamp each PDF page with the current page number.  This should be done in the DTWAIN_TN_FILEPAGESAVING notification:.  

     

        case DTWAIN_TN_ACQUIRESTARTED:

              page_count = 1;  // Set the page count to 1 at the start of the acquisition

        break;

       

        case DTWAIN_TN_FILEPAGESAVING:  // Called when page is about to be saved

        {

                TCHAR text[100];

                wsprintf(text, _T("Page %d"), page_count);  // This will create a string of "Page 1", "Page 2", etc. 


                // Set the text within the Text element.

                // Since the TextElement is tied to the source by the previous call to DTWAIN_AddPDFTextElement(), 

                // this change will automatically show up as printed text on the generated page

                DTWAIN_SetPDFTextElementString(TextElement, text, DTWAIN_PDFTEXTELEMENT_TEXT);


                ++page_count;  // Page count is incremented

          }

          return 1;


You are allowed to add theoretically an unlimited amount of unique text element objects to a DTWAIN_SOURCE.  For example, if you want to add multiple strings with varying fonts, positions, etc. to a single PDF page, you would create as many DTWAIN_PDFTEXTELEMENT objects as necessary, adjust each one, and add each of them to the DTWAIN_SOURCE.


Note that if you were to use the "simple" DTWAIN_AddPDFText function instead of the above example, you would not need to set up a DTWAIN_PDFTEXTELEMENT, however,you would need to call DTWAIN_AddPDFText every time in the DTWAIN_TN_FILEPAGESAVING handler with all of the parameters describing the text, plus use  the DTWAIN_PDFTEXTLEMENT_CURRENTPAGE flag.  The issue is that if you had multiple strings to write to the PDF page, this technique becomes less scalable and more maintenance would be incurred.  Thus it is recommended to use the DTWAIN_PDFTEXTELEMENT method of creating text on PDF pages.