Printing programtically

Ask a Question related to Adobe Acrobat Macintosh, Design and Development.

  1. #1

    Default Printing programtically

    I am trying to print from my plugin without throwing up the Print dialog, but it is not working. I am using the AVDocPrintPagesWithParams API call and it is consistently throwing a general exception with an error code of bad parameter. I am trying to print to my postscript printer and save the file has an image. This all works fine when I use the GUI, however it is not working via this automated method. I used the code from AVPrintSnip.cpp as a guide, and here is what I am doing:

    AVDocPrintParamsRec r;
    memset (&r, 0, sizeof(AVDocPrintParamsRec));

    r.size = sizeof(AVDocPrintParamsRec);
    r.pageSpec = PDAllPages;

    // if true, displays dialog boxes; otherwise does not display
    // dialog boxes.
    r.interactive = false;

    // If interactive is false and cancelDialog is true, a Cancel
    // dialog box appears.
    r.cancelDialog = false;

    r.emitToPrinter = true; // only emitToPrinter or emitToFile must be true
    r.emitToFile = false;

    ASFileSys theFileSys;
    ASInt32 retVal = AVAcquireSpecialFilePathName
    (kAVSCUser,kAVSFDocuments,"test_print.pdf",
    &theFileSys,&(r.filePathName));

    // Used if emitToPrinter or emitToFile are true. First page
    // to be printed; zero-based; if -1, then all pages are printed
    r.firstPage = -1;

    r.psLevel = 2;
    r.binaryOK = false;
    r.shrinkToFit = false;
    r.doColorSeparations = false;
    r.emitFileOption = kAVEmitFilePS;
    r.emitFlags = 0;
    r.emitFontOption = kAVEmitFontAllFonts;
    r.ranges = NULL;
    r.numRanges = 0;
    r.reverse = false;
    r.transparencyLevel = 3; //The transparency level range from 1 to 5

    strcpy(&r.destProfile[0], "PostScript printing");

    r.printAsImage = true;

    ASPlatformPrinterSpecRec aspr;
    memset(&aspr, 0, sizeof(ASPlatformPrinterSpecRec));
    aspr.size = sizeof(ASPlatformPrinterSpecRec);
    ASText prname = ASTextFromPDText("Adobe PDF 7.0");
    ASUTF16Val* pval = &aspr.printerName[0];
    &*pval = ASTextGetUnicodeCopy(prname, kUTF16BigEndian);
    r.printerSpec = &aspr;

    DURING
    AVDocPrintPagesWithParams(avDoc, &r);
    ASTextDestroy(prname);
    ASFileSysReleasePath(NULL, r.filePathName);
    r.filePathName = NULL;
    HANDLER
    ShowErrMsg(ERRORCODE);
    ASTextDestroy(prname);
    ASFileSysReleasePath(NULL, r.filePathName);
    r.filePathName = NULL;
    return(rcINTERNAL_ERROR);
    END_HANDLER
    Maurice_Leake@adobeforums.com Guest

  2. Similar Questions and Discussions

    1. CFGRID row highlight programtically
      Can you programatically set a row to be highlighted in a CFGRID? I want to have the first row selected every time the form is loaded so as to...
    2. Freehand printing - right margin decreases when printing multiple copies of file.
      I'm using Freehand mx. Everytime I print more than one copy of a file, the right margin decreases. Thus, if I print five or six copies of a file,...
    3. Printing Dynamically Insantiated MovieClips (multi-page printing)
      I can create multiple pages with just one prompt with new PrinJob() object in Flash MX2004; but ... .... when I try to addpages which is one...
    4. Printing without showing the printing dialog window
      hey - did you ever figure out a solution to the printing without dialog issue? i'm trying to get around the same problem myself. thanks! -jason
    5. Help: How can I find the error in a Procedure programtically
      We have a procdure. Every night it will become invalid, but it will be recompiled automatically by our scripts. There is no bad influence on our...
  3. #2

    Default Re: Printing programtically

    I am having a hard time understanding how to populate the ASPlatformPrinterSpecRec under the MAC platform. The members are completely different than those of its Unix and Windows counterparts. I am particularly stuck on how to correctly populate printerName since it is defined as UniChar printerName[256]; and then theres the CGrafPtr--what the heck is this and what am I supposed to set it to. I have only been able to find a couple of threads on the Net and they are both related to Windows.

    This is very frustrating--believe it or not, I've managed to get this far by examing the the header files (AVExpT.h and ASExpT.h) than with the documentation.
    /* Define a platform specification for a printer */

    #if MAC_PLATFORM
    #define kPrinterSpecNameLen 256
    typedef struct _t_ASPlatformPrinterSpec {
    /** Size of the data structure. Must be set to
    sizeof(ASPlatformPrinterSpecRec).
    */
    ASSize_t size;
    /** Port to print to. */
    CGrafPtr *cGrafPtr;
    /** Best known resolution of current printer. */
    short hRes, vRes;
    /** Name of printer. */
    UniChar printerName[kPrinterSpecNameLen];
    } ASPlatformPrinterSpecRec, *ASPlatformPrinterSpec;
    #endif
    Maurice_Leake@adobeforums.com Guest

  4. #3

    Default Re: Printing programtically

    I've solved my problem! Here's what I learned if anyone is interested.

    After pain-stakingly going over every inch of the AVDocPrintParamsRec structure in the AVExpT.h header file. I noticed the following comment for the filePathName member:
    /* ... If emitToPrinter is true, and filePathName is non-NULL, then the system printer driver is used to emit the output stream to the file. This is implemented for Windows only. */

    Please notice the reference to "Windows only". So, after starting all over from scratch and simply setting every parameter in the structure either to its default or the value that I wanted, and setting filePathName to NULL--it worked! The actual output file was written to my desktop; which isn't where I wanted it to be, but I can work around that.

    So here's what I ended up with:

    AVDocPrintParamsRec Parms;
    memset (&Parms, 0, sizeof(AVDocPrintParamsRec));

    Parms.size = sizeof(AVDocPrintParamsRec);
    Parms.pageSpec = PDAllPages;
    Parms.interactive = false;
    Parms.cancelDialog = false;
    Parms.embedded = false;
    Parms.emitToPrinter = true;
    Parms.emitToFile = false;
    Parms.fileSysName = ASAtomNull;
    Parms.filePathName = NULL;
    Parms.firstPage = -1;
    Parms.lastPage = -1;
    Parms.psLevel = 3;
    Parms.binaryOK = false;
    Parms.shrinkToFit = true;
    Parms.doColorSeparations = false;
    Parms.emitFontOption = kAVEmitFontAllFonts;
    Parms.ranges = NULL;
    Parms.numRanges = 0;
    Parms.reverse = false;
    Parms.transparencyLevel = 0;
    Parms.emitFileOption = false;
    Parms.emitFlags = 0;
    Parms.TTasT42 = true;
    Parms.printAsImage = true;
    Parms.printerHasFarEastFonts = false;
    Parms.tileData = NULL;
    Parms.rasterData = NULL;
    Parms.overrideData = NULL;
    Parms.selectRect = NULL;
    Parms.ocContext = NULL;
    Parms.resPolicy = kAVResPolicySendAtStart;
    Parms.marksFlags = kAVCropMarks;
    Parms.nUpData = NULL;
    Parms.marksStyle = kAVDefaultMarkType;
    Parms.printDialogWasCancelled = true;
    Parms.parentWindow = NULL;

    Thanks!
    Maurice_Leake@adobeforums.com Guest

  5. #4

    Default Re: Printing programtically

    You may want to try asking these questions on the Acrobat SDK Forum where they actually ask programmatic questions. You will probably get a quicker response too.

    ~T
    Tembowa@adobeforums.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139