We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Transparency in PDF
Page Index Toggle Pages: 1
Transparency in PDF (Read 3588 times)
Transparency in PDF
Jun 10th, 2010, 3:01pm
 
Hello,

I have a problem trying to place png transparent images in a PDF.

The code is quite simple, something like that:

PImage imgbasebig = loadImage("image.png");
pdf.image(imgbasebig,0,0,xsize,ysize);

The PDF will have an image inside but the transparent areas of the png are now solid white (or black) areas.

If I do the same but using as destination image a  JAVA2D graphic everything is ok. So, is it a bug? or there is a way to mantain the transparent areas of the original png image inside the pdf.

Thank you!
Re: Transparency in PDF
Reply #1 - Jun 11th, 2010, 1:57am
 
Works for me, even if the end image is quite ugly (looks like transparency becomes binary, not alpha levels).
My relevant code (not "something like that"...) is:
Code:
  PImage img = loadImage("D:/images/earth.png");
PGraphics pdf = createGraphics(512, 512, PDF, "test.pdf");
pdf.beginDraw();
pdf.image(img, 10, 10);
pdf.dispose();
pdf.endDraw();
Re: Transparency in PDF
Reply #2 - Jun 11th, 2010, 2:28am
 
Sorry If I was so plain...

Here is my code:

import processing.pdf.*;
void setup(){
 size(512,512);
}
void draw(){
 PImage img = loadImage("Odlaw.png");
 background(0);
 image(img, 10, 10);
 image(img, 100, 100);
 save("test.jpg");
 PGraphics pdf = createGraphics(512, 512, PDF, "test.pdf");
 pdf.beginDraw();
 pdf.background(0);
 pdf.image(img, 10, 10);
 pdf.image(img, 100, 100);
 pdf.dispose();
 pdf.endDraw();
 exit();
}

In my case, using Processing 1.03, 1.09 and 0184 under Windows, the image inside the pdf loose the treansparency... but it is ok in the jpg

Is it a bug? it work for you under a different OS?.

Thanks.
Re: Transparency in PDF
Reply #3 - Jun 11th, 2010, 6:59am
 
Ah, I was stupid, I suppose I expected a black background, but it was white against the default white of the page...
Indeed, with a background of color, I see the issue.

Now, transparency in PDF isn't a simple topic. If I judge by the message found in RE: [iText-questions] Transparant Images thread:
Quote:
> The pdf format doesn't support ARGB, only RGB. Transparency is done:
>
> - setting an array to mark the transparent colors (6 elements for RGB)
> - creating a BW image to use as a mask
> - creating a grayscale image to use as an smask to have 256 degrees of
alpha

Wow...

So I won't call that a bug, but a limitation... Smiley
Re: Transparency in PDF
Reply #4 - Jun 11th, 2010, 9:38am
 
Hummm it looks like I am in a dead end,  so I must add it to the wish list...

Thank you PhiLho!.
Re: Transparency in PDF
Reply #5 - Jun 11th, 2010, 9:59am
 
what exactly do you need it for ? maybe we can think about some workarounds. For example, you can create a black and white mask of your image and export it as well and then add the mask by hand. Not really convenient but it would be a way to do it.
Re: Transparency in PDF
Reply #6 - Jun 11th, 2010, 11:08am
 
Cedric,

I want to create a PDF with a composition of little images. Like this one http://juanosborne.com/2010/06/11/the-more-difficult-wheres-waldo-ever/ because in the pdf when you zoom you don't loose definition.

I also try to vectorize the png so can spread shapes instead of images. But I cant use tint() with shapes!!!!

I finally found a way... Two shapes, the original and a transparent one over it with disableStyle(). But the final file is huuuuugeeee.

It will be easier if the PDF just accept ARGB...

Perhaps is there is a way to use instances of the shapes in the pdf. Now each time I add a shape the PDF count it as new one, even if it is the same shape.

Best Regards.
Re: Transparency in PDF
Reply #7 - Jun 11th, 2010, 11:23am
 
if you put only images in your pdf, it actually doesnt matter if you output it as pdf or save it as png file for example (except that in an pdf a single image could still be selected) but choosing a pdf doesnt make it a higher resolution, or zoomable without loosing definition. as long it is based on images it doesnt make a difference.
Re: Transparency in PDF
Reply #8 - Jun 11th, 2010, 11:40am
 
Well... my program insert the same image with multiple sizes.

If you insert a big size png in a PDF forcing the target size image(x,y,w,h) you can zoom in the pdf and the little image will show the original resolution...

So in some way I have the original png in different sizes but at full resolution, no matter how little the inserted image is.

With a raster image when you insert it resample the image...

I dont know if I can explaind myself correctly... but it happens this way. I tried it Smiley
Re: Transparency in PDF
Reply #9 - Jun 11th, 2010, 11:49am
 
correct, i didnt thought about it, that you use your images and rescale them, but that means, your images do have different resolutions, so you can zoom in on the little ones, but not on the big ones. but i understand the problem... hmm
Page Index Toggle Pages: 1