pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hesham Gneady" <heshamgne...@gmail.com>
Subject RE: PDFBox gets wrong font color values from PDF file!
Date Wed, 09 Jan 2019 19:17:48 GMT
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:  <mailto:users-unsubscribe@pdfbox.apache.org> users-unsubscribe@pdfbox.apache.org

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

> 

> 

> 

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

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

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

> 

 

 

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

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

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

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message