PDF Optimize

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

PDF Optimize

Post by HomerWu »

Hello,

We know tracker provide a operation allows to optimize the PDF document and this is the sample code:
https://sdkhelp.pdf-xchange.com/vie ... t_optimize. i noticed that the parameter named 'Options' contains many sub-parameters which can make diffrent optimized document.i wonder the meaning of the method called 'Zip' in Images->Comp->Method ,can i use it make a zip file or not?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF Optimize

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

ZIP is a compression method not a file, meaning that ZIP compression will be used for the fullcolor image compression.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: PDF Optimize

Post by HomerWu »

Hello Sasha,

Thank you for your reply.But I have other two questions that need to consult you:

1.I found your parameter 'JPEGQuality' contains a value 'Lossless',but when i use it to optimize pdf,i found the iamge changed,can your SDK make a lossless compression picture?
2.Please have a look at my attachment,'1.pdf ' is the original file and '2.pdf' is the compressed document by other soft,I would like to use your SDK to compress PDF and achieve that effect,but failed, i use JPEG2000+Lossless and dpi above is 225 and dpi to is 150,Do you have any suggestions for me?
Attachments
2.pdf
(254.88 KiB) Downloaded 67 times
1.pdf
(2.41 MiB) Downloaded 68 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF Optimize

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Well, you have decreased the dpi thus the downsampling took place. Also, please clarify what image exactly are you talking about?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: PDF Optimize

Post by HomerWu »

Hello Sasha,

Yes,i decreased the dpi from 225 to 150,on color images and grayscale images.the file size becomes smaller,but the the quality of the document is also worse :( .what i want to do is to make the file smaller,with a little(or no) quality change,do you have any good ideas? :P
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

Re: PDF Optimize

Post by Will - Tracker Supp »

Hi Homer,

As Sasha exlpained, the loss in quality is because you lowered the DPI of the image. If you want to retain the image quality, then you will need to compress the image without downsampling. This is done by selecting 'No Downsampling':
https://sdkhelp.pdf-xchange.com/vie ... ze_Options
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: PDF Optimize

Post by HomerWu »

Hello Will,

Thank you for your quick reply.
As you said,i changed my code as below:

Code: Select all

public bool OptimizePDF(string filePath)
{
	PDFXEdit.IPXV_Inst Inst = this.pdfCtl.Inst;
	int nID = Inst.Str2ID("op.document.optimize", false);
	PDFXEdit.IOperation Op = Inst.CreateOp(nID);
	var input = Op.Params.Root["Input"];
	PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
	PDFXEdit.IAFS_Name impPath = fsInst.DefaultFileSys.StringToName(filePath);
	PDFXEdit.IPXC_Inst pxcInst = (PDFXEdit.IPXC_Inst)Inst.GetExtension("PXC");
	PDFXEdit.IPXC_Document resDoc = pxcInst.OpenDocumentFrom(impPath, null);
	//Then pass it to the optimization operation
	input.Add().v = resDoc;
	PDFXEdit.ICabNode options = Op.Params.Root["Options"];
	//Images
	PDFXEdit.ICabNode images = options["Images"];
	//DiscardObjects
	PDFXEdit.ICabNode discardObjects = options["DiscardObjects"];
	//DiscardUserData
	PDFXEdit.ICabNode discardUserData = options["DiscardUserData"];
	//CleanUp
	PDFXEdit.ICabNode cleanup = options["CleanUp"];
	images["Enabled"].v = true;
	images["ReducedOnly"].v = true;

	PDFXEdit.ICabNode comp = images["Comp"];
	PDFXEdit.ICabNode scale = images["Scale"];


	scale["Color.Method"].v = 0;
	//scale["Color.To"].v = scaleColorTo;
	//scale["Color.IfAbove"].v = scaleColorIfAbove;
	comp["Color.JPEGQuality"].v = 5;
	comp["Color.Method"].v = 1;

	//灰度图
	scale["Grayscale.Method"].v = 0;
	//scale["Grayscale.To"].v = scaleGrayscaleTo;
	//scale["Grayscale.IfAbove"].v = scaleGrayscaleIfAbove;
	comp["Grayscale.JPEGQuality"].v = 5;
	comp["Grayscale.Method"].v = 1;

	//索引图
	//scale["Indexed.Method"].v = scaleIndexedMethod;
	//scale["Indexed.To"].v = scaleIndexedTo;
	//scale["Indexed.IfAbove"].v = scaleIndexedIfAbove;
	//comp["Indexed.Method"].v = comIndexedMethod;

	// 黑白图
	scale["Mono.Method"].v = 0;
	//scale["Mono.To"].v = scaleMonoTo;
	//scale["Mono.IfAbove"].v = scaleMonoIfAbove;
	comp["Mono.Method"].v = 0;

	//忽略对象
	discardObjects["Flags"].v = discard;
	//忽略用户数据
	discardUserData["Flags"].v = discardUser;
	//清除
	cleanup["Flags"].v = clear;

	Op.Do();
	resDoc.WriteTo(impPath);
	value = true;
}
the new method created a optimized file,but when i open and zoomed it to 400%,the picture is no longer smooth around,Is my code wrong?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF Optimize

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Well you are using the optimization - it will reduce the data quality from the first place. Anyways it's up to you to experiment and choose the best quality/size settings.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: PDF Optimize

Post by HomerWu »

Hello Sasha,

But as will said 'If you want to retain the image quality, then you will need to compress the image without downsampling',now i set the Color.Method to 0(No downsampling)、Color.Method to 0(Retain existing)、Color.JPEGQuality to 5(Lossless),and the Grayscale is same. Why when i open and zoomed it to 400%,the picture is no longer smooth around?please have a look at my three attachments.
Attachments
OceanFax_High Avaliability_HotSync_20161020.pdf
(2.6 MiB) Downloaded 64 times
OceanFax_High Avaliability_HotSync_20161020_Optimized.pdf
(505.14 KiB) Downloaded 66 times
OceanFax_High Avaliability_HotSync_20161020_OptimizedByPDFXChange.pdf
(703.31 KiB) Downloaded 69 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF Optimize

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Have you tried all of these settings in the End-User Editor?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: PDF Optimize

Post by HomerWu »

Hello Sasha,

Yes,I promise I tried all of these settings in the PDF-XChange Editor,and i also tried all of these settings in my code,because this feature is important for us.We need an optimization function that contains three levels,and now the low and the medium levels have been completed,but the high level which can make the file smaller,with a little(or no) quality change is difficult for me. :cry:
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF Optimize

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

I'm afraid that you will have to try different methods for yourself, compare the results and choose the best one - we can't possibly know what do you want to achieve.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply