MarcRB Active Member Licensed User Longtime User May 24, 2018 #1 Hi, I will create a pdf report that contains a background image like a business logo or a fullpage coporate identity. I used two kind of pdf libs and they both work great with small images, but one PDF page can grow up to 12 MB after inserting an 45kB png image file. I discovered that a fullpage (A4) background logo file in png of 45kB file size grows to a bitmap of 12,8MB. Also outside b4a. If I open that png an choose SaveAs *.bmp in any image application the file grows to 12,8Mb . (1785 x 2520 pixels). So bitmap seems to be so big that I want to insert my png without converting to bitmap. Test png image is attached. Note smaller resolution has a big impact on quality. In the pdf code I MUST use LoadBitmap, or maybe there is a way to load a png? At that point my image file is converted to a huge bitmap and it makes the pdf huge also. Code: Copy Dim bmpLogo As Bitmap If File.Exists(AppUtils.cstAppFolder, "logoA4.png") = True Then bmpLogo= LoadBitmap(AppUtils.cstAppFolder, "logoA4.png") PDFWriter1.addImage2(0,AppUtils.mm2pdf(0),(bmpLogo.width/dblFact),(bmpLogo.Height/dblFact),bmpLogo) End If Is there any better way to insert a full page image of good quality in a pdf without making that pdf useless for email, because of its file size ? Attachments logoA4.png 45.3 KB · Views: 486
Hi, I will create a pdf report that contains a background image like a business logo or a fullpage coporate identity. I used two kind of pdf libs and they both work great with small images, but one PDF page can grow up to 12 MB after inserting an 45kB png image file. I discovered that a fullpage (A4) background logo file in png of 45kB file size grows to a bitmap of 12,8MB. Also outside b4a. If I open that png an choose SaveAs *.bmp in any image application the file grows to 12,8Mb . (1785 x 2520 pixels). So bitmap seems to be so big that I want to insert my png without converting to bitmap. Test png image is attached. Note smaller resolution has a big impact on quality. In the pdf code I MUST use LoadBitmap, or maybe there is a way to load a png? At that point my image file is converted to a huge bitmap and it makes the pdf huge also. Code: Copy Dim bmpLogo As Bitmap If File.Exists(AppUtils.cstAppFolder, "logoA4.png") = True Then bmpLogo= LoadBitmap(AppUtils.cstAppFolder, "logoA4.png") PDFWriter1.addImage2(0,AppUtils.mm2pdf(0),(bmpLogo.width/dblFact),(bmpLogo.Height/dblFact),bmpLogo) End If Is there any better way to insert a full page image of good quality in a pdf without making that pdf useless for email, because of its file size ?
Erel B4X founder Staff member Licensed User Longtime User May 27, 2018 #2 Try to draw the image with: https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/ Upvote 0
Try to draw the image with: https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/
MarcRB Active Member Licensed User Longtime User May 29, 2018 #3 Erel, thanks for your reply. Before trying to draw in the canvas I tryed the example in your link. Do I need some special libraries to get the PDFDocument Object. Do I have to download an additional jar file ? I checked library core (V8.00), tried PDF(V0.25) and PDFWriter(v1.10), but still don't get it work. How do I get that PDFdocument object? B4A V8.00 SDK manager API 24 Upvote 0
Erel, thanks for your reply. Before trying to draw in the canvas I tryed the example in your link. Do I need some special libraries to get the PDFDocument Object. Do I have to download an additional jar file ? I checked library core (V8.00), tried PDF(V0.25) and PDFWriter(v1.10), but still don't get it work. How do I get that PDFdocument object? B4A V8.00 SDK manager API 24
Erel B4X founder Staff member Licensed User Longtime User May 30, 2018 #4 You need to download and reference the printing library: https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/ Other libraries are not required. Upvote 0
You need to download and reference the printing library: https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/ Other libraries are not required.
MarcRB Active Member Licensed User Longtime User Jun 1, 2018 #5 Drawing in the canvas, works, but the pdf size is still huge. (Canvas is also a bitmap) Are there other PDF solutions noncommerial or commercial thta can do the job? DonManfred's version has the same problem with this type of image. Or is it possible to change the compression settings of that pdf? If not than I will test again with the library created/edited by DonManfred. In that case I will use 4 images, top header, bottom footer, left and right border.All the Whitepsaces can be excluded. In a setting file I can set the positions and its dimensions of each image. Upvote 0
Drawing in the canvas, works, but the pdf size is still huge. (Canvas is also a bitmap) Are there other PDF solutions noncommerial or commercial thta can do the job? DonManfred's version has the same problem with this type of image. Or is it possible to change the compression settings of that pdf? If not than I will test again with the library created/edited by DonManfred. In that case I will use 4 images, top header, bottom footer, left and right border.All the Whitepsaces can be excluded. In a setting file I can set the positions and its dimensions of each image.