You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Marcel Stör <ma...@frightanic.com> on 2010/04/08 23:25:09 UTC
Converting/replacing colors
I had my first encounter with PDFBox today...I'm looking into ways to replace a given color in a PDF. I've got some 80 PDFs in which one would like to replace a blueish color with redish (adjust to customer's CI).
Google turned up PDFBox ConvertColorspace. So I tried.
java -cp commons-logging-1.1.1.jar:pdfbox-1.1.0.jar:log4j-1.2.15.jar org.apache.pdfbox.ConvertColorspace -equiv "CMYK:(80,60,0,0)=CMYK:(0,99,100,0)" fr_sample.pdf new_fr_sample.pdf
-> see attached fr_sample.pdf
The completion finished without error but the result is not what I expected. All kinds of colors were replaced instead of just the "blue bars". Is PDFBox not capable of doing what I want it to do or is there a problem with fr_sample.pdf?
Re: Converting/replacing colors
Posted by Marcel Stör <ma...@frightanic.com>.
On 08.04.2010, at 23:25, Marcel Stör wrote:
> I had my first encounter with PDFBox today...I'm looking into ways to replace a given color in a PDF. I've got some 80 PDFs in which one would like to replace a blueish color with redish (adjust to customer's CI).
>
> Google turned up PDFBox ConvertColorspace. So I tried.
>
> java -cp commons-logging-1.1.1.jar:pdfbox-1.1.0.jar:log4j-1.2.15.jar org.apache.pdfbox.ConvertColorspace -equiv "CMYK:(80,60,0,0)=CMYK:(0,99,100,0)" fr_sample.pdf new_fr_sample.pdf
> -> see attached fr_sample.pdf
Ok, looks like mailman stripped the attachment...could have thought of that...
-> http://frightanic.com/misc/fr_sample.pdf
> The completion finished without error but the result is not what I expected. All kinds of colors were replaced instead of just the "blue bars". Is PDFBox not capable of doing what I want it to do or is there a problem with fr_sample.pdf?
Re: Converting/replacing colors
Posted by Marcel Stör <ma...@frightanic.com>.
On 18.04.2010 20:00, Andreas Lehmkuehler wrote:
> Theoretically it should be possible to replace the used cs with PDFBox:
>
> - load the pdf using PDDocument.load
> - search for the used cs (in your case it seems to be named as Cs6)
> - replace the cs
> - save the pdf
>
> If you really like to implement such a program, you should have a look
> at the PDFDebugger which comes with PDFBox. You can use it to visualize
> the content
> of your pdf in a much more understandable way. The cs you are looking
> for can
> be found in the resources dictionary of the page.
Thanks a lot for your valuable feedback!
It looks as if the hardest part is step 3 (replace the cs)...I've got
everything else covered. I can confirm that the actual cs instance is a
org.apache.pdfbox.pdmodel.graphics.color.PDICCBased. However, since all
of this is new stuff for me I'm not yet certain what to do with that object.
Should I create a brand new cs (how to init the values)?
Should I get Java cs from it (would be
java.awt.color.ICC_ColorSpace.getProfile()) and work with that?
Working with the Java cs I saw that the one I'm interested in has a
java.awt.color.ICC_ProfileRGB. So, it would have been cool if there was
a way to replace the RGB values in that given profile :-(
I'll keep digging.
Cheers,
Marcel
--
Marcel Stör, http://www.frightanic.com
Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
Skype: marcelstoer
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Re: Converting/replacing colors
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Marcel Stör schrieb:
> On 08.04.2010, at 23:25, Marcel Stör wrote:
>> I had my first encounter with PDFBox today...I'm looking into ways to replace a given color in a PDF. I've got some 80 PDFs in which one would like to replace a blueish color with redish (adjust to customer's CI).
>>
>> Google turned up PDFBox ConvertColorspace. So I tried.
>>
>> java -cp commons-logging-1.1.1.jar:pdfbox-1.1.0.jar:log4j-1.2.15.jar org.apache.pdfbox.ConvertColorspace -equiv "CMYK:(80,60,0,0)=CMYK:(0,99,100,0)" fr_sample.pdf new_fr_sample.pdf
>> -> see attached fr_sample.pdf
>>
>> The completion finished without error but the result is not what I expected. All kinds of colors were replaced instead of just the "blue bars". Is PDFBox not capable of doing what I want it to do or is there a problem with fr_sample.pdf?
>
>
> Could the fact that I didn't get a reply here mean that PDFBox may be the wrong tool for what I try to accomplish?
AFAIU the ConvertColorspace command line tool is only able to convert a
RGB colorspace into a CMYK colorspace.
> What other PDF manipulation library would be better suited to replace colors?
I don't know any other tool, but that doesn't mean that there isn't any.
I have a look at your document and it seems that the cs you try to replace is an
ICC-based cs. So it isn't that easy to adress it with just 4 CMYK values.
Theoretically it should be possible to replace the used cs with PDFBox:
- load the pdf using PDDocument.load
- search for the used cs (in your case it seems to be named as Cs6)
- replace the cs
- save the pdf
If you really like to implement such a program, you should have a look at the
PDFDebugger which comes with PDFBox. You can use it to visualize the content
of your pdf in a much more understandable way. The cs you are looking for can
be found in the resources dictionary of the page.
BR
Andreas Lehmkühler
Re: Converting/replacing colors
Posted by Marcel Stör <ma...@frightanic.com>.
On 08.04.2010, at 23:25, Marcel Stör wrote:
> I had my first encounter with PDFBox today...I'm looking into ways to replace a given color in a PDF. I've got some 80 PDFs in which one would like to replace a blueish color with redish (adjust to customer's CI).
>
> Google turned up PDFBox ConvertColorspace. So I tried.
>
> java -cp commons-logging-1.1.1.jar:pdfbox-1.1.0.jar:log4j-1.2.15.jar org.apache.pdfbox.ConvertColorspace -equiv "CMYK:(80,60,0,0)=CMYK:(0,99,100,0)" fr_sample.pdf new_fr_sample.pdf
> -> see attached fr_sample.pdf
>
> The completion finished without error but the result is not what I expected. All kinds of colors were replaced instead of just the "blue bars". Is PDFBox not capable of doing what I want it to do or is there a problem with fr_sample.pdf?
Could the fact that I didn't get a reply here mean that PDFBox may be the wrong tool for what I try to accomplish? What other PDF manipulation library would be better suited to replace colors?
Cheers,
Marcel
--
Marcel Stör, http://www.frightanic.com
Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
Skype: marcelstoer
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org