Home Devices

Add a Drawcommand to a PDF-Page

edited October 2010 in Devices
Hi,

I have a TppDBArchiveReader and with the help of
"How To...Add a Drawcommand to a Page" from the rbWiki i can
draw to the screen and the printer.

Now i like to draw to the PDF-Output.
Which changes i have to make, so that this will also work with
PDF?

Best regards
Olaf


RB 11.08
Delphi 7

Comments

  • edited October 2010
    Hi Olaf,

    For the example, instead of using a TppRasterDevice, use a TppDevice instead
    and change the code to something like the following to include file devices.

    procedure TForm1.ppArchiveReader1BeforePrint(Sender: TObject);
    var
    lDevice: TppDevice;
    begin

    // get reference to the screen, printer, or file device
    if (ppArchiveReader1.FileDevice <> nil) then
    lDevice := ppArchiveReader1.FileDevice
    else if (ppArchiveReader1.PrinterDevice <> nil) then
    lDevice := ppArchiveReader1.PrinterDevice
    else if (ppArchiveReader1.PreviewForm <> nil) then
    lDevice := TppViewer(ppArchiveReader1.PreviewForm.Viewer).ScreenDevice
    else
    lDevice := nil;

    // attach handler to device OnPageReceive event
    if (lDevice <> nil) then
    lDevice.OnPageReceive := ehPageReceive;

    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2010
    Hi Nico,

    Thanks, it works.

    BUT...

    I have a text drawcommand with
    lDrawText.Border.Weight := 1.2;
    lDrawText.Border.BorderPositions := [bpTop, bpBottom];

    Printing to the PrinterPreview there will be borders.
    Printing to the PDF there will not be some borders.
    There are only two very little pieces of gray at the textstart
    (top and bottom).

    Is there something going wrong?

    Best regards, Olaf
  • edited October 2010
    Hi Olaf,

    In my testing with RB 11.08 and Delphi 7, using your exact code below to
    assign a top and bottom border, the PDF output was correct. If possible,
    please send a simple example that demonstrates this issue to
    support@digital-metaphors.com in .zip format and I'll take a look at it for
    you.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2010
    Hi Nico,

    Thanks for the help!

    AND FOR ALL:
    I made the following errors:

    I had to make some changes to rbWiki example
    How To...Add a Drawcommand to a Page

    For PDF you need a file device
    ...
    var
    lDevice: TppDevice;
    begin
    // get reference to the screen, printer, or file device
    if (ppArchiveReader1.FileDevice <> nil) then
    lDevice := ppArchiveReader1.FileDevice
    else if (ppArchiveReader1.PrinterDevice <> nil) then
    lDevice := ppArchiveReader1.PrinterDevice
    else if (prReader.PreviewForm <> nil) then
    lDevice := TppViewer(ppArchiveReader1.PreviewForm.Viewer).ScreenDevice
    else
    lDevice := nil;
    ...

    In the AddDrawCommand procedure i used WordWrapped text.
    When you use AutoSize=True, you can not use WordWrapped text.
    It is better and easier to use "lDrawText.Text"

    Regards, Olaf
This discussion has been closed.