Embed Icc Color Profile in PDF

Embedding ICC profile using Ghostscript

With Ghostscript you can't embed a specific ICC profile in the output PDF at present, with the exception of PDF/A conversion.

This will change within the next few releases. However, you still won't embed the specific profile, you will just direct Ghostscript to use the profile(s), and then set the ColorConversionStrategy to UseDeviceIndependentColor

How to generate proper PDF/A with embedding IIC profile using Ghostscript and Ghostscript .NET

You should not use -dNOSAFER, you should instead add files/directories to the permitted file reading list using the --permit-file-read switch. The file which needs to be read is the OutputIntent profile which is one of the main ingredients of the pdfa_def.ps file. See below.

If you do not include the pdfa_def.ps file then you will not get an OutputIntent in the final PDF/A file and it will not be PDF/A compliant (unless you specify UseDeviceIndependentColor as the ColorConversionStrategy). That's why your code example doesn't work. Noticing that PDF-Tools still says the file is valid, I would stop using that as a validator, it clearly isn't reliable. I've found VeraPDF to be the best validator personally (it's better than the Acrobat built-in verification).

I'm surprised that the command line you have shown at the top of the question produces a valid PDF/A file, unless you have modified the pdfa_def.ps file? You are supposed to and in particular you must modify the value associated with the /ICCProfile key. That value (a string inside parentheses) needs to be a fully qualified path to the ICC profile and either the ICC profile file or the directory it resides in needs to be added to the permitted list of files to read see the documentation here under -dSAFER.

Assuming you have done so, then the resulting PDF file should be a PDF/A-1b conformant file. And indeed according to your question, VeraPDF says it is conformant so I'm unclear on what your problem is there. It would be much more useful to share the input and output PDF files rather than a picture of (part of) the Acrobat display.

So to answer your questions:

  1. Yes there is a way to generate a PDF/A file with ICC information (it isn't valid if it doesn't have an OutputIntent) and your command line does so. If you have not modified the pdfa_def.ps file appropriately you may still have a problem.

  2. As far as I know you run the pdfa_def.ps file using Ghostscript.NET in exactly the same way as you do on the command line, you just put it in the list of arguments. So you just need to uncomment the line you've commented. Of course, you haven't included -dNOSAFER, nor added the ICC profile to the list of permitted files to read, so you will get an error. I am surprised you are getting a fatal error though, I'd expect an invalidaccess, but the obvious thing to do is to add -dNOSAFER to the arguments. The back channel output might be useful, it may have more information, and you haven't included that.

Oh, and I would not write to a pipe either. The pdfwrite device expects to be writing to a file and it may try to seek within the file while writing it. If it does and you've written to a pipe (or other non-seekable output), then it's going to fail.

You don't need to add -f to the argument list, and this:

switches.Add("-dNOPAUSEgsArgs");

looks suspicious to me, that looks like it ought to be -dNOPAUSE.

Finally, if you intend to distribute this application you should check the terms of the AGPL, I believe that Artifex will consider the use of Ghostscript.NET and the Ghostscript DLL to be a 'derivative work' and you may need a commercial license.

Edit

The output_gscommand.pdf has this:

1 0 obj
<</Type /Catalog /Pages 3 0 R
/OutputIntents [ 5 0 R ]
/Metadata 27 0 R
>>

5 0 obj
<</OutputConditionIdentifier(sRGB)
/DestOutputProfile 4 0 R
/S/GTS_PDFA1
/Type/OutputIntent>>
endobj

So that's an OutputIntent specified in the Catalog, the only OutputIntent has a PDFA1 identifier, a valid OutputConditionIdentifier (which is only used for human-readable information), and an ICC profile. As far as I can see that's entirely valid.

Both VeraPDF and the preflight tool in Adobe Acrobat X (Pro) verify the PDF file as conforming. So I think the file is a conforming PDF/A file (the Acrobat X preflight tool also lists the OutputIntent as sRGB(Custom) ICC OutputProfile: "Artifex Software sRGB ICC Profile").

I've no idea why DC is not showing the OutputIntent, I can see no problems with the file.

How do I dump embedded ICC profile information in PDF? (command line or GUI tools)

Here is a command line based method to extract ICC color profiles from a PDF. It uses the Python script pdf-parser.py written by security researcher Didier Stevens which you can download here.

However, this tool is not a specialized tool for ICC extraction. (I do not know such a tool.) It is a generic command line tool to investigate PDF files.

Therefor you need to go through various steps in order to achieve the extraction.

Step 1: Determine the PDF object ID of the ICC profile

You have to use -s to search for the string ICCBased. (PDF files without an embedded ICC profile will not have this keyword [with the exception of possibly using it in their text contents...].)

pdf-parser -s ICCBased my.pdf

My test PDF returned this:

obj 18 0
Type:
Referencing: 21 0 R

It seems that an ICC profile is to be found in PDF object 21.

Step 2: Look at the PDF object found in step 1

You have to use -o 21 to see what PDF object 21 is:

pdf-parser.py -o 21 my.pdf

My test PDF returns this:

obj 21 0
Type:
Referencing:
Contains stream

<<
/Alternate /DeviceRGB
/Filter /FlateDecode
/Length 2574
/N 3
>>

Ok, this looks like we are getting close...

Step 3: Dump the stream contained in the PDF object containing the profile

In step 2 we acquired two important infos:

  • The PDF object 21 contains a stream (the contents of which are not shown by using the -o 21 parameter of pdf-parser.py).
  • The object stream has to be de-compressed with the /FlateDecode in order to get to its content.

Hence we have to run pdf-parser.py now with two additional arguments:

  • -d filename in order to dump the stream of PDF object 21 to a file.
  • -f in order to filter/un-compress the object stream when dumping it to a file.
  • Command to run: pdf-parser.py -o 21 -f -d 21.stream my.pdf

Step 4: Verify what was extracted

We now have dumped the stream of PDF object 21 to a file named 21.stream. Let's see what it contains:

file 21.stream
21.stream: Microsoft ICM Color Profile

Looks like we succeeded. :-)

