1

Can i count charts in pdf using iTextSharp? I've made code for finding images, but charts are saved in some diffrent way (for example MATLAB charts). Can i do it in some way with iTextSharp ? BTW. My main goal is to delete all images and charts from pdf.

Bartosz Olchowik
  • 1,129
  • 8
  • 22
  • If your charts are *"saved in some diffrent way"* than (bitmap) images, they most likely are stored as vector graphics. Vector graphics instructions can be put into a content stream (page, XObject, ...) in an arbitrary order and arbitrarily intermingled with other page content. In particular it is neither clear how many separate charts (in a human viewer's eyes) are on a single page (if there are vector graphics at all) nor is it clear whether some instructions, drawing e.g. a line, are part of a chart or probably merely underlining some text word or separating text as a horizontal rule. – mkl Jun 18 '18 at 15:40
  • Thus, you will have to analyze the locations of those instructions. If there is a region with many vector graphics instructions and not more than a few text drawing instructions, that region probably constitutes a chart (or multiple charts next to each other). If there is a region with much text and merely a few vector graphics, they probably are text blocks with underlines or colored backgrounds or something alike. Chart legends may have a balanced ratio of text and graphics... You can find tools for graphics extraction in the `...parser` namespace, in particular the `IExtRenderListener`. – mkl Jun 18 '18 at 15:47
  • Thank you mkl, i will try to extract graphics, and i will inform here about results with solution code, if i'd get to that point. – Bartosz Olchowik Jun 18 '18 at 16:22
  • So far it seems to be working ,i mean if there is any graph or chart, which isnt image on page, RenderPathCounter,ModifyPathCounter or ClipPathCounter are having high values- i declared some counters, and i'm incrementing them everytime program is entering those functions. Now i have to get location of these graphics from functions of `IExtRenderListener` - `RenderImage,RenderPath,ModifyPath,ClipPath `func. I havent got clue what RenderPath,ModifyPath or ClipPaths contains. Can i get location of those Vector Graphics elements ? – Bartosz Olchowik Jun 18 '18 at 17:44
  • oh wait, i found something already: https://stackoverflow.com/questions/32560215/pdf-coordinate-system-in-itextsharp Seems to be legit, heh. Thank you again @mkl for your valuable response ! – Bartosz Olchowik Jun 18 '18 at 17:49
  • @BartoszOlchowik, you mentioned that you created code to find an image in a PDF. Is that true? I need to do the same thing. We are looking at trying to compare an image in a PDF and if found we would pull extract that page in the PDF and create a new PDF. Could you help me with that? – Andy Mar 10 '23 at 14:37
  • @Andy yes, i done it but im kinda busy right now. – Bartosz Olchowik Apr 14 '23 at 13:40

0 Answers0