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

PDF showing "fuzzy" images

edited March 2009 in Devices
I'm having a problem with printing images to PDF files.

The source image is 874 by 759 screen pixels high.

I print that using a TppImage of size 6712 by 4119 printer pixels high. Note
that if I set TReport.Units to utScreenPixels this is 1074 by 659 (note
height is now smaller than source image).

If I set TppImage.Stretch to false the image is fine but is cut off top and
bottom. If I set TppImage.Stretch to true the image fits on the screen but
has been resized & is fairly fuzzy & illegible.

I'm thinking that the PDF/Printer resolution must be higher than my screen
resolution and so this image should be able to fit but how do I determine or
control this relationship between screen pixels and PDF/printer pixels.

Thanks

Comments

  • edited March 2009
    Hi Geoff,

    If you are stretching an image to fit into a space larger than its actual
    size, you are going to loose some fidelity no matter what resolution you
    use. One option you might try is setting Stretch and MaintainAspectRatio to
    True to give a properly sized image for the space allowed. Another is to
    set Stretch to False and AutoSize to True so the top is no longer cut off.

    If this still does not give you what you need, you may need to resize the
    image using a high quality imaging suite such as Photoshop before displaying
    it in ReportBuilder.

    --
    Regards,

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

    Best Regards,

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

    Thanks for your answer. Unfortunately it's not solved my problem.

    I'm not stretching the image it's being shrunk & messed up when saved as a
    PDF. When I specify TppImage.Stretch to false then the image is cut off top
    and bottom. If I specify TppImage.Stretch to true then the image is shrunk
    and becomes illegible.

    This is the bit I don't understand. The TppImage size is set to 6712x4119
    printer pixels whilst the image I'm posting from the screen is only 874x759
    screen pixels - so it should fit easily. But it doesn't - and I'm guessing
    that is because Report Builder does some conversion between the screen
    pixels and the printer ones (note 6712x4119 printer pixels = 1074x659 screen
    pixels).

    In my mind the resolution of the printer (or PDF) has the area should allow
    the image to be shown with no loss of pixels - am I right?

    So is there anyway to do what I need to do?

    I tried setting Stretch to False and AutoSize to True and the image is still
    cut off top and bottom.

    Resizing the image in an external program isn't an option as this is an
    automatically generated image - rather than a static one.

    Thanks for you help
  • edited March 2009
    Hi Geoff,

    Thanks for the clarification.

    Images that are "shrunk" are automatically scaled in PDF to save space. You
    can override this feature by setting the PDFSettings.ScaleImages property to
    False.

    --
    Regards,

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

    Best Regards,

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

    Thanks for the reply but I must be missing something as I still can get it
    to work as I expect.

    If I understand correctly images within PDFs are stored with full resolution
    and information about how they should be scaled when rendered. So I don't
    undertstand why when the image is shrunk to fit the page that I'm losing
    detail when printed or zoomed into given that the resolution of the screen
    image being stored is much lower than printer resolution.

    To demonstrate I created a small demo program. To try this create a form
    application and drop a button, aTppReport and a TExtraOptions. Then in the
    report designer drop a TppImage onto the report. Then create the two event
    methods on form create and button click and add the folowing code...

    procedure TFormMain.FormCreate(Sender: TObject);
    var
    memo : TMemo;
    i : integer;
    begin
    // Resize form to be large but much smaller than the paper size
    FormMain.Height := 800;
    FormMain.Width := 640;

    // Now add some text to demostrate loss of detail
    memo := TMemo.Create(FormMain);
    memo.Parent := FormMain;
    memo.Height := FormMain.Height - 80;
    memo.Align := alBottom;
    for i := 1 to 100 do
    begin
    memo.Lines.Add('The quick brown fox jumped over the lazy dog. Rooks just
    love my big lump of quartz. 123456789.00');
    end;
    end;


    procedure TFormMain.ButtonSnapshotClick(Sender: TObject);
    var
    MyRect, SourceRect : TRect;
    c: TCanvas;
    h: THandle;
    width, height: Integer;
    begin
    // Snapshot current form
    c := TCanvas.Create;
    c.Handle := GetWindowDC(GetDesktopWindow);
    try
    h := GetForegroundWindow;
    if h <> 0 then
    begin
    // Set up the report
    ppReport1.Units := utPrinterPixels;
    ppReport1.PDFSettings.ScaleImages := true;
    ppReport1.AllowPrintToFile := True;
    ppReport1.PrinterSetup.Orientation := poLandscape;

    // Set up the image to fill the page whilst keeping aspect ratio
    ppImage1.Stretch:= true;
    ppImage1.AutoSize := false;
    ppImage1.MaintainAspectRatio := true;
    ppImage1.Height := ppReport1.Printer.PaperHeight - 200;
    ppImage1.Width := ppReport1.Printer.PaperWidth - 200;

    // Determine size of current form
    GetWindowRect(h, SourceRect);
    width := Abs(SourceRect.Right - SourceRect.Left);
    height:= Abs(SourceRect.Bottom - SourceRect.Top);

    // Copy a snapshot of current form onto the image
    ppImage1.Picture.Bitmap.Width := width;
    ppImage1.Picture.Bitmap.Height := height;
    MyRect := Rect(0, 0, width, height);
    ppImage1.Picture.Bitmap.Canvas.CopyMode := cmSrcCopy;
    ppImage1.Picture.Bitmap.Canvas.CopyRect(MyRect, c, SourceRect);

    // Set up some options
    ExtraOptions1.PDF.ScaleImages := true;

    ppReport1.Printer.DocumentName:='Snapshot - ' + Caption;

    ppReport1.DeviceType:='Printer';

    // Now print
    ppReport1.Print;

    ppImage1.Picture.Bitmap.FreeImage;
    end;
    finally
    ReleaseDC(0, c.Handle);
    c.Free;
    end;
    end;


    Now run the program, click the button and save to a PDF file. When viewing
    the PDF file you can see that detail has been lost on the image. If you set
    ppImage1.Stretch to false then no detail is lost but the top & bottom of the
    image is cropped.

    How do I store the image so it's the correct size but no detail is lost when
    printed or zoomed into?

    Many thanks
  • edited March 2009
    Hi Geoff,

    I'm very sorry, I was under the impression that you were using the built-in
    PDF device. We are unable to give support for any third party addons. You
    will need to contact their support (support@waler.com).

    I did notice below that you are setting the TExtraDevices ScaleImages
    property to True. If this behaves similarly to the same property in the
    ReportBuilder PDF device, when it is set to True, the images stored in the
    PDF file are not with full resolution. Try setting this property to False
    and see if that fixes the issue.

    --
    Regards,

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

    Best Regards,

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

    OK - I have removed the ExtraDevices component so it uses the built in
    ReportBuilder PDF functioinality and I still have the same issue.

    To demonstrate I created a small demo program. To try this create a form
    application and drop on a button and aTppReport. Then in the report designer
    drop a TppImage onto the report. Then create the two event methods on form
    create and button click and add the folowing code...

    unit UnitExampleWOExtraDevices;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Printers,
    ppTypes, ppCtrls, ppPrnabl, ppClass, ppCache, ppComm, ppRelatv, ppProd,
    ppReport, ppBands;

    type
    TFormMain = class(TForm)
    ButtonSnapshot: TButton;
    ppReport1: TppReport;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppImage1: TppImage;
    procedure FormCreate(Sender: TObject);
    procedure ButtonSnapshotClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    FormMain: TFormMain;

    implementation

    {$R *.dfm}

    procedure TFormMain.FormCreate(Sender: TObject);
    var
    memo : TMemo;
    i : integer;
    begin
    // Resize form to be large but much smaller than the paper size
    FormMain.Height := 800;
    FormMain.Width := 640;

    // Now add some text to demostrate loss of detail
    memo := TMemo.Create(FormMain);
    memo.Parent := FormMain;
    memo.Height := FormMain.Height - 80;
    memo.Align := alBottom;
    for i := 1 to 100 do
    begin
    memo.Lines.Add('The quick brown fox jumped over the lazy dog. Rooks just
    love my big lump of quartz. 123456789.00');
    end;
    end;


    procedure TFormMain.ButtonSnapshotClick(Sender: TObject);
    var
    MyRect, SourceRect : TRect;
    c: TCanvas;
    h: THandle;
    width, height: Integer;
    begin
    // Snapshot current form
    c := TCanvas.Create;
    c.Handle := GetWindowDC(GetDesktopWindow);
    try
    h := GetForegroundWindow;
    if h <> 0 then
    begin
    // Set up the report
    ppReport1.Units := utPrinterPixels;
    ppReport1.PDFSettings.ScaleImages := true;
    ppReport1.AllowPrintToFile := True;
    ppReport1.PrinterSetup.Orientation := poLandscape;

    // Set up the image to fill the page whilst keeping aspect ratio
    ppImage1.Stretch:= true;
    ppImage1.AutoSize := false;
    ppImage1.MaintainAspectRatio := true;
    ppImage1.Height := ppReport1.Printer.PaperHeight - 200;
    ppImage1.Width := ppReport1.Printer.PaperWidth - 200;

    // Determine size of current form
    GetWindowRect(h, SourceRect);
    width := Abs(SourceRect.Right - SourceRect.Left);
    height:= Abs(SourceRect.Bottom - SourceRect.Top);

    // Copy a snapshot of current form onto the image
    ppImage1.Picture.Bitmap.Width := width;
    ppImage1.Picture.Bitmap.Height := height;
    MyRect := Rect(0, 0, width, height);
    ppImage1.Picture.Bitmap.Canvas.CopyMode := cmSrcCopy;
    ppImage1.Picture.Bitmap.Canvas.CopyRect(MyRect, c, SourceRect);

    ppReport1.Printer.DocumentName:='Snapshot - ' + Caption;

    ppReport1.DeviceType:='Printer';

    // Now print
    ppReport1.Print;

    ppImage1.Picture.Bitmap.FreeImage;
    end;
    finally
    ReleaseDC(0, c.Handle);
    c.Free;
    end;
    end;

    end.


    Now run the program, click the button and save to a PDF file. When viewing
    the PDF file you can see that detail has been lost on the image. If you set
    ppImage1.Stretch to false then no detail is lost but the top & bottom of the
    image is cropped.

    How do I store the image so it's the correct size but no detail is lost when
    printed or zoomed into?

    Many thanks
  • edited March 2009
    Hi Geoff,

    If possible please send a simple example application that demonstrates this
    behavior 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 March 2009
    Nico,

    Many thanks for your help - example program on it's way to you now.

    Note that I have managed to solve the issue when using ExtraDevices by
    turning off CompressImages and it works great.

    However the built-in PDF for Report Builder still has the same problem (and
    before you ask I have tried ppReport1.PDFSettings.CompressionLevel :=
    clNone; and it makes no difference).

    In the zip are two projects and sample PDF files; one from ReportBuilder PDF
    the other from ExtraDevices PDF - compare the two to see what the problem
    is.


    Kind Regards
  • edited October 2010
    Is here a solution yet ?
    I have the same problem.

    When I send the report to devicetype dtScreen, the image on my report is
    very sharp and can be zoomed in without problems.
    With dtPDF, however, the image on the PDF is showing a very low
    resolution, and is "fuzzy" when zoomed in.

    I tried changing several PDFsettings (scaleImages,
    compressionLevel,...), but none of them solves the problem.

    My image is loaded with a quit large and high resolution jpeg, stretched
    to 78 mm wide by 34mm high

    Regards
    Herman
  • edited October 2010
    Hi Herman,

    Which version of ReportBuilder and Delphi are you using?

    You need to be absolutely sure you have the PDFSettings.ScaleImages property
    set to False. Are you loading templates? If so, you need to set this
    property after the template is loaded or it will be overwritten.

    If you are still having issues, please send a simple example that
    demonstrates the problem 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 November 2010
    Op 29/10/2010 3:45, Nico Cizik (Digital Metaphors) schreef:
    Hi Nico,

    I am using version 11.07 Pro (D2009).

    But the problem is solved !
    I was loading a template that overwrote the scaleImages ...

    Thanks
This discussion has been closed.