Search code examples
areapdflib

How do I set the display area in PDFLIB


When I set the PDF paper size to A4, is there a way to make the PDF display area only A5 size while keeping the PDF paper size to A4? Parts of text or images larger than A5 will not be displayed. I have try the option 'CropBox',but it's make A4 size to A5 size. please help me !!


Solution

  • you could clip the content by first creating a clipping path. This could look like:

    p.being_page_ext(595, 842, "");
    p.save();
    p.rect(0, 0, 421, 595);
    p.clip();
    ... (place content which will only visible within the A5 area)
    p.restore()
    ... further content which will be visible on the whole page.
    p.end_page_ext("");
    

    I added the save()/restore(), so you can encapsulate the clipping and can add additional content afterwards. Please adjust also the reference point for the clipping rectangle if necessary.

    Please see PDFlib 9.3 Tutorial, chapter 3.2.3 "Direct Paths and Path Objects" for details.