Hello Peter, Here is an example of how to embed an ICC profile in your pdf and use it as the default colorspace. The code is VB but you should be able to port it to java with minimal effort. Basically the steps I follow in our application are: 1) read the ICC profile data into a byte array 2) create a PdfStream and add the ICC profile data, number of components and alternate colorspace 3) compress the stream data 4) create a new PdfArray and add the PdfName.ICCBASED to the new PdfArray 5) Create a new page, add the PdfStream to the body of the pdf doc and get its indirect reference 6) add that reference to the ICCBased colorspace array 7) add the ICCBased colorspace array to the body of the pdf doc 8) set the page default colorspace to DefaultRGB using the reference to the ICCBased colorspace array (which in turn references the ICC profile data) I figured this out by studying the pdf ref manual, the internals of some of the itext code and opening in a text editor simple pdf docs with icc profiles embeded and examining their structure. Some of the postings on the itext mailing list also helped out. I started this not knowing very much at all about colorspaces, etc. so if anyone knows a better way, please let me know. Example code is below: 'read the icc profile data Dim binReader As New BinaryReader(File.OpenRead("C:\PDFGEN\resources\AdobeRGB1998.icc")) Dim buffer() As Byte buffer = binReader.ReadBytes(binReader.BaseStream.Length) Dim iccprof As ICC_Profile iccprof = ICC_Profile.GetInstance(buffer) 'set up the ICCBased color space data stream Dim iccstream As PdfStream = New PdfStream(iccprof.Data) iccstream.Put(PdfName.N, New PdfNumber(iccprof.NumComponents)) iccstream.Put(PdfName.ALTERNATE, PdfName.DEVICERGB) 'compress the stream data iccstream.FlateCompress() 'ICCBased color space is specified as an array Dim iccarray As PdfArray = New PdfArray iccarray.Add(PdfName.ICCBASED) Dim iccRef As PdfIndirectReference Dim csRef As PdfIndirectReference doc.NewPage() 'add ICC profile data stream to body of pdf doc and get its indirect reference iccRef = writer.AddToBody(iccstream).IndirectReference 'add reference to ICC profile data to ICCBased colorspace array iccarray.Add(iccRef) 'add ICCBased colorspace array to body of pdf doc and get its indirect reference csRef = writer.AddToBody(iccarray).IndirectReference 'set default colorspace to DefaultRGB with a reference to the 'ICCBased colorspace array cb.SetDefaultColorspace(PdfName.DEFAULTRGB, csRef) Good luck! Eliot
Sent with DeskNow Lite - Free mail & groupware server http://www.desknow.com |
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/