You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Hesham Gneady <he...@gmail.com> on 2019/01/07 09:22:05 UTC

PDFBox gets wrong font color values from PDF file!

Hello,

 

In this sample PDF file:

https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?dl=0

I am trying to check the font colors for all letters, but I have noticed
that PDFBox gets colors with values partially different from the ones that I
see in Adobe Acrobat. I use this code:

    @Override

    public void processTextPosition( TextPosition t )  {

      try {

             PDGraphicsState gs = getGraphicsState();

Color color = new Color( gs.getNonStrokingColor().toRGB() );

System.out.println( color.getRed() );

System.out.println( color.getGreen() );

System.out.println( color.getBlue() );        

      } 

       catch (IOException ioe) {}

    }

 

For example PDFBox prints the values: 

Red:64, Green:96, Blue:172

 

While in Adobe Acrobat the values appear as:

Red:66, Green:105, Blue:178

 

Is there a reason for this?

 

Best regards,

Hesham 

 

 



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

RE: PDFBox gets wrong font color values from PDF file!

Posted by Hesham Gneady <he...@gmail.com>.
Now it's clear. Thanks a lot Tilman 😊


Best regards,
Hesham

--------------------------------------------------------------------------------------------------
Included Message:

It's the CMYK icc profile from Adobe. We can't include it because of the license. We use a different icc profile.

The code below reinitializes the CMYK colorspace with that icc profile.

Tilmam

Am 10.01.2019 um 09:09 schrieb Hesham Gneady:
> That has fixed this, and the colors appear with right RGB values now!
> I am not sure what this file does, but it has fixed it!
>
> Thanks a lot Tilman.
>
>
> Best regards,
> Hesham
>
> ----------------------------------------------------------------------
> ----------------------------
> Included Message:
>
> Add this at the beginning of your software:
>
>
>           PDDeviceCMYK.INSTANCE = new PDDeviceCMYK()
>           {
>               @Override
>               protected ICC_Profile getICCProfile() throws IOException
>               {
>                   return ICC_Profile.getInstance("USWebCoatedSWOP.icc");
>               }
>           };
>
> Get the ICC file here:
>
> https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.ht
> ml
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox gets wrong font color values from PDF file!

Posted by Tilman Hausherr <TH...@t-online.de>.
It's the CMYK icc profile from Adobe. We can't include it because of the 
license. We use a different icc profile.

The code below reinitializes the CMYK colorspace with that icc profile.

Tilmam

Am 10.01.2019 um 09:09 schrieb Hesham Gneady:
> That has fixed this, and the colors appear with right RGB values now!
> I am not sure what this file does, but it has fixed it!
>
> Thanks a lot Tilman.
>
>
> Best regards,
> Hesham
>
> --------------------------------------------------------------------------------------------------
> Included Message:
>
> Add this at the beginning of your software:
>
>
>           PDDeviceCMYK.INSTANCE = new PDDeviceCMYK()
>           {
>               @Override
>               protected ICC_Profile getICCProfile() throws IOException
>               {
>                   return ICC_Profile.getInstance("USWebCoatedSWOP.icc");
>               }
>           };
>
> Get the ICC file here:
>
> https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: PDFBox gets wrong font color values from PDF file!

Posted by Hesham Gneady <he...@gmail.com>.
That has fixed this, and the colors appear with right RGB values now!
I am not sure what this file does, but it has fixed it!

Thanks a lot Tilman.


Best regards,
Hesham

--------------------------------------------------------------------------------------------------
Included Message:

Add this at the beginning of your software:


         PDDeviceCMYK.INSTANCE = new PDDeviceCMYK()
         {
             @Override
             protected ICC_Profile getICCProfile() throws IOException
             {
                 return ICC_Profile.getInstance("USWebCoatedSWOP.icc");
             }
         };

Get the ICC file here:

https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox gets wrong font color values from PDF file!

Posted by Tilman Hausherr <TH...@t-online.de>.
Add this at the beginning of your software:


         PDDeviceCMYK.INSTANCE = new PDDeviceCMYK()
         {
             @Override
             protected ICC_Profile getICCProfile() throws IOException
             {
                 return ICC_Profile.getInstance("USWebCoatedSWOP.icc");
             }
         };

Get the ICC file here:

https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: PDFBox gets wrong font color values from PDF file!

Posted by Hesham Gneady <he...@gmail.com>.
Tilman,

 

I haved used exactly the same code in the "PrintTextColors.java" to print the colors in my PDF sample. I have just added a couple of lines to the processTextPosition(...) method to print the RGB colors, like this:

@Override