Step 5: Open the color profile

I'll see if my Mac OSX system does accept this profile:

mv 21.stream 21.icm
open 21.icm

OSX uses the 'Color Sync Utility' to open the file and display a window. Clicking on the list entries opens different information panes at the bottom of the window:

Mac OSX  'Color Sync Utility' showing various infos about the extracted ICM profile.


Step 6: Use Argyll's iccdump to dump the contents of the ICC profile as text

Note, that Graeme Gill's ArgyllCMS, the open source color management software, available for Linux, Mac OSX and Windows, ships with a whole suite of command line tools. One of these is iccdump. We can use it to look at the properties of the newly won 21.icm file:


iccdump 21.icm

icc:
Header:
size = 3144 bytes
CMM = 'Lino'
Version = 2.1.0
Device Class = Display
Color Space = RGB
Conn. Space = XYZ
Date, Time = 9 Feb 1998, 6:49:00
Platform = Microsoft
Flags = Not Embedded Profile, Use anywhere
Dev. Mnfctr. = 'IEC '
Dev. Model = 'sRGB'
Dev. Attrbts = Reflective, Glossy
Rndrng Intnt = Perceptual
Illuminant = 0.964203, 1.000000, 0.824905 [Lab 100.000000, 0.000498, -0.000436]
Creator = 'HP '

tag 0:
sig 'cprt'
type 'text'
offset 336
size 51
Text:
No. chars = 43
0x0000: Copyright (c) 1998 Hewlett-Packard Company

