Q: I'm working with image-based (scanned) PDF documents and I need to
develop a function that allows me to select a rectangular portion of
the page and save the contents of the selected area to a TIFF file.
I'm easily able to select an entire page and export it to an image
file, however I'm having difficulity saving only the selected portion
of the page to an image. I've searched all the sample code and also
visited the support group on Google, but I'm not able to find enough
hints on how to accomplish this. Any code samples or suggestions you
could forward would be appreciated would be appreciated.
A: Perhaps the simplest way to render a subset of a PDF page is to set
a crop box before passing the page to PDFDraw. For example:
Rect old_crop = page.GetCropBox();
After you export the page you may want to restore the previous clip
For a concrete sample code please take a look at example 5 in PDFDraw
Also if you are extending PDFView sample project with this
functionality, make sure that you lock the document before reading or
writing the PDF document.
This will prevent possible collision between the render thread and
your own thread.
The only remaining question is how to implement a user mode tool to
allow the user to select a region (i.e. region_rect in the above code)
of PDF page for export. For a concrete example of how to implement
this functionality you may want to take a look at the impementation of
'rectangular zoom', and 'Link create' tools in PDFView sample