Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

Unexpected changing of the printername in the template

edited July 2009 in Devices
Hello,

I have a problem with an unexpected changing of the printername in the
template which results in changing the layout of the report.

I have a template that contains a general printername 'Medicator' where the
data is placed in the centre of the paper. If the default Windows printer
has also the name 'Medicator' the report is printed correctly. But when the
default Windows printername is something else (this can physically the same
printer with another name) the printername in the template is changed to the
printername of the default Windows printer. And the data will be printed
from the left margin of the paper, no longer in the centre of the paper.

How can I change the name of the default Windows printer without these
unexpected and unwanted changes in the template of my report.

regards,

Hanjo Willems
iSOFT Nederland B.V.

Comments

  • edited July 2009
    Correct. If the PrinterSetup.PrinterName does not match any of the installed
    printer names on the machine, then the PrinterName is set to 'Default'. When
    the report is generatated, the Windows default printer is used.

    One simple solution is to use a standard printer name for all of the
    installed printers. (However, might not be an option for your environment).

    Another solution is to write some code to iterate over the installed
    PrinterNames for the machine and find the printer with the similar name.

    example: {this is incomplet code - just to give you an idea}

    uses
    ppPrintr;

    for liIndex := 0 to myReport.PrinterSetup.PrinterNames.Count-1 do
    begin
    lsPrinterName := myReport.PrinterSetup.PrinterNames[liIndex];

    if {lsPrinterName is similar to the Medicator} then
    myReport.PrinterSetup.PrinterName := lsPrinterName;

    end;




    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2009
    Hello,

    In the original posting I asked also something about the position of the
    report on the paper. (And the data will be printed
    from the left margin of the paper, no longer in the centre of the paper.)
    Because the report must be printed on A5-format paper. The items in the
    report are moved to the left side of the paper when the name of the printer
    is changed to the default printer. Is it possible that the items have still
    the same position (on the centre of the paper) after the printer is changed?

    When the lay out will be the same on every printer it is maybe not
    nescessary that the printer have always the same name.

    regards,
    Hanjo Willems
    iSOFT Nederland b.v.



  • edited August 2009
    Hi Hanjo,

    Using Anchors you may be able to get the effect you are after. This will
    keep certain objects the same distance away from two adjacent sides of the
    report regardless how the margins/page size is changed.

    Another option would be to create a report object loop that adjusts each
    component based on the size of the paper when it is changed.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Layouts/Report_Object_Loop

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2009
    Hello,

    I'm still working on this problem. I will try to explain the situation a
    little bit more. When the template is designed a printername 'Medicator' is
    saved in the template. On the PC where the template is designed is this a
    valid printername. The property SavePrinterSetup have still the default
    value: false. The label will be printed on A6 paper.
    In the application the user can select one of the printers installed on that
    PC to print a label. When the selected printer doesn't have the name
    'Medicator' the template switched to the default Windows printer and not to
    the specified printer that the user has selected in the application.

    In the template the printername is: 'Medicator'.
    The selected printer is: 'HP Laserjet 1010', this is not the default Windows
    printer. This printer have the same paperformats as the printer 'Medicator'.
    The printername 'Medicator' is an alias for this HP Laserjet 1010 printer.
    It's not an option for us to install on each PC where the application is
    running an alias for a printer with the name 'Medicator'.

    The label will be printed on the default Windows printer instead of on the
    HP Laserjet 1010.
    Why is the label printed on the default Windows printer instead of on the HP
    Laserjet 1010?

    regards,
    Hanjo Willems
    iSOFT Nederland B.V.


  • edited September 2009

    From your description it sounds like everything is working as designed.

    The Report.PrinterSetup information is use always saved as part of the
    report definition.

    When Report.PrinterSetup.PrinterName cannot be found, then the 'Default'
    printer is used. Default refers to the Windows default printer.

    In your description you state 'In the application the user can select one of
    the printers installed on that
    PC to print a label."

    Can you clarify how you do that? And how you do apply that information to
    the Report.PrinterSetup.PrinterName?



    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited September 2009
    Hello Nard,

    In the application a list of Windows printers is presented in a combobox,
    the user can select one of the printers from this list. The list with
    printers is filled with the statement: for Index := 0 to
    (Printer.Printers.Count - 1) do
    AfwijkendMediComboBox.Items.Add(Printer.Printers[Index]).
    Each time the list with printers will be presented to the user is this list
    refreshed with the current Windows printers. The selected printer is also
    stored as an option in the registry. Each time the printer is selected there
    is an check of this printer is still present on the PC, when the printer is
    not found the user must select another printer. So the printer that will be
    used for printing the labels is always one of the printers available on the
    PC. The name of this printer is send to ReportBuilder by setting the
    property lPrinterDevice.Printer.PrinterSetup.PrinterName.
    lPrinterDevice.Printer.PrinterSetup is filled with FReport.PrinterSetup.

    So we find it strange that this printer is not be used when the name of the
    printer is not equal to the name of printer in the template. And that the
    default Windows printer is used in this case. We want to use the specified
    printer and not the default Windows printer. The printername in the template
    should not be used, but the specified printername must be used!

    regards,
    Hanjo Willems
    iSOFT Nederland B.V.


  • edited September 2009

    1. To get a list of installed printers you can simply use
    Report.PrinterSetup.PrinterNames or access the global TppPrinterList object
    by using ppPrinters.

    uses
    ppPrintr;

    myCompbox.Items.Assign(myReport.PrinterSetup.PrinterNames);

    or

    myComboBox.Items.Assign(ppPrinters.PrinterNames);


    2. To rebuild the list of printers available on the machine call

    ppPrinters.Refresh;


    3. Make sure you first load the report definition and then set the printer
    name;

    // load the report definition
    myReport.LoadFromFile (or LoadFromDatabase);

    // refresh the printer list, if needed
    ppPrinters.Refresh;

    // check whether the selected printer is installed
    if (ppPrinters.PrinterNames.IndexOf(myPrinterName) < 0 then
    // name not found, need to use Default printer or ask the user
    else
    begin
    // update the report
    myReport.PrinterSetup.PrinterName := myPrinterName;

    // update the printer device
    myPrinterDevice.PrinterSetup := myReport.PrinterSetup;

    end;








    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.