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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Cropping pages with QuickPDF Library
  FAQ FAQ  Forum Search   Register Register  Login Login

Cropping pages with QuickPDF Library

 Post Reply Post Reply
Author
Message
Richard Langin View Drop Down
Beginner
Beginner
Avatar

Joined: 18 Mar 17
Location: Rome
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Richard Langin Quote  Post ReplyReply Direct Link To This Post Topic: Cropping pages with QuickPDF Library
    Posted: 18 Mar 17 at 12:00PM

I’m quite sure I’ve carefully perused QuickPDF’s documentation, examples, references (both developer’s and functions’), yet I could find neither a simple explanation nor an example of a simple and straightforward operation: cropping pages. I’ve read the definition of methods like SetCropBox and SetRenderCropType, still I couldn’t understand how actually cropping is performed, where “actually cropping” trivially means, e.g. : “QuickPDF, take page three in the document loaded into the library and crop it with these top, left, height, width parameters I’m giving you”.

I assume this must be a very simple operation, hence I think / hope helping me will be easy and requiring a very short reply.

Thank you very much.


Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 175
Post Options Post Options   Thanks (1) Thanks(1)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 20 Mar 17 at 6:33PM
Adding a crop box to a page does not change the underlying page, or delete any part of it from the file. As the documentation says, SetCropBox simply defines what part you want to be visible when you later display or print it.  So there is no visible evidence that a crop box exists until you actually render the page to screen or file, or print it.  That's how PDF cropping is done.  Does that explanation help?
Back to Top
Richard Langin View Drop Down
Beginner
Beginner
Avatar

Joined: 18 Mar 17
Location: Rome
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Richard Langin Quote  Post ReplyReply Direct Link To This Post Posted: 20 Mar 17 at 8:40PM
First, thank you for your reply.

That’s the problem: I do understand that the crop box is an “invisible” setting, yet I can’t put it to work effectively. I tried to set a crop box in a document, but after closing the application supposed to change this box, I opened the document back in Acrobat Reader and could see no change in the pages.

Getting straight to the point, may I ask you any example (or just a code snippet) which is supposed to actually crop the page, so that the document appears cropped next time I open it in a reader?

Thank you for your attention & support.
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 175
Post Options Post Options   Thanks (1) Thanks(1)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 21 Mar 17 at 11:29PM
Sorry, though I have worked with crop boxes I do not have to hand an example which does just what you need, and at the moment do not have time to create one specially.  If you are able to post a very simple piece of your own code, to load, apply a crop, and save a file, then someone here may be able to spot what is causing it not to achieve the result you expect.
Back to Top
ukobsa View Drop Down
Senior Member
Senior Member


Joined: 29 May 06
Location: Germany
Status: Offline
Points: 115
Post Options Post Options   Thanks (1) Thanks(1)   Quote ukobsa Quote  Post ReplyReply Direct Link To This Post Posted: 23 Mar 17 at 4:11PM
Richard,

here's a very simple sample:


pdf := TDebenuPDFLibrary.Create;
  try
    pdf.LoadFromFile('d:\downloads\testseite.pdf', '');

    pdf.SetOrigin(0);
    dLeft := pdf.GetPageBox(2,0);
    dTop := pdf.GetPageBox(2, 1);
    dWidth := pdf.GetPageBox(2,2);
    dHeight:= pdf.GetPageBox(2,3);

    // CropBox :=  (dLeft, dTop, dLeft + dWidth, dTop - dHeight)
   
   // reduze size by 50 PDF units
    pdf.SetPageBox(2, dLeft + 50, dTop - 50, dWidth - 2 * 50, dHeight - 2 * 50);
    pdf.SaveToFile('d:\downloads\testseite_red.pdf')
  finally
    pdf.Free;
  end;


But please be aware that visually you will see only a change, when crop box is inside or equal media box (simplified said).
More general: what you see on screen is the intersection of Crop and Media box.

HTH,
Uli
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 175
Post Options Post Options   Thanks (1) Thanks(1)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 24 Mar 17 at 10:23AM
If you see only the intersection, that is exactly what I would expect.  Is it not what you expect?  Here is an explanation from an Adobe manual I have (for PDF 1.7, dated 2008):

"The page object dictionary specifies these boundaries in the MediaBox, CropBox, BleedBox, TrimBox, and ArtBox entries, respectively (see Table 30). All of them are rectangles expressed in default user space units. The crop, bleed, trim, and art boxes shall not ordinarily extend beyond the boundaries of the media box. If they do, they are effectively reduced to their intersection with the media box. Figure 86 illustrates the relationships among these boundaries. (The crop box is not shown in the figure because it has no defined relationship with any of the other boundaries.)"
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 175
Post Options Post Options   Thanks (1) Thanks(1)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 24 Mar 17 at 10:38AM
I should add that your code works for me.  I tried it on an A4 PDF and got a PDF 174.6mm by 261.8mm, with the edge strips of the original document missing.
Back to Top
Richard Langin View Drop Down
Beginner
Beginner
Avatar

Joined: 18 Mar 17
Location: Rome
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Richard Langin Quote  Post ReplyReply Direct Link To This Post Posted: 27 Mar 17 at 2:44PM
I haven’t applied your advice yet; in the meanwhile let me thank you all (Ukobsa first) for your help. Gratefully.

Back to Top
HNRSoftware View Drop Down
Senior Member
Senior Member


Joined: 13 Feb 11
Location: Washington, USA
Status: Offline
Points: 79
Post Options Post Options   Thanks (0) Thanks(0)   Quote HNRSoftware Quote  Post ReplyReply Direct Link To This Post Posted: 07 Apr 18 at 2:58PM
I know this is a bit late, but I needed to do some "cropping" work and based it on ukobsa's example.  I have discovered a few less-than-obvious things. 

First is that the example code only changes the first page.  It is necessary to use a page selection loop to change all of the pages -- that seems to work fine.

Second - this does not actually "crop" anything out of the file -- all of the existing data on each page is still there and the file remains about the same size.  I am guessing that the "SetCropBox" call just adds a small thing to each page telling it where the "useful" data is.

Adobe Acrobat does recognize the "CropBox" and does more or less what you would expect.  I'm not sure of exactly how it treats the cropbox on printing, but it is at least reasonable.

Thanks - Howard


Edited by HNRSoftware - 07 Apr 18 at 2:59PM
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store