Unduely large PDF file size?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Unduely large PDF file size?

Postby fck » March 22nd, 2014, 5:21 pm

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;
fck
Member
Member
 
Posts: 3
Joined: March 22nd, 2014, 3:55 pm

Re: Unduely large PDF file size?

Postby Kambiz » March 29th, 2014, 8:48 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Unduely large PDF file size?

Postby fck » April 1st, 2014, 3:35 pm

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
fck
Member
Member
 
Posts: 3
Joined: March 22nd, 2014, 3:55 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 21 guests

cron