I tried the code in the link you provided, and it worked for me. The colors I get are 148.92, 179.01001 and 214.965. I wish I could provide you with my PDF file for work, maybe if I save it externally for SO? My PDF used a shade of blue that seemed to fit. It was just one page of text, created in Word 2010 and exported, nothing too intense.
A few suggestions ....
- Recall that the return value is a float between 0 and 1. If the value is accidentally chosen for int, then, of course, the values ββwill contain almost all 0. The code associated is a multiple of 255 to get a range from 0 to 255.
- As the commentator said, the most common color for a PDF file is black, which is 0 0 0
That's all I can think of now, otherwise I have version 1.7.1 from pdfbox and fontbox, and as I said, I pretty much followed the link you gave.
EDIT
Based on my comments, is there perhaps a slight invasive way to do this for PDFs such as color.pdf ?
In PDFStreamEngine.java in PDFStreamEngine.java method can be executed inside try block
if (operation.equals("RG")) { // stroking color space System.out.println(operation); System.out.println(arguments); } else if (operation.equals("rg")) { // non-stroking color space System.out.println(operation); System.out.println(arguments); } else if (operation.equals("BT")) { System.out.println(operation); } else if (operation.equals("ET")) { System.out.println(operation); }
This will show you the information, then itβs up to you to process the color information for each section according to your needs. Below is a snippet from the beginning of the output of the above code when running on color.pdf ...
BT rG [COSInt(1), COSInt(0), CosInt(0)] RG [COSInt(1), COSInt(0), CosInt(0)] ET BT ET BT rG [COSFloat{0.573}, COSFloat{0.816}, COSFloat{0.314}] RG [COSFloat{0.573}, COSFloat{0.816}, COSFloat{0.314}] ET ......
In the above, you see the empty BT ET section, this is the section labeled DEVICEGRAY. All the others give you the values ββ[0,1] for the components R, G and B
demongolem
source share