Crop White Space

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

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

Post Reply
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Crop White Space

Post by relapse »

Hi, a new question from me:

I try to remove white space with your dialog which I call with this commands:

Code: Select all

object dummy;
pdfViewer.DoVerb("", "ExecuteCommand", "CropPages", out dummy, 0);
Please, test it with the attached file, there is pretty much white space left. Why? Is it possible to optimize the result?



Thanx!
Attachments
test_object.zip
(3.36 KiB) Downloaded 198 times
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Crop White Space

Post by Walter-Tracker Supp »

Crop white space only crops completely empty space around the margins of the PDF page; it is not based on colour. In this case there is a white rectangular object that is larger than the blue rectangle and it crops to fit that. I have attached an image showing where this object sits (the light blue outline surrounds a plain white rectangle that is left by the crop function). If you delete this rectangle from the PDF it crops to the blue rectangle.

FYI, the same thing would occur if you had an embedded image with a white border (as part of that image, e.g. a scanned page) and selected crop whitespace. It would crop to the edge of the image but will not crop the white regions inside of the image. White space is very strictly defined as "parts of the visible PDF page that do not contain objects", ie, they are completely empty. To consider anything else would introduce considerable ambiguity (for example, what if you had a white image on a black page background?).
Attachments
problem.jpg.zip
(21.32 KiB) Downloaded 214 times
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: Crop White Space

Post by relapse »

Thanks for your answer, I was on vacation last week, that's why I reply so late.

Your answer is complete, but it poses the next question: is it possible to delete those unseen embedding objects (you described) with your SDK? If there is a white rectangle embedding the blue rect I'd like to be cropped, could I delete that embedding object?


Thanks!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17906
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Crop White Space

Post by Tracker Supp-Stefan »

Hello Relapse,

It's not possible directly with the Viewer SDK - and pdf manipulation at the level you need is possible with the low-level API in the PDF Tools SDK - but that will require quite some knowledge of the PDF format and structure, and the logic that you will need to use to recognize the unwanted objects before removing them is up to you.

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: Crop White Space

Post by relapse »

Could you please advise me a function from your PDF Tools Library to handle such objects in a pdf document (e.g. a white space object surrounding smaller color object to be cropped -> see the the Walter's answer
a white rectangular object that is larger than the blue rectangle
)?

I couldn't find any...
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Crop White Space

Post by Walter-Tracker Supp »

relapse wrote:Could you please advise me a function from your PDF Tools Library to handle such objects in a pdf document (e.g. a white space object surrounding smaller color object to be cropped -> see the the Walter's answer
a white rectangular object that is larger than the blue rectangle
)?

I couldn't find any...
There is no simple, automated way to do this, in our libraries. I can see how this would be a useful feature (but all things have limits!).


You could do it on your own, but you would have to access the objects on the page and look at their properties using the low level PXCp_ (pro, low level) library functions. To use these functions you need to understand the PDF specification in detail (or learn enough of it to get by), as this library gives direct access to PDF dictionaries, objects, etc.

You could conceivably also roll your own cropping function by rendering the page to memory with the Simple Viewer DLL, and checking the boundaries of the whitespace in that rendering, transforming those coordinates back into PDF page space, and performing the crop. The algorithm you would use to do this would be up to you.

Otherwise, if you have the option, try to re-generate the PDFs without this extra background rectangle.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: Crop White Space

Post by relapse »

this library gives direct access to PDF dictionaries, objects, etc.
How can I determine which objects/dictionaries are related to a certain figure on a pdf page?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17906
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Crop White Space

Post by Tracker Supp-Stefan »

Hi Relapse,

I believe that you will need to "read" the whole PDF Structure and find our the relationship between objects and dictionaries to be able to determine that - not an easy task in any case - and this will need to be done with the low level Tools SDK functions as Walter mentioned and not the Viewer SDK.

Best,
Stefan
Post Reply