1
我有一個包含不同顏色文本和背景顏色的PDF。如何以CMYK或RGB格式識別PDF中使用的顏色?從pdf中識別rgb和cmyk顏色
StringBuilder sb_Sourcepdf = new StringBuilder();
PdfReader reader_FirstPdf = new PdfReader(pdf_of_FirstFile);
Document document = new Document();
PDFParser parser = new PDFParser(new FileInputStream(pdf_of_FirstFile));
parser.parse();
PDDocument docum = parser.getPDDocument();
PDFStreamEngine engine = new PDFStreamEngine();
PDPage page = (PDPage)docum.getDocumentCatalog().getAllPages().get(0);
engine.processStream(page, page.findResources(), page.getContents().getStream());
PDGraphicsState graphicState = engine.getGraphicsState();
string colorname = graphicState.getStrokingColor().getColorSpace().getName();
graphicState.getTextState().getFont();
int r = graphicState.getNonStrokingColor().getJavaColor().getRed();
int g = graphicState.getNonStrokingColor().getJavaColor().getGreen();
int b = graphicState.getNonStrokingColor().getJavaColor().getBlue();
int rgb = graphicState.getNonStrokingColor().getJavaColor().getRGB();
float[] cosp = graphicState.getNonStrokingColor().getColorSpaceValue();
PDColorSpace pd = graphicState.getNonStrokingColor().getColorSpace();
string re = graphicState.getStrokingColor().toString();
int rgbcolor = graphicState.getStrokingColor().getJavaColor().getRGB();
float[] components = { java.awt.Color.black.getRed(), java.awt.Color.black.getGreen(), java.awt.Color.black.getBlue() };
float[] colorSpaceValues = graphicState.getStrokingColor().getColorSpaceValue();
foreach (float c in colorSpaceValues)
{
Debug.WriteLine(c * 255.00);
}
我用PDFBOX但我得到價值0.0
? – pdp 2013-04-18 09:04:44
pdfbox 1.7版本1 – Pragya 2013-04-18 09:05:30
如果您使用的是PDFBox,爲什麼要將問題標記爲「itextsharp」? – 2013-04-18 09:11:28