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

Re : Transparency and resolution problems with exported PDF

$
0
0
Yeah, I read all those unresolved old posts before I decided to start a new one. I was hoping that, by now, someone has come up with a hack or something. BTW I have tried both SVG libraries and they didn't work at all. I got many errors like other people.

You mentioned iText so I did some investigating. The pdf library is apparently a wrapper for iText. The itext.jar file is together with the pdf.jar file in C:\Program Files\Image\processing-2.0b7\modes\java\libraries\pdf\library\. I hacked together some java code to reproduce the same scenario using pure itext code.

  1. import java.awt.Color;
  2. import java.io.*;
  3. import com.lowagie.text.*;
  4. import com.lowagie.text.pdf.*;
  5. public class imagesPDF
  6. {
  7.     public static void main(String arg[])throws Exception
  8.         {                 
  9.          Rectangle pageRect = new Rectangle (580, 580);
  10.          pageRect.setBackgroundColor(new Color(0x00, 0x00, 0x00));
  11.          Document document = new Document(pageRect);
  12.          PdfWriter.getInstance(document,new FileOutputStream("imagePDF.pdf"));
  13.          document.open();
  14.          Image image = Image.getInstance ("moon.0096_cr.png");
  15.          int ppi = 180;
  16.          image.scalePercent(100*72/ppi);
  17.          //image.scaleAbsolute(document.getPageSize().getWidth()/4, document.getPageSize().getHeight()/4);
  18.          image.setAbsolutePosition(document.getPageSize().getWidth()/2 - image.getScaledWidth()/2, document.getPageSize().getHeight()/2 - image.getScaledHeight()/2);
  19.          document.add(image);
  20.          document.close();
  21.     }
  22. }

The results are surprising and alarming.



The resolution is 180 ppi as in the first example above, BUT the transparency is honored, which is the DEFAULT for PNG in iText PDFs. Same PDF version of 1.4. The transparency shows up in preflight analysis. I don't know what the red X means other than some error, but it may not be good for the service provider. I don't know. But it looks great! I'm getting "high" resolution AND transparency. So now my question is, if this is the default behavior of iText, why isn't it being implemented in the library. I was careful to use the Processing itext.jar, in the directory listed above, directly, to level the playing field, so-to-speak. It is an older version. You will notice that I set the resolution directly with scalePercent so I would get exactly 180 ppi. image.scaleAbsolute(document.getPageSize().getWidth()/4, document.getPageSize().getHeight()/4) gave me like 178.749 ppi. :)

I know people have been able to incorporate calls to iText functions in their .PDE files but I don't know how to mix code like that. Maybe someone here does know and can give an example of how you could make a call to one of the image scale functions from my original script and put the image into the PDF using iText's image function.


Viewing all articles
Browse latest Browse all 1768

Trending Articles