Controlling printer settings

  • Hello,

    We are currently evaluating ViewPDF for our application. However, a requirement is total control over the printer, eg. duplex and choice of tray.

    This seems to be possible by manipulating the DevMode structure, then making use of the COMPDF_PrintSetDEVMODE call.

    We are using the following code to test printing to different trays:

    This does not work - all copies goes to the default tray.

    Question: Is the code faulty, or is what we are doing not possible?


    Chris

    • Offizieller Beitrag

    Hi,

    Is this Delphi 2009 or Delphi 2010.

    Right now, the DevMode should be the TDevModeA type (not unicode type)

    The tray can also not be set like this. It is not just a number such as 2..4, but an identifier which has usually a rather large value.

    You can use these commands

    COMPDF_SelectPrinterBin0 = 38; // PrinterBin Def for default
    COMPDF_SelectPrinterBin1 = 39; // PrinterBin Def for primary
    COMPDF_SelectPrinterBin2 = 40; // PrinterBin Def for secondary

    to select certain tray (ids!)

    Using the command

    COMPDF_SetPagePaperBin

    a certain bin number 0,1,2 (default/primary/secondary) can be set for certain pages. It will work on the current selection.

    COMPDF_PageSelectionGet = 247; // Checks if a page is selected. Pass zero based page number. Result = 1, if selected
    COMPDF_PageSelectionClear = 248; // Removes previous selection
    COMPDF_PageSelectionAdd = 249; // Select one additional page. Pass zero based page number. Result = count of selected pages.
    COMPDF_PageSelectionDel = 250; // Removes Selection from Page. Pass zero based page number. Result = count of selected pages.
    COMPDF_PageSelectionToggle= 258; // Toggles state for a certain page. Pass zero based page number. Result = count of selected pages.
    COMPDF_PageSelectionInvert= 251; // Inverts Selection. Result = count of selected pages.

  • Hello Julian,

    It is Delphi 2007 (non-unicode).

    I wrote the example in haste, the default source selection should of course be something like

    Code
    DevMode^.dmDefaultSource := trays[tray];

    (as it is in our application, where we do the printer control the same way).

    This still does not work - all copies goes to the default bin.

    Unfortunately we can not use the pre-defined constants, because some customers have up to five bins - and is using them. And please keep in mind, that the bin thing is only meant as an example, and we need to access other devicemode settings like duplex, and in time maybe color and resolution.

    Being able to control all TWPViewPDF printersettings througt the devicemode, as the previous example shows, would make that easy for us. But something in the stomach of the TWPViewPDF source seems to prevent that.

    Or, of course, the example might still be faulty? :)


    Chris

  • Problem solved. I needed to call:

    Code
    CommandEx(COMPDF_DONTSETDEVMODE,1);

    after the COMPDF_SelectPrinter call.

    Now tray changing works like a charm - at least at the one printer I have been testing. :)


    Chris

  • Hi,
    I use the code as follows:
    WPViewPDF1.CommandEx(COMPDF_PrintUseScaling,1);
    WPViewPDF1.CommandEx(COMPDF_PrintDialog,0);
    Although I change the tray in printer properties, the print job gets always sent to tray 1.
    What is the point of providing a printer dialog if nothing can be changed?

    Please advise!
    Thanks
    Christoph

  • O.k.
    the following sequence of commands works as expected

    WPViewPDF1.CommandEx(COMPDF_DONTSETDEVMODE,1);
    WPViewPDF1.CommandEx(COMPDF_PrintUseScaling,1);
    WPViewPDF1.CommandEx(COMPDF_PrintDialog,0);

    which I found out by trial and error.

    Your documentation and samples are not helpful in this respect at all!
    Christoph

  • Just to clarify my above comments, we ended out with something like this, which works very well if you call it before printing or showing printer dialogs.


    Chris