我有一个由不同颜色文本和背景颜色组成的PDF。如何识别使用CMYK或RGB格式的PDF中使用的颜色?
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
答案 0 :(得分:1)
PdfReader reader_FirstPdf = new PdfReader(pdf_of_FirstFile);
for (int i = 1; i <= reader_FirstPdf.NumberOfPages; i++)
{
TextWithFont_SourcePdf Sourcepdf = new TextWithFont_SourcePdf();
}
text_First_File = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader_FirstPdf, i, Sourcepdf);
public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
{
int r = renderInfo.GetColorNonStroke().R;
int g = renderInfo.GetColorNonStroke().G;
int b = renderInfo.GetColorNonStroke().B;
}