tag 1:
sig 'desc'
type 'desc'
offset 388
size 108
TextDescription:
ASCII data, length 18 chars:
0x0000: sRGB IEC61966-2.1
No Unicode data
ScriptCode Data, Code 0x0, length 18 chars
0x0000: 73 52 47 42 20 49 45 43 36 31 39 36 36 2d 32 2e 31 00

tag 2:
sig 'wtpt'
type 'XYZ '
offset 496
size 20
XYZArray:
No. elements = 1

tag 3:
sig 'bkpt'
type 'XYZ '
offset 516
size 20
XYZArray:
No. elements = 1

tag 4:
sig 'rXYZ'
type 'XYZ '
offset 536
size 20
XYZArray:
No. elements = 1

tag 5:
sig 'gXYZ'
type 'XYZ '
offset 556
size 20
XYZArray:
No. elements = 1

tag 6:
sig 'bXYZ'
type 'XYZ '
offset 576
size 20
XYZArray:
No. elements = 1

tag 7:
sig 'dmnd'
type 'desc'
offset 596
size 112
TextDescription:
ASCII data, length 22 chars:
0x0000: IEC http://www.iec.ch
No Unicode data
ScriptCode Data, Code 0x0, length 22 chars
0x0000: 49 45 43 20 68 74 74 70 3a 2f 2f 77 77 77 2e 69 65 63 2e 63 68 00

tag 8:
sig 'dmdd'
type 'desc'
offset 708
size 136
TextDescription:
ASCII data, length 46 chars:
0x0000: IEC 61966-2.1 Default RGB colour space - sRGB
No Unicode data
ScriptCode Data, Code 0x0, length 46 chars
0x0000: 49 45 43 20 36 31 39 36 36 2d 32 2e 31 20 44 65 66 61 75 6c 74 20
...

tag 9:
sig 'vued'
type 'desc'
offset 844
size 134
TextDescription:
ASCII data, length 44 chars:
0x0000: Reference Viewing Condition in IEC61966-2.1
No Unicode data
ScriptCode Data, Code 0x0, length 44 chars
0x0000: 52 65 66 65 72 65 6e 63 65 20 56 69 65 77 69 6e 67 20 43 6f 6e 64
...

tag 10:
sig 'view'
type 'view'
offset 980
size 36
Viewing Conditions:
XYZ value of illuminant in cd/m^2 = 19.644501, 20.371796, 16.808899
XYZ value of surround in cd/m^2 = 3.928894, 4.074387, 3.361786
Illuminant type = D50

tag 11:
sig 'lumi'
type 'XYZ '
offset 1016
size 20
XYZArray:
No. elements = 1

tag 12:
sig 'meas'
type 'meas'
offset 1036
size 36
Measurement:
Standard Observer = 1931 Two Degrees
XYZ for Measurement Backing = 0.000000, 0.000000, 0.000000 [Lab 0.000000, 0.000000, 0.000000]
Measurement Geometry = Unknown
Measurement Flare = 1.0%
Standard Illuminant = D65

tag 13:
sig 'tech'
type 'sig '
offset 1072
size 12
Signature
Technology = Cathode Ray Tube Display

tag 14:
sig 'rTRC'
type 'curv'
offset 1084
size 2060
Curve:
No. elements = 1024

tag 15:
sig 'gTRC'
type 'curv'
offset 1084
size 2060
Curve:
No. elements = 1024

tag 16:
sig 'bTRC'
type 'curv'
offset 1084
size 2060
Curve:
No. elements = 1024

P.S.:

ArgyllCMS contains a command line tool, extracticc, which can extract an embedded ICC profile from a TIFF file. It does not have a tool to extract a profile from a PDF file.

Include ICC Colour Profile in PDF created with Objective-C iOS?

After a lot of searching I've concluded this isn't possible. Documentation is thin on the ground and what does exist usually refers to Mac OSX, not iOS.
ColorSync, as suggested by Moose, appears to be restricted to images and UI elements, and I can see no way of including it in PDF creation. Closing.



Related Topics



Leave a reply



Submit