Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Reduce PDF file size |
Post Reply |
Author | |
kk aw
Team Player Joined: 02 Feb 10 Location: Malaysia Status: Offline Points: 36 |
Post Options
Thanks(0)
Posted: 12 Mar 14 at 10:14AM |
I have a large pdf document, and I want to reduce the document size. Can I use replaceimage and clearimage to reduce the document size? In my test with both version 9.16 and 10.13, it does not seem to work. The replaceimage function always returned 0. Does this mean that it failed? Using the clearimage function by itself works and the image is no longer visible in the document. Unfortunately, the filesize is not reduced. |
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
I expect you've already tried this but just in case, have you used the compress page function so that QP reduces your PDF as much as possible?
For a = 1 To QP.PageCount Call QP.SelectPage(a) Call QP.CompressPage Next a QP.SaveToFile (SaveString) Worth mentioning just in case.
|
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
|
In versions of Debenu Quick PDF Library since version 8 or so the CompressImages flag has been set to true.
This flag does not resize images. All it does is turn on image compression so that when a PDF file is saved then the image data is compressed and stored much like a Zip file compresses a file. If the image data in the PDF is not compressed (quite rare these days) then compressing it will save some space. Most files will not be affected. Currently if you would like to resample and downscale images then you would need to extract the image, load the image into an image processing library such as ImageEn, ImageMagick - process it and then call QP.ReplaceImage to replace the image with smaller compressed, lower quality image data. Andrew.
|
|
kk aw
Team Player Joined: 02 Feb 10 Location: Malaysia Status: Offline Points: 36 |
Post Options
Thanks(0)
|
I use the following codes to convert the bmp image format to jpg image format:
procedure TMainform.ConvertImage1Click(Sender: TObject); var i,j,n: Integer; ImgID, nImgID: Integer; ImgCount: Integer; ImgName1, ImgName2: widestring; ImgType: Integer; ImgConverted: Integer; FPrivdir: string; FileExt: string; FFileName: string; retval: Integer; Fsize1, FSize2: Integer; begin Screen.Cursor := crHourGlass; FPrivdir:= sm.slashAdd(LmdSysInfo1.TempPath); FileExt:= sm.locase(ElcomboBox1.Text); FSize1:= Qp.GetDocumentFileSize; ImgConverted:= 0; try ImgCount := Qp.FindImages; j:= 1; imgId := QP.GetImageID(j); while j <= ImgCount do begin qp.SelectImage(ImgID); ImgType := Qp.ImageType; if ImgType = 2 then begin ImgName1 := FPrivdir + Format('PdfImage%d.bmp',[j]); ImgName2 := FPrivdir + Format('PdfImage%d.%s',[j,FileExt]); QP.SaveImageToFile(Imgname1); If sm.EqualIC(FileExt,'jpg') then Bmp2Jpeg(ImgName1, ImgName2) else if sm.EqualIC(FileExt,'gif') then continue else if sm.EqualIC(FileExt,'png') then continue; If FileExists(imgname2) then begin nImgID:= qp.AddImageFromFile(ImgName2,0); if nImgID = 0 then begin ShowMessage('Cannot addimagefromfile '+ImgName2); exit; end; end else begin ShowMessage(ImgName2 + ' not found'); exit; end; retval:= qp.ReplaceImage(ImgID, nImgID); If retval = 0 then begin ShowStatusBar('Image not replaced'); Sleep(500); end else begin retval:= qp.ClearImage(ImgID); If retval = 0 then ShowMessage('Image not cleared'); end; FSize2:= Qp.GetDocumentFileSize; Inc(ImgConverted); end; Inc(j); imgId := QP.GetImageID(j); end; Screen.Cursor := crDefault; If ImgConverted > 0 then begin ShowMessage(Format('%d Embedded images successfully converted.'+crlf+ 'Originalsize: %d New size: %d',[ImgConverted, FSize1, FSize2])); FFileName:= FSelectedFile; n:= sm.posIC('.pdf', FFileName); System.Insert('[IR]',FFileName, n); Qp.SaveToFile(FFileName); end else ShowStatusBar('No image to convert or converted'); finally Screen.Cursor := crDefault; end; end; procedure TMainform.Bmp2Jpeg(const BmpFileName, JpgFileName: string); var Bmp: TBitmap; Jpg: TJPEGImage; begin Bmp := TBitmap.Create; Jpg := TJPEGImage.Create; try Bmp.LoadFromFile(BmpFileName); Jpg.Assign(Bmp); Jpg.SaveToFile(JpgFileName); finally Jpg.Free; Bmp.Free; end; end; The image files in bmp and jpg as exported. The retval in the line: retval:= qp.ReplaceImage(ImgID, nImgID) is always 0. If I carry one regardless, qp.clearimage(imgid) returns 1..... The image-replaced file size is slightly bigger than the original. Any ideas what is happening? |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store