I have a PDF that consists of different color text and background color. How do I identify which colors are used in the PDF with CMYK or RGB format?
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); }
I used pdfbox but I am getting value as 0.0