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;