Re: [SPAM] Re: Detect Lines in PDF
FDnC Red <[email protected]>
| Newsgroups | gmane.comp.java.lib.itext.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks Michael. I took your advice and looked closer at PDFContentStreamProcessor.cs and GraphicsState.cs, in fact, I downloaded the source and stepped through it as it was processing the cm operators in my PDF. I guess I'm missing some fundamental thing here because I still do not understand where my lines are getting translated. In the (cm) ModifyCurrentTransformationMatrix function I definitely see this happening: float a = ((PdfNumber)operands[0]).FloatValue; float b = ((PdfNumber)operands[1]).FloatValue; float c = ((PdfNumber)operands[2]).FloatValue; float d = ((PdfNumber)operands[3]).FloatValue; float e = ((PdfNumber)operands[4]).FloatValue; float f = ((PdfNumber)operands[5]).FloatValue; Matrix matrix = new Matrix(a, b, c, d, e, f); GraphicsState gs = processor.gsStack.Peek(); gs.ctm = matrix.Multiply(gs.ctm); The problem is that gs.ctm is always the identity matrix so the matrix.Multiply just sets it to whatever operands were parsed out. I was expecting some actual translation. I guess that is happening somewhere else at a later time. Perhaps after all streams are parsed. Am I just missing the boat here and looking in the wrong place or is this just not possible with iText since it's almost more of a rendering thing - translating what is in the PDF to actual coordinates after all translations are applied? Thanks for your help. Darren On Monday, September 1, 2014 7:47 AM, mkl <[email protected]> wrote: Darren, FDnC Red wrote > I figured out I could setup a PDFContentStreamProcessor and get all line > values from the Pdf operators like this snippet below. The only remaining > problem is I can't get the CTM so my line coordinates are off. > > Listener listener = new Listener(); > PdfContentStreamProcessor processor = new > PdfContentStreamProcessor(listener); > CountOps counter = new CountOps(); //IContentOperator > processor.RegisterContentOperator("q", counter); > processor.RegisterContentOperator("cm", counter); > processor.RegisterContentOperator("m", counter); > processor.RegisterContentOperator("l", counter); > processor.RegisterContentOperator("S", counter); > processor.RegisterContentOperator("Q", counter); > > processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, > 1), res); > > > Is there any way to get the CTM in my IContentOperator class as the > operators are found? I assume I need the CTM so then I can add the matrix > found with the cm operator to find the real coordinates of the line. As you already have found the PdfContentStreamProcessor class, you should inspect it some more and look at its inner IContentOperator implementations PushGraphicsState, PopGraphicsState, and ModifyCurrentTransformationMatrix by default registered for q, Q, and cm, and the GraphicsState class. They can serve as examples on how to process those operators and make the CTM available (GraphicsState.GetCtm). https://svn.code.sf.net/p/itextsharp/code/trunk/src/core/iTextSharp/text/pdf/parser/PdfContentStreamProcessor.cs https://svn.code.sf.net/p/itextsharp/code/trunk/src/core/iTextSharp/text/pdf/parser/GraphicsState.cs Regards, Michael -- View this message in context: http://itext-general.2136553.n4.nabble.com/Detect-Lines-in-PDF-tp4660295p4660310.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php