Print Page | Close Window

How to get "Bounding box" (inked area)

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2140
Printed Date: 22 Nov 24 at 2:36PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to get "Bounding box" (inked area)
Posted By: ADev
Subject: How to get "Bounding box" (inked area)
Date Posted: 10 Feb 12 at 10:58AM
Welcome,
I'm testing library v.8.13, Delphi, DCU.
QP can get MediaBox,CropBox,BleedBox,TrimBox,ArtBox from PDF page.
Any idea, how to get "Bounding box" (inked area) of PDF page without rasterizing?

For example GhostScript can get this by:
gs -dNOPAUSE -dBATCH -sDEVICE=bbox
Result like this:
   %%BoundingBox: 14 37 570 719
   %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158

I'm try:
1. Detect Bounding box (?)
2. Crop page to Bounding box (crop to inked area, removing white margins) - by CapturePage,DrawCapturePage.

How to detect Bounding box?

Regards,
Adam



Replies:
Posted By: AndrewC
Date Posted: 10 Feb 12 at 12:01PM

QP.GetPageBox will allow you to get all the box values you need.

http://www.quickpdflibrary.com/help/quickpdf/GetPageBox.php - http://www.quickpdflibrary.com/help/quickpdf/GetPageBox.php

SetRenderCropType will tell which box to crop when rendering.

http://www.quickpdflibrary.com/help/quickpdf/SetRenderCropType.php - http://www.quickpdflibrary.com/help/quickpdf/SetRenderCropType.php

CapturePage will capture the entire PDF contents and it doesn't know how to crop white margins.  You may have to reset the pages boxes manually to get the margin you need using QP.SetPageBox.

Andrew.

Andrew


Posted By: ADev
Date Posted: 10 Feb 12 at 1:28PM
Andrew, thank you for your answer.

In my pdf file (A3 page), GhostScript return:
%%BoundingBox: 56 78 1119 772
%%HiResBoundingBox: 56.599100 78.070990 1118.497817 771.208992

QP results:
page has only 1 box (QP.HasPageBox): MediaBox: 0,1191,842,1191,842,0

Pdf created by PdfCreator v. 1.2.3 (PdfCreator use GhostScript 9.04)

BoundingBox from GhostScript has a good result.

Any other ideas?

Regards,
Adam


Posted By: AndrewC
Date Posted: 10 Feb 12 at 1:45PM
I would need to see the PDF to make reasonable comment.  It is a bit hard trying to guess without seeing the PDF file.



Posted By: ADev
Date Posted: 10 Feb 12 at 2:27PM
Thanks,
sample file (zip packed) is in:
http://ge.tt/9h1R7SD - Test pdf file


Posted By: AndrewC
Date Posted: 11 Feb 12 at 2:22AM
If you open the PDF file in a text editor you will see that the only page box defined is the MediaBox.

4 0 obj
<</Type/Page/MediaBox [0 0 842 1191]
/Rotate 90/Parent 3 0 R
/Resources<</ProcSet[/PDF /Text]
/Font 8 0 R
>>

It is most likely that GhostScript is keeping track of the rendering process and is updating the bounding box as renders.  Quick PDF Library doens't have this capability.

It is impossible to calculate this value without parsing the full content stream which happens when you render the full file.  You could get a very close approximation by rendering the PDF page to a Bitmap and then checking for pixels in all four directions until a non white pixel is found.

Andrew.




Posted By: ADev
Date Posted: 11 Feb 12 at 5:06PM
Ok Andrew,
thank you for your interest,
I think, GS detect this bounduary by detect all bounduary objects (its faster an rasterizing complete objects), also with rasterizing fonts..
I can't use GS, the commercial problem exists for me.
You are right, inked area is available after rasterizing all of page content.
Im know about http://www.quickpdf.org/forum/implementing-a-new-renderer_topic2109.html - this topic
But .. look in my first post :
"Any idea, how to get "Bounding box" (inked area) of PDF page without rasterizing? "
This is one of the key to my program.
I can analyze bitmaps, but first I need to have the bitmap. Fast have ..
My example file is small, but in reality I use large files (e.g. 900x2000 mm files, with raster and vector contents).
Thank you for good intentions,
I will seek further ..




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk