Page 1 of 1

Unduely large PDF file size?

PostPosted: March 22nd, 2014, 5:21 pm
by fck
I am trying to write a ScanToPDF type app by using the TPrintPreview component. It works great apart that the PDF file is larger than I expected. Compared with similar app’s, the file size is about 150Kb vs 60Kb expected. This was done by placing the BMP file (size=650Kb on the TPrintPreview object.

I then tried to convert the BMP file to JPG. The graphic size reduced from 650 to a fair 340Kb, but when the TPrintPreview object save it as PDF, the file size jump to over 900Kb! Am I doing something wrong?

Code: Select all
procedure TfrmScanToPDF.DrawImageOnlyPage;
var
  PR : TRect;
  imgJPG : TJPEGImage;
  S, S1  : String;

begin
   //Comment either one of two options out
   //OPTION 1:--Setup PDF File from a BMP file
{  PDFCreateRoute := 1;   //BMP route
   S := ExtractFilePath(Application.ExeName)+ 'MSPhotoEditorOrg.bmp';
   S1 := GetFileSize(S);
   ShowMessage('Org In-file='+S+' Size='+S1);
   imgInvoice.Picture.LoadFromFile(S);
   PR := PageBoundsAfterMargin;
   ppPrintPreview.PaintGraphicEx(PR,imgInvoice.Picture.Graphic,True,False,True);
}

   //OPTION 2:--Setup PDF File from a JPG file
   PDFCreateRoute := 2;     //JPG route
   S := ExtractFilePath(Application.ExeName)+ 'MSPhotoEditorOrg.bmp';
   S1 := GetFileSize(S);
   ShowMessage('Org In-file='+S+' Size='+S1);
   imgInvoice.Picture.LoadFromFile(S);
   imgJPG := TJPEGImage.Create;
   imgJPG.PixelFormat := jf24Bit;
   imgJPG.Grayscale := False;
   imgJPG.Assign(imgInvoice.Picture.Bitmap);
   imgJPG.CompressionQuality := 30;
   imgJPG.Compress;
   S := ExtractFilePath(Application.ExeName)+ 'DelphiJPG.jpg';
   imgJPG.SaveToFile(S);
   S1 := GetFileSize(S);
   ShowMessage('JPG Out-File='+S+' Size='+S1);
   imgJPG.LoadFromFile(S);
   if imgJPG.Empty then
      ShowMessage('Empty');
   PR := PageBoundsAfterMargin;
   ppPrintPreview.PaintGraphicEx(PR,imgJPG,True,False,True);
   imgJPG.Free;

end;

Re: Unduely large PDF file size?

PostPosted: March 29th, 2014, 8:48 pm
by Kambiz
PiaintGraphic and PaintGraphicEx methods of the component convert the image to device independent bitmap because some printers cannot print any other format. This could be why the PDF size is large.

Re: Unduely large PDF file size?

PostPosted: April 1st, 2014, 3:35 pm
by fck
Thanks! Any possible solutions you can point me to? Are there other methods (or components, hopefully also freeware or openware) that I can perhaps use instead? I am new to this set of components and just got it from some examples. Regards