How to save PDF as 'reduced size' ?

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, 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
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

How to save PDF as 'reduced size' ?

Post by whoit »

Hi -
We have a situation where we are watermarking PDFs with a lot of pages (500 - 1500 or more) and the resulting file size is extremely large
when compared to the original.
If we open the file in Acrobat Pro, we can re-save it as 'reduced size' and get it to something more manageable.

Is there a way to accomplish this (reduced size, optimized - whatever terms works) using CoreAPI ?

For example - a PDF with All Text, no graphics:
original PDF = 158kb
processed/watermarked = 5.2mb
Acrobat Reduced = 502kb

This is becoming an issue for our clients as initial PDFs can start at a few hundred kb and balloon to dozens of mb.....

Here's a link to download some samples:
www.coastallogic.com/wayne/pages_501.zip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Hello whoit,

Every watermarks that is being added on each page is a unique XForm with unique content. You have 14 different watermark types added on different pages - this results in 11022 X-Object Forms that take 4.7 mb of space. We are adding unique XForms because watermarks hold macros and they need to be unique because the content itself can differ from page to page.
You have several ways of fixing this:
1) Use Editor-Level's Optimizer to shrink down PDF sizes.
2) Do not use watermarks at all (that is if you don't need them to be in the manage watermarks window). You can just add text blocks with needed font parameters and coordinates - this will shrink PDF size a lot.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

Hi Alex -

We're not using the Editor API so unless #1 is available in Core, we can't do that.

Regarding item #2, for some reason we've never even seen the 'text blocks' option - is this available in Core?
If so, what is the method?

Thanks.
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

Hi Alex -

One more question - what is Acrobat doing to the file when I use the 'reduce' save method?
Can this same technique be used from the Core API?

-Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

You should use this method: https://sdkhelp.pdf-xchange.com/vie ... wTextBlock
Search the forums for more information.

As for the optimizer - it is an Editor plugin that can only be used in the Editor's level.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

My main concern with a textblock would be this:
Do we have to supply a fixed size (specifically width) ?

For example, with Watermark, we specify a string+font+size and it gets printed as long (wide) as necessary.
Should I assume that we would need to get the string length first if we want the textbox to be wide enough to
accommodate the string without wrapping/truncating?

Also, not to stray too far in this thread, but - what does the RTF flag (nFlags, PXC_DrawTextFlags Enumeration) allow for?
Does this mean I can use an RTF-coded string and get, for example, one word on a line in a different font and color than the rest of the line?
Is there any sample code for this (any language) ?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Hello whoit,

As for the show text block you should first use it with the CalcTextSize method to calculate the output rectangle. The pRect parameter specifies the maximum rectangle into which your text should be written into. Then you will have the pTextBounds as an output with real text size.
As for the DTF_RichText flag - for this one the text should be in the XFA formatting - pass this as text with this flag and it should work.
Here's the link to the specification:
http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf
You should read the 27 Rich Text Reference about how to write the XFA formatted text.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

OK, thanks Alex....I'll dig into this and most likely will get back to you...
-Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

OK, Alex - I've played a bit and have a few more questions about ShowTextBlock

1) Do the config options in ContentCreator override the settings in the XFA formatting?
Which options take precedence ?
For example, what if Font Size is set using both ContenCreator.SetFontSize and within XFA text (CSS) ?

2) How can I determine the required size of the TextBox if there are multiple lines, mixed fonts and sizes, etc (again, XFA formatting, <br> tags, and so forth)?
ContentCreator.CalcTextSize seems to only be useful for single lines....
For example, how do I know the textbox will be large enough to hold all the text?

More to come... :)

-Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

1) Not sure about this one - I think the font size of the Content Creator will be overwritten. To set the default parameters for the XFA, you can use the IPXC_CharFormat and IPXC_ParaFormat parameters. Anyways - you can make a simple test for yourself with this one and try - from what I remember, the default font size for the XFA is 12.

2) I did not mean the IPXC_ContentCreator::CalcTextSize method - what I meant was that you should pass the DTF_CalcSizeOnly along with the DTF_RichText flag in the ShowTextBlock method. As for the rectangle - you can take the visual top left corner of the area that you need the text to be placed into and the bottom right will be the visual end of the page - can't make it bigger that that.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

Hi Alex -

For #1 - ok, I can do a few tests no problem. My original question extends to most of the flags, like wordwrap, etc.

For #2 - Ah, I understand - I can use the two DTF flags to return the required size without placing the text.

NEW: I noticed that the DrawTextFlags are not exclusive - meaning, it appears I can set BOTH "Justify" and "Right",
however in practice, they are exclusive. Is there a 'compound' usage that I'm not aware of ? NO
How are these reconciled if multiple items are selected ? See below
OK - I tested this and the result is lowest value wins, except for "Left" because it's 0.
So the results are:
justify | right = right
justify | left = justify
left | right = right
justify | justify all = justify

NEW: What do each of these flags mean? I there is no description in the documentation...
DTF_AllowPartial
DTF_AlignMask
DTF_FirstPara
DTF_LastPara
DTF_AddClip


Thanks,
Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Hello Simon,

DTF_AllowPartial - to don't break before last partially visible line in last visible paragraph.
DTF_AlignMask - holds flags of all of the Aligns (for bit operations).
DTF_AddClip - the rectangle specified as Clip will be used if this flag is specified, if that parameter is NULL then the pRect will be used as clip.

About the Para - will need to consult with the dev who made this.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

OK, thanks this helps...

-Wayne

P.S. Not "Simon" :)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

Sorry again :)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to save PDF as 'reduced size' ?

Post by whoit »

No Worries...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to save PDF as 'reduced size' ?

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply