PDFWriter: Using ExtEscape WIN32 API call to set document propeties

PDFWriter: Using ExtEscape WIN32 API call to set document propeties

Post by Bruce Fergus » Tue, 20 Nov 2001 10:27:43



I am having a hard time porting the sample code provided by Adobe in
the PDFWctrl Visual C++ application to Visual Basic.  Below I have
listed first the Adobe sample C++ code followed by my best effort in
porting it to work with VB.  I am doing okay until I actually call the
ExtEscape function from VB then I am getting a "data mismatch" error.

I haven't been able to find any VB sample code on setting these
properties (outputfilename, title, author, subject, and keywords) by
using ExtEscape.  Please let me know if I am approaching this wrong,
but the PDFWriter API Reference says that you can only set the title,
author, subject, and keywords by using printer escapes.

Any help would be most appreciated.  Thanks,

  Bruce

C++ Sample Code Provided in Adobe Acrobat PDFWriter API Reference:

#define PDFFILENAME 4312        /* Escape number */

/* Return values */
#define PDFINPUT_OK 1  
#define PDFINPUT_FAIL -1

typedef struct _PDFDocInfo {
        char                    title[MAXPATH];         // Title
        char                    author[MAXPATH];
        char                    creationDate[MAXPATH];
        char                    creator[MAXPATH];
        char                    producer[MAXPATH];
        char                    subject[MAXPATH];
        char                    keywords[MAXPATH];
        char                    modDate[MAXPATH];

Quote:} PDFDocInfo, *PDFDocInfoPtr;

/****** A note on specifying the metadata in a PDF file.***
 Although it is possible to set the creation date, modification
 date, creator and producer using the above structure, we do not
 suggest that you do so. If you leave these blank PDF Writer will
 fill in appropriate values. If you set the date yourself and it
 does not meet the PDF specification it may cause trouble for readers
 of the PDF. PDFWriter will set the appropriate date using the system
 clock, use the application name from the DOCINFO struct and set
itself
 as the producer
 */
typedef struct _PDFINPUT
    {
    CHAR                outputfilename[MAXPATH];
        PDFDocInfo              docinfo;
    } PDFINPUT, FAR * LPPDFINPUT;

         PDFINPUT  pdfInput;
         PDFDocInfo pdfdocinfo;
         memset (&pdfdocinfo,0,sizeof(PDFDocInfo));

         strcpy(pdfInput.outputfilename,"c:\\pdfwout.pdf");
         strcpy(pdfdocinfo.title,"my_title");
         strcpy(pdfdocinfo.author,"my_author");
         strcpy(pdfdocinfo.subject,"my_subject");
         strcpy(pdfdocinfo.keywords,"my_keywords");

/*   Although it is possible to set the following
fields, we do not suggest that you do so. If you leave these
blank PDF Writer will fill in appropriate values. If you set
the date yourself and it does not meet the PDF specification
it may cause trouble for readers of the PDF. PDFWriter will
set the appropriate date using the system clock, use the
application name from the DOCINFO struct and set itself as the
producer

     strcpy(pdfdocinfo.creationDate,"my_date");
         strcpy(pdfdocinfo.creator,"my_creator");
         strcpy(pdfdocinfo.producer,"my_producer");
         strcpy(pdfdocinfo.modDate,"my_modDate");
*/
         pdfInput.docinfo = pdfdocinfo;

 // PDFWriter control by ExtEscape() function

                        if(use_escape){
                        if ( ExtEscape(pd.hDC, PDFFILENAME, sizeof(pdfInput),
(LPSTR)&pdfInput, 0,NULL) == PDFINPUT_OK ){
                        // escape successful
                        } else {
                        // escape failed
                        sprintf(szTemp, "escape failed");
                   MessageBox(hwnd, szTemp, NULL, MB_OK | MB_ICONHAND);
                        }

My attempt at porting the above code to Visual Basic 6:

(in the module declarations)
Public Declare Function ExtEscape Lib "gdi32" (ByVal hdc As Long,
ByVal nEscape As Long, ByVal cbInput As Long, ByVal lpszInData As
String, ByVal cbOutput As Long, ByVal lpszOutData As String) As Long

Type PDFDocInfo
    title As String
    author As String
    creationDate As Date
    creator As String
    producer As String
    subject As String
    keywords As String
    modDate As Date
End Type

Type PDFInput
    outputfilename As String
    docinfo As PDFDocInfo
End Type

(in the sub)
Sub SetPDFWriterProperties()

'A note on specifying the metadata in a PDF file.***
'Although it is possible to set the creation date, modification
'date, creator and producer using the above structure, we do not
'suggest that you do so. If you leave these blank PDF Writer will
'fill in appropriate values. If you set the date yourself and it
'does not meet the PDF specification it may cause trouble for readers
'of the PDF. PDFWriter will set the appropriate date using the system
'clock, use the application name from the DOCINFO struct and set
itself
'as the producer

Const PDFFILENAME = 4312
Const PDFINPUT_OK = 1
Const PDFINPUT_FAIL = -1

Dim PDFWriterProperties As PDFInput
PDFWriterProperties.outputfilename = "c:\test1.pdf"
PDFWriterProperties.docinfo.title = "BSF Test Document"

If ExtEscape(Printer.hdc, PDFFILENAME, Len(PDFWriterProperties),
CStr(PDFWriterProperties), Null) = "PDFINPUT_OK" Then
    'Printer Escape Settings successful, now start the print job
Else
    'Printer Escape Settings failed
End If

End Sub
________

I think my problem is that I don't really understand the
paramaters/arguments that ExtEscape requires.  Also, why does the
Declare show six parameters while Adobe only passes five?

 
 
 

PDFWriter: Using ExtEscape WIN32 API call to set document propeties

Post by Aandi Inst » Tue, 20 Nov 2001 18:16:57



>I am having a hard time porting the sample code provided by Adobe in
>the PDFWctrl Visual C++ application to Visual Basic.  

Most people who use Visual Basic for this purpose abandon the escape
mechanism, and instead use the much simpler INI file/registry method.
I am not sure that Visual Basic can be used to create every kind of
C-based structure. You have to understand the internal data formats of
both languages - your Visual Basic structure is an array of pointers
to the internal "string" and "date" type rather than a collection of
in-line character arrays.
----------------------------------------

Please support usenet! Post replies and follow-ups, don't e-mail them.

 
 
 

1. VB And PDFWriter -- ExtEscape prints blank document

Hi,

I'm trying to use the ExtEscape api call to create a PDF document from
visual basic.  The following code creates an empty pdf document.  Any ideas?

    '---- Define API call....

Private Declare Function ExtEscape Lib "GDI32" (ByVal hdc As Long, ByVal
nEscape As Long, _
    ByVal cbInput As Long, ByVal lpszInData As Any, ByVal cbOutput As Long,
ByVal lpszOutData As Any) As Long

    '---- Prep the printer -- PDFWriter.......

    lngReturn = ExtEscape(Printer.hdc, 4312, Len("c:\myfile.pdf"),
"c:\myfile.pdf", 0, "")

    '---- Print an HTML document using internet explorer....

    Call objWebBrowser.ExecWB(OLECMDID_PRINT,
OLECMDEXECOPT_DONTPROMPTUSER,0, 0)

2. Listing all the databases

3. Call External and Win32 API dll's Subroutine calls

4. User Rights

5. How to change display settings without calling Win32 API functions in VB.NET.

6. Mouse doesn't work, resolution can't change

7. Solutiion: Calling WIN32 API Functions

8. Memory map Apple ][

9. Win32 API calls - RegEnumKeyEx

10. Calling WIN32 API Functions

11. VO/Win32 API Calling Conventions

12. Win32 Api calls

13. Does PB Support Calls to Win32 and Win16 API Libraries ?