Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get font color using pdfbox
    text
    copied!<p>I am trying to extract text with all information from the pdf using pdfbox. I got all the information i want, except color. I tried different ways to get the fontcolor (including <a href="https://stackoverflow.com/questions/5861471/getting-text-colour-with-pdfbox">Getting Text Colour with PDFBox</a>). But not working. And now I copied code from PageDrawer class of pdfBox. But then also the RGB value is not correct. </p> <pre><code>protected void processTextPosition(TextPosition text) { Composite com; Color col; switch(this.getGraphicsState().getTextState().getRenderingMode()) { case PDTextState.RENDERING_MODE_FILL_TEXT: com = this.getGraphicsState().getNonStrokeJavaComposite(); int r = this.getGraphicsState().getNonStrokingColor().getJavaColor().getRed(); int g = this.getGraphicsState().getNonStrokingColor().getJavaColor().getGreen(); int b = this.getGraphicsState().getNonStrokingColor().getJavaColor().getBlue(); int rgb = this.getGraphicsState().getNonStrokingColor().getJavaColor().getRGB(); float []cosp = this.getGraphicsState().getNonStrokingColor().getColorSpaceValue(); PDColorSpace pd = this.getGraphicsState().getNonStrokingColor().getColorSpace(); break; case PDTextState.RENDERING_MODE_STROKE_TEXT: System.out.println(this.getGraphicsState().getStrokeJavaComposite().toString()); System.out.println(this.getGraphicsState().getStrokingColor().getJavaColor().getRGB()); break; case PDTextState.RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT: //basic support for text rendering mode "invisible" Color nsc = this.getGraphicsState().getStrokingColor().getJavaColor(); float[] components = {Color.black.getRed(),Color.black.getGreen(),Color.black.getBlue()}; Color c1 = new Color(nsc.getColorSpace(),components,0f); System.out.println(this.getGraphicsState().getStrokeJavaComposite().toString()); break; default: System.out.println(this.getGraphicsState().getNonStrokeJavaComposite().toString()); System.out.println(this.getGraphicsState().getNonStrokingColor().getJavaColor().getRGB()); } </code></pre> <p>I am using the above code. The values getting are r = 0, g = 0, b = 0, inside cosp object value is [0.0], inside pd object array = null and colorSpace = null. and RGB value is always -16777216. Please help me. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload