Loading...
Logo
Processing Forum
Some of you, including myself had some problems with the PDF export recently. We discussed it here :
https://forum.processing.org/topic/pdf-export-not-working-anymore

as we really needed the PDF export and the latest processing version we tried to find where the problem is.
After 3 hours, testing and digging in the source code we realized it is a conflict with seltars posttoweb library.

So in case you are having problems. Try to remove the posttoweb folder from the libraries folder.
Worked fine here and solved our problems.

@seltar: its looks like there is some problem with the  PGraphicsPDF.java in your library. Maybe you can check that. 

Replies(1)

Ah, good catch!
Note: the trick I used to get in memory PDF output is no longer needed with recent versions of Processing, as one can properly extend PGraphicsPDF now:
Copy code
  1. import java.io.*;

  2. import processing.core.*;
  3. import processing.pdf.*;

  4. // New version, taking advantage of the new PGraphicsPDF implementing my previous suggestions!
  5. public class InMemoryPGraphicsPDF extends PGraphicsPDF
  6. {
  7.   @Override
  8.   protected void allocate() // Called by PGraphics in setSize()
  9.   {
  10.     output = new ByteArrayOutputStream(16384);
  11.   }
  12.   public byte[] getBytes()
  13.   {
  14.     return ((ByteArrayOutputStream) output).toByteArray();
  15.   }
  16. }
I have this in a .java file and I use it as:
Copy code
  1.   if (frameCount >= 10)
  2.   {
  3.     // Clean up phase
  4.     pdf.dispose();
  5.     pdf.endDraw();
  6.     InMemoryPGraphicsPDF impgpdf = (InMemoryPGraphicsPDF) pdf;  // Get the real renderer
  7.     byte[] pdfData = impgpdf.getBytes();
  8. [...]