Print Page | Close Window

Cropping pages with QuickPDF Library

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=3445
Printed Date: 24 Apr 24 at 3:17PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Cropping pages with QuickPDF Library
Posted By: Richard Langin
Subject: Cropping pages with QuickPDF Library
Date 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.





Replies:
Posted By: tfrost
Date 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?


Posted By: Richard Langin
Date 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.


Posted By: tfrost
Date 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.


Posted By: ukobsa
Date 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


Posted By: tfrost
Date 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.)"


Posted By: tfrost
Date 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.


Posted By: Richard Langin
Date 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.



Posted By: HNRSoftware
Date 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



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