PDF Export

edited November 2013 in Library Questions

Hi. I would like to create a multiple page PDF with customized page size (not the usual A0, A3, etc) and gave a look at PDF library examples at processing.org/reference/libraries/pdf/index.html. Googling around I also found Toxi's Specifying PDF page size in Processing

I need to satisfy at the same time these requirements:

1) to export a (big format) PDF while showing a reduced bitmap preview onscreen;

2) the PDF must contain multiple pages;

3) the PDF page size is free and this is independent from the preview size.

To satisfy requirement 1: example Single Frame (With Screen Display) (but PDF page size corresponds to the screen preview and doesn't satisfy 3).

To satisfy requirement 2: example Multiple Pages (No Screen Display) (but there is an image onscreen and 1 is not satisfied).

To satisfy requirement 3: example Using createGraphics() to Create a PDF File (but I cannot find a way to split pages as pdf.nextPage() described in Multiple Pages (No Screen Display) is not available: 2 is not satisfied).

My easy workaround is to create single PDF pages and then collate them using some freeware, but I am searching for an elegant solution (more because of curiosity than real need).

The ideal would be to add a page splitter command to Using createGraphics() to Create a PDF File. Is it possible?

Thank you Alex

Answers

  • Answer ✓
    import processing.pdf.*;
    
    PGraphics pdf = createGraphics(300, 300, PDF, "H:/Temp/output.pdf");
    pdf.beginDraw();
    pdf.background(128, 0, 0);
    pdf.line(50, 50, 250, 250);
    ((PGraphicsPDF) pdf).nextPage();
    pdf.background(0, 128, 0);
    pdf.line(50, 250, 250, 50);
    pdf.dispose();
    pdf.endDraw();
    
  • PhiLho, thank you, as always. It works great! Alex

Sign In or Register to comment.