#1 2011-06-14 16:28:12

fkaynakli
Member
Registered: 2011-06-14
Posts: 12

Transparent PNG support?

Hi;
First of all, this is a great component. I am new at this component but I have two problem:
1. I am using transparent PNG files but when I add these files to PDF, transparency disappear. Did I do something wrong or there is not transparent PNG support.
2. Is it possible to use CMYK colors and images instead of RGB?
Thanks for your help. Best Regards...

Offline

#2 2011-06-14 18:39:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Transparent PNG support?

1. AFAIK transparency is not handled currently.
It sounds like a difficult task:

http://en.wikipedia.org/wiki/Transparency_(graphic)#Transparency_in_PDF wrote:

Transparency in PDF

Starting with version 1.4 of the PDF standard, transparency (including translucency) is supported. This is a very complex model, requiring over 100 pages to document. A key source of complication is that PDF files may contain objects with different color spaces, and blending these is tricky. PDF supports many different blend modes, not just the most common averaging method. In addition, the rules for compositing many overlapping objects allow choices, such as whether a group of objects are blended before being blended with the background, or whether each object in turn is blended into the background.
Adobe Acrobat 5.0 was the first to support PDF 1.4 and, hence, transparent PDF files. Transparency in PDF was carefully designed not to cause errors in PDF viewers that did not understand it, they would simply display all elements as fully opaque. This was a two-edged sword. On the one hand, it reduced errors and complaints about errors; on the other hand it meant people with older viewers, PDF printers, etc. might print something completely different from the original design, increasing complaints about incorrect output. When PDF files are used to prepare work for professional printing, transparency issues could cause millions of printed copies to be incorrect, and have to be destroyed.

Not very encouraging...

One possibility could be to create a wide bitmap including transparent bitmaps drawn over it, computed as a TBitmap using the VCL or Windows API, then draw it in the PDF with the text over it.
Another workaround could be to create a region around your bitmap content, then use it as clipping mask. It should work.

2. CMYK could be handled in PDF generation, but all our bitmap image sources (TGraphic based) are RGB (like in Windows).
It could be possible to overload the TPdfImage.Create constructor to handle CMYK pictures, if the bitmap is provided as C/M/Y/K individual values.
But the PDF reference document doesn't give any sample of such pictures.

Offline

#3 2011-06-14 18:50:43

fkaynakli
Member
Registered: 2011-06-14
Posts: 12

Re: Transparent PNG support?

Thanks for the reply. What about CMYK stroke and fill colors?

Eureka. I added two functions to TPdfCanvas:

procedure TPdfCanvas.SetCMYKFillColor(C, M, Y, K: Byte);
begin
  if FContents<>nil then
    FContents.Writer.AddWithSpace(C/100).AddWithSpace(M/100).AddWithSpace(Y/100).AddWithSpace(K/100).Add('k'#10);
end;

procedure TPdfCanvas.SetCMYKStrokeColor(C, M, Y, K: Byte);
begin
  if FContents<>nil then
    FContents.Writer.AddWithSpace(C/100).AddWithSpace(M/100).AddWithSpace(Y/100).AddWithSpace(K/100).Add('K'#10);
end;

Last edited by fkaynakli (2011-06-14 19:06:13)

Offline

#4 2011-06-15 05:24:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Transparent PNG support?

Nice!

I'll add those to methods the unit.

Offline

#5 2011-06-15 07:28:00

fkaynakli
Member
Registered: 2011-06-14
Posts: 12

Re: Transparent PNG support?

ab wrote:

One possibility could be to create a wide bitmap including transparent bitmaps drawn over it, computed as a TBitmap using the VCL or Windows API, then draw it in the PDF with the text over it.
Another workaround could be to create a region around your bitmap content, then use it as clipping mask. It should work.

How can I achieve clipping with pdfimage? If someone can give a sample code for pdf, I will be very pleased.

Offline

#6 2011-06-15 11:58:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: Transparent PNG support?

To handle clipping, just define a pdf path, then use the Clip method.
You should use GSave and GRestore method calls.

See for instance, how DrawXObjectEx() method implement a rectangular clipping:

procedure TPdfCanvas.DrawXObjectEx(X, Y, AWidth, AHeight: Single;
      ClipX, ClipY, ClipWidth, ClipHeight: Single; const AXObjectName: PDFString);
begin
  DrawXObjectPrepare(AXObjectName);
  GSave;
  Rectangle(ClipX, ClipY, ClipWidth, ClipHeight);
  Clip;
  NewPath;
  ConcatToCTM(AWidth, 0, 0, AHeight, X, Y);
  ExecuteXObject(AXObjectName);
  GRestore;
end;

Offline

Board footer

Powered by FluxBB