Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Transparency and resolution problems with exported PDF

$
0
0
I am trying to create a PDF with image content that has a transparent background. I have tried various methods with disappointing results.

I tried the direct-to-pdf beginRecord(PDF, "filename.pdf") method:

  1. import processing.pdf.*;
  2. void setup() {
  3.     size(580, 580);
  4.     noLoop();
  5.     beginRecord(PDF, "image_test_direct_pdf.pdf");
  6. }
  7. void draw()  {
  8.     PImage img; 
  9.     img = loadImage("moon.0096_cr.png");
  10.     imageMode(CENTER);
  11.     background(0);
  12.     pushMatrix();
  13.         translate(width/2, height/2);
  14.         image(img,0,0,width/4, height/4);
  15.     popMatrix();
  16.     endRecord();
  17. }


This looks great and has 180ppi resolution but the transparency has been replaced with opaque gray.

The buffered pdf surface (PGraphicsPDF) createGraphics(width, height, PDF, "filename.pdf") method:

  1. import processing.pdf.*;
  2. PGraphicsPDF pg;
  3. void setup() {
  4.     size(580, 580);
  5.     pg = (PGraphicsPDF) createGraphics(width, height, PDF, "image_test_pdf_createGraphics.pdf");
  6.     noLoop(); //     Stops Processing from continuously executing the code within draw()
  7. }
  8. void draw()  {
  9.     beginRecord(pg);
  10.         PImage img; 
  11.         img = loadImage("moon.0096_cr.png");
  12.         imageMode(CENTER);
  13.         image(img, width/2, height/2);
  14.         pg.imageMode(CENTER);
  15.         pg.background(0);
  16.         pg.pushMatrix();
  17.             pg.translate(width/2, height/2);
  18.             pg.image(img,0,0,width/4, height/4);
  19.         pg.popMatrix();
  20.     endRecord();
  21. }



Interestingly enough, this also looks just as good but Acrobat is showing only 72ppi. What's up with that?! Same situation with the transparency.

The off-screen buffer createGraphics(width, height) method:

  1. import processing.pdf.*;
  2. PGraphics pg;
  3. void setup() {
  4.     size(580, 580);
  5.     pg = createGraphics(width, height);
  6.     noLoop(); //     Stops Processing from continuously executing the code within draw()
  7. }
  8. void draw()  {
  9.     pg.beginDraw();
  10.         PImage img; 
  11.         img = loadImage("moon.0096_cr.png");
  12.         pg.imageMode(CENTER);
  13.         pg.background(0);
  14.         pushMatrix();
  15.             pg.translate(width/2, height/2);
  16.             pg.image(img,0,0,width/4, height/4);
  17.         popMatrix();
  18.     pg.endDraw();
  19.     image(pg,0,0);
  20.     pg.save("image_test_createGraphics.png");
  21.     beginRecord(PDF, "image_test_createGraphics.pdf");
  22.         image(pg, 0, 0);
  23.     endRecord();
  24. }



Now transparency is being preserved but the resolution is unacceptable. Again it is showing as 72ppi and this time it looks it...

On the PDF Export library page it says

Images don't look great, mostly because of the difference of expectations in how a PDF should look (scalable and high res) versus what happens when image data is written to it at 72 dpi.

And yet in the first example above, image data was written at 180ppi. I don't know why 72ppi would be the default. It is ridiculously low even for a small-screen monitor. But for a PDF which will likely be printed, 300-1200 ppi is the norm. Why isn't this adjustable? Is there a hack that can make it adjustable?

The PDF version of the exported files is 1.4 (Acrobat 5.x), which supports an alpha channel. I even made a PDF of the same version with the original image and the background was transparent. This also should be programmable. Is there a hack for this?

So I don't know where to go from here. It's either horrible resolution or no transparencies. I can't proceed with either situation. Does anyone know a work-around that will give me high resolution AND transparency at the same time. I still need scalable vector graphics as well for text and graphics objects so a high-res image is not an option.



Viewing all articles
Browse latest Browse all 1768

Trending Articles