protected void processTextPosition( TextPosition text )  {  

               try {

                               super.processTextPosition(text);

                               PDColor strokingColor = getGraphicsState().getStrokingColor();

                               PDColor nonStrokingColor = getGraphicsState().getNonStrokingColor();

                               Color fontColor = new Color( nonStrokingColor.toRGB() );

                               String unicode = text.getUnicode();

                               RenderingMode renderingMode = getGraphicsState().getTextState().getRenderingMode();

                               System.out.println("Unicode:            " + unicode);

                               System.out.println("Rendering mode:     " + renderingMode);

                               System.out.println("Stroking color:     " + strokingColor);

                               System.out.println("Non-Stroking color: " + nonStrokingColor);

                               System.out.println("Non-Stroking color: " + nonStrokingColor);

                               System.out.println("Letter color:      " + fontColor.getRGB() + " => R:" + fontColor.getRed() + ", G:" + fontColor.getGreen() + ", B:" + fontColor.getBlue() );

                               System.out.println();

               }

               catch (IOException ioe) {}

}

 

In my sample PDF file there is the title "Strawberry Smoothie and Fruit Toast" for example. It prints the following for the first "S" letter:

Unicode:            S

Rendering mode:     FILL

Stroking color:     PDColor{components=[0.0], patternName=null}

Non-Stroking color: PDColor{components=[0.805, 0.613, 0.0, 0.0], patternName=null}

Non-Stroking color: PDColor{components=[0.805, 0.613, 0.0, 0.0], patternName=null}

Letter color:      -12558164 => R:64, G:96, B:172

 

The last line shows the RGB colors, which appear different in Adobe Acrobat.

I hope my exaplanation now is more clear.

 

Best regards,

Hesham

 

--------------------------------------------------------------------------------------------------

Included Message:

 

Am 08.01.2019 um 11:16 schrieb Hesham Gneady:

> Thanks Telman!

>   

> I have tested the PrintTextColors example and I am getting the same results!

> Still, PDFBox reports RGB values different than the ones I see in 

> Adobe Acrobat when using the PrintTextColors example with my PDF sample.

 

 

Yes but what colors are wrong? All of them, some of them, or what?

 

I can't investigate if you're not telling me where you searched.

 

The example tool also outputs some text. That makes it easier to find the actual color command in the content stream.

 

Tilman

 

 

 

> 

> 

> Best regards,

> Hesham Gneady

> 

> ----------------------------------------------------------------------

> ------

> ----------------------

> Included Message:

> 

> Hi,

> 

> Please use the PrintTextColors example and combine this to your code, 

> then show where these colors come up, i.e. for what glyph. Hopefully 

> at the beginning or at the end of the output.

> 

> Tilman

> 

> Am 07.01.2019 um 10:22 schrieb Hesham Gneady:

>> Hello,

>> 

>>    

>> 

>> In this sample PDF file:

>> 

>>  <https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?d> https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?d

>> l

>> =0

>> 

>> I am trying to check the font colors for all letters, but I have 

>> noticed that PDFBox gets colors with values partially different from 

>> the ones that I see in Adobe Acrobat. I use this code:

>> 

>>       @Override

>> 

>>       public void processTextPosition( TextPosition t )  {

>> 

>>         try {

>> 

>>                PDGraphicsState gs = getGraphicsState();

>> 

>> Color color = new Color( gs.getNonStrokingColor().toRGB() );

>> 

>> System.out.println( color.getRed() );

>> 

>> System.out.println( color.getGreen() );

>> 

>> System.out.println( color.getBlue() );

>> 

>>         }

>> 

>>          catch (IOException ioe) {}

>> 

>>       }

>> 

>>    

>> 

>> For example PDFBox prints the values:

>> 

>> Red:64, Green:96, Blue:172

>> 

>>    

>> 

>> While in Adobe Acrobat the values appear as:

>> 

>> Red:66, Green:105, Blue:178

>> 

>>    

>> 

>> Is there a reason for this?

>> 

>>    

>> 

>> Best regards,

>> 

>> Hesham

>> 

>>    

>> 

>>    

>> 

>> 

>> 

>> ---

>> This email has been checked for viruses by Avast antivirus software.

>>  <https://www.avast.com/antivirus> https://www.avast.com/antivirus

>> 

> 

> ---------------------------------------------------------------------

> To unsubscribe, e-mail:  <ma...@pdfbox.apache.org> users-unsubscribe@pdfbox.apache.org

> For additional commands, e-mail:  <ma...@pdfbox.apache.org> users-help@pdfbox.apache.org

> 

> 

> 

> ---------------------------------------------------------------------

> To unsubscribe, e-mail:  <ma...@pdfbox.apache.org> users-unsubscribe@pdfbox.apache.org

> For additional commands, e-mail:  <ma...@pdfbox.apache.org> users-help@pdfbox.apache.org

> 

 

 

---------------------------------------------------------------------

To unsubscribe, e-mail:  <ma...@pdfbox.apache.org> users-unsubscribe@pdfbox.apache.org

For additional commands, e-mail:  <ma...@pdfbox.apache.org> users-help@pdfbox.apache.org

 


Re: PDFBox gets wrong font color values from PDF file!

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 08.01.2019 um 11:16 schrieb Hesham Gneady:
> Thanks Telman!
>   
> I have tested the PrintTextColors example and I am getting the same results!
> Still, PDFBox reports RGB values different than the ones I see in Adobe
> Acrobat when using the PrintTextColors example with my PDF sample.


