Q: We want to move all the page to the top or to move the page a
specific gap from the top. For example 0.2 inch or 0 inch. In the
following example it moved 0 inch from the top
How do I shift content on a PDF page?
----
A: Probably the simplest approach to shift all content on a PDF page
is to translate PDF page boxes (e.g the crop box and media box). This
is illustrated in RectTest sample project (http://www.pdftron.com/net/
samplecode.html#Rect). In this sample the page box is shifted
horizontally, but you can use the same approach to shift content
vertically. Also, besides updating the media box (page.GetMediaBox())
you should also translate the crop box (page.GetCropBox()) and
possibly other page boxes.
In case you would like to latter add new content to shifted pages it
is important to take into account the effect of page translation/
rotation (as described in the following article
http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/10190611076bd2cd/eb7382f49c0ee0fe).
Q: I already saw the RectTest example, and indeed I succeed shifting
the page vertically using the following code:
Rect media_box(pg_itr1.Current().GetMediaBox());
media_box.y1 -= 30;
media_box.y2 -= 30;
media_box.Update();
But my question was how can I know the gap from the media box to the
top of the page in run time.
I cannot use hard coded in my program:
media_box.y1 -= 30;
media_box.y2 -= 30;
-----
A: Media box (or in particular the crop box page.GetCropBox()) defines
the dimensions of a PDF page (box.Width(), box.Height()). It also
defines the offset of the page box relative to the origin of PDF
coordinate system (box.x1, box.y1).
Could you please clarify what you mean by 'the top of the'?
In case you need to find a tight bounding box for all content on the
page, you could use ElementReader - similar to ElementReader/
ElementReaderAdv samples (http://www.pdftron.com/net/
samplecode.html#ElementReader). The idea is that you can use
element.GetBBox(rect) to obtain a bounding box for every element of
the page. Looping through all elements on the page you can compute the
union of all bounding boxes for all content on the page.