Sto cercando di estrarre il testo con tutte le informazioni dal pdf utilizzando pdfbox. Ho tutte le informazioni che voglio, tranne il colore. Ho provato diversi modi per ottenere il fontcolor (incluso Getting Text Colour with PDFBox). Ma non funziona. E ora ho copiato il codice dalla classe PageDrawer di pdfBox. Ma poi anche il valore RGB non è corretto.Come ottenere il colore del font utilizzando pdfbox
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());
}
Sto usando il codice sopra. I valori ottenuti sono r = 0, g = 0, b = 0, il valore dell'oggetto di cosp interno è [0.0], all'interno di pd object array = null e colorSpace = null. e il valore RGB è sempre -16777216. Mi aiuti per favore. Grazie in anticipo.
vedo che si stanno ottenendo il nero, di che colore si aspetta? –