Yes but what colors are wrong? All of them, some of them, or what?

I can't investigate if you're not telling me where you searched.

The example tool also outputs some text. That makes it easier to find 
the actual color command in the content stream.

Tilman



>
>
> Best regards,
> Hesham Gneady
>
> ----------------------------------------------------------------------------
> ----------------------
> Included Message:
>
> Hi,
>
> Please use the PrintTextColors example and combine this to your code, then
> show where these colors come up, i.e. for what glyph. Hopefully at the
> beginning or at the end of the output.
>
> Tilman
>
> Am 07.01.2019 um 10:22 schrieb Hesham Gneady:
>> Hello,
>>
>>    
>>
>> In this sample PDF file:
>>
>> https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?dl
>> =0
>>
>> I am trying to check the font colors for all letters, but I have
>> noticed that PDFBox gets colors with values partially different from
>> the ones that I see in Adobe Acrobat. I use this code:
>>
>>       @Override
>>
>>       public void processTextPosition( TextPosition t )  {
>>
>>         try {
>>
>>                PDGraphicsState gs = getGraphicsState();
>>
>> Color color = new Color( gs.getNonStrokingColor().toRGB() );
>>
>> System.out.println( color.getRed() );
>>
>> System.out.println( color.getGreen() );
>>
>> System.out.println( color.getBlue() );
>>
>>         }
>>
>>          catch (IOException ioe) {}
>>
>>       }
>>
>>    
>>
>> For example PDFBox prints the values:
>>
>> Red:64, Green:96, Blue:172
>>
>>    
>>
>> While in Adobe Acrobat the values appear as:
>>
>> Red:66, Green:105, Blue:178
>>
>>    
>>
>> Is there a reason for this?
>>
>>    
>>
>> Best regards,
>>
>> Hesham
>>
>>    
>>
>>    
>>
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: PDFBox gets wrong font color values from PDF file!

Posted by Hesham Gneady <he...@gmail.com>.
Thanks Telman!
 
I have tested the PrintTextColors example and I am getting the same results!
Still, PDFBox reports RGB values different than the ones I see in Adobe
Acrobat when using the PrintTextColors example with my PDF sample.


Best regards,
Hesham Gneady

----------------------------------------------------------------------------
----------------------
Included Message:

Hi,

Please use the PrintTextColors example and combine this to your code, then
show where these colors come up, i.e. for what glyph. Hopefully at the
beginning or at the end of the output.

Tilman

Am 07.01.2019 um 10:22 schrieb Hesham Gneady:
> Hello,
>
>   
>
> In this sample PDF file:
>
> https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?dl
> =0
>
> I am trying to check the font colors for all letters, but I have 
> noticed that PDFBox gets colors with values partially different from 
> the ones that I see in Adobe Acrobat. I use this code:
>
>      @Override
>
>      public void processTextPosition( TextPosition t )  {
>
>        try {
>
>               PDGraphicsState gs = getGraphicsState();
>
> Color color = new Color( gs.getNonStrokingColor().toRGB() );
>
> System.out.println( color.getRed() );
>
> System.out.println( color.getGreen() );
>
> System.out.println( color.getBlue() );
>
>        }
>
>         catch (IOException ioe) {}
>
>      }
>
>   
>
> For example PDFBox prints the values:
>
> Red:64, Green:96, Blue:172
>
>   
>
> While in Adobe Acrobat the values appear as:
>
> Red:66, Green:105, Blue:178
>
>   
>
> Is there a reason for this?
>
>   
>
> Best regards,
>
> Hesham
>
>   
>
>   
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox gets wrong font color values from PDF file!

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Please use the PrintTextColors example and combine this to your code, 
then show where these colors come up, i.e. for what glyph. Hopefully at 
the beginning or at the end of the output.

Tilman

Am 07.01.2019 um 10:22 schrieb Hesham Gneady:
> Hello,
>
>   
>
> In this sample PDF file:
>
> https://www.dropbox.com/s/2z5b3vrvnzjo0lo/Font%20color%20Sample.pdf?dl=0
>
> I am trying to check the font colors for all letters, but I have noticed
> that PDFBox gets colors with values partially different from the ones that I
> see in Adobe Acrobat. I use this code:
>
>      @Override
>
>      public void processTextPosition( TextPosition t )  {
>
>        try {
>
>               PDGraphicsState gs = getGraphicsState();
>
> Color color = new Color( gs.getNonStrokingColor().toRGB() );
>
> System.out.println( color.getRed() );
>
> System.out.println( color.getGreen() );
>
> System.out.println( color.getBlue() );
>
>        }
>
>         catch (IOException ioe) {}
>
>      }
>
>   
>
> For example PDFBox prints the values:
>
> Red:64, Green:96, Blue:172
>
>   
>
> While in Adobe Acrobat the values appear as:
>
> Red:66, Green:105, Blue:178
>
>   
>
> Is there a reason for this?
>
>   
>
> Best regards,
>
> Hesham
>
>   
>
>   
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org