Android Question PDF file size

ddk1

Member
Licensed User
I have just started using PdfDocument, and like TomKluz in Pdf file size, if I write a bitmap to the pdf I get a much bigger size.
In my case it has nothing to do with screen or scale. Simply 170Kb jpg added to blank pdf = 800Kb pdf.
For example, a tweak on the standard sample given by Erel, but adding a picture rather than drawing lines:
Dim pdf As PdfDocument
pdf.Initialize
pdf.StartPage(595, 842) 'A4 size
Dim bmp as BitMap = LoadBitmap(strDir, strFile)
Dim DestRect as Rect
DestRect.Initialize(0, 0, 595, 842)
pdf.Canvas.DrawBitmap(bmp, Null, DestRect)
pdf.FinishPage
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "1.pdf", False)
pdf.WriteToStream(out)
out.Close
pdf.Close
If the source picture is a jpg, 170Kb. When added and saved as a pdf, the resulting pdf file is 800Kb.
Even if I change the DestRect to be much smaller, I end up with a small picture on the page but its still 800Kb.
I thought maybe its to do with the source being a jpg file, with compression, and the target is uncompressed bitmap embedded in the pdf. However if a use a Pdf editing program to create a pdf and insert this picture, it doesn't end up with such a large pdf.
Is there a way to not have the pdf so large using PdfDocument? In that other post, TomKluz said 'PdfCreator used in B4J' didn't have this problem.
 

ddk1

Member
Licensed User
Simply using LoadBitmapResize keeping same size bitmap does not appear to make a difference. Sure, if I resize it smaller the result is smaller, but I lose quality. I'd already made the original bitmap a size that retained enough detail ie. 170Kb as opposed to 5-10MB straight from the camera.
I used this bit of code to utilize xui.LoadBitmapResize, retaining original size. Is there a different way I should have done it (assuming you don't simply mean resize it smaller)?
B4X:
Dim bmp1 As Bitmap = LoadBitmap(strDir, strFile)
Dim bmp As B4XBitmap = xui.LoadBitmapResize(strDir, strFile, bmp1.Width, bmp1.Height, True).Rotate(90)
ScrRect.Initialize(0, 0, bmp.Width,bmp.Height)
 

ddk1

Member
Licensed User
Ah, I see where you're going. If the full image size is told to show in a small space, it seems you get a larger pdf than necessary. Resizing the image to the smaller target size reduces how much image is embedded in the pdf. In this case, I end up 500Kb for a full page image (less margins). This is better than 800Kb but its still much larger than the original 170Kb image (which was in fact bigger in pixel size). I can live with that if thats the way it is. At least we trimmed it a bit.
 
Top