Recent

Author Topic: LazReport: TFrTNPDFExportFilter Not Exporting Images  (Read 476 times)

re_Chained

  • New Member
  • *
  • Posts: 11
LazReport: TFrTNPDFExportFilter Not Exporting Images
« on: July 29, 2022, 09:34:50 pm »
Hello all,

I'm playing around with LazReport, trying to export some non-database data to a .pdf via the lazreportpdfexport package. There seems to be an issue when trying to export a report that has an image. The below code will show the report (that has a picture object placed in it) with whatever image is inside Image1, but the resulting exported .pdf will be missing the image.
Code: Pascal  [Select][+][-]
  1. frReport1.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'export.lrf');
  2. TfrPictureView(frReport1.FindObject('Picture1')).Picture.Bitmap.Assign(Image1.Picture.Bitmap);
  3. frReport1.ShowReport;
  4. frReport1.PrepareReport;
  5. frReport1.ExportTo(TFrTNPDFExportFilter, 'export.pdf');

This code, however, works fine and exports as normal:
Code: Pascal  [Select][+][-]
  1. frReport1.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'export.lrf');
  2. TfrPictureView(frReport1.FindObject('Picture1')).Picture.LoadFromFile('image.png');
  3. frReport1.ShowReport;
  4. frReport1.PrepareReport;
  5. frReport1.ExportTo(TFrTNPDFExportFilter, 'export.pdf');

The reason I would like to not load the image from file is because the image may be a .webp, which isn't supported. I'm handling that by allowing a TBGRABitmap object to turn the .webp into a bitmap which I then assign to the TImage. So my question is what's happening that's allowing the report to show the image, but not have it be exported to the resulting .pdf?

I suppose I could dump the Image1.Bitmap to a temp folder and then load that file, or just allow the end user to print the report to a .pdf via LazReport's print preview, but I wanted to see if there was a more direct way.

dseligo

  • Hero Member
  • *****
  • Posts: 807
Re: LazReport: TFrTNPDFExportFilter Not Exporting Images
« Reply #1 on: July 30, 2022, 02:39:35 am »
I use something like this:

Code: Pascal  [Select][+][-]
  1. var frQR: TfrObject;
  2.     Bmp: TBitmap;
  3. ... // create and fill bitmap
  4.   frQR := frReport1.FindObject('Picture1');
  5.   If frQR = nil then Exit;
  6.   If not (frQR is TfrPictureView) then Exit;
  7.  
  8.   (frQR as TfrPictureView).dx := Bmp.Width; //Width
  9.   (frQR as TfrPictureView).dy := Bmp.Height; //Height
  10.   (frQR as TfrPictureView).Picture.Bitmap := Bmp;
  11. ... // free bitmap

re_Chained

  • New Member
  • *
  • Posts: 11
Re: LazReport: TFrTNPDFExportFilter Not Exporting Images
« Reply #2 on: July 30, 2022, 03:25:37 am »
The issue ended up being (I think?) something to do with an incompatibility of sorts between BGRABitmap and LazReportPDFExport. For some reason, if a bitmap is created via a TBGRABitmap object, then assigned back to, say, a TImage, LazReport sees it fine, but it will not export via LazReportPDFExport. Even if I dump the image to a file via Image.Picture.SaveToFile, then load it via TfrPictureView.Picture.LoadFromFile, LazReportPDFExport just will just put a blank image in its place on the .pdf.

However, when I dump the image to a file via TBGRABitmap, then load THAT file into the report picture object, then both the report and LazReportPDFExport see it, and it comes through on the resulting .pdf. Guess that's what I get for mixing library utilities and expecting it all to work together seamlessly...

So I have a form variable of TBGRABitmap that I used to convert the image and I just used that to dump the image to a .bmp file, which I then load into the form picture object then delete after the .pdf is exported. All working fine now.

 

TinyPortal © 2005-2018