Click here to Skip to main content
15,921,840 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
I am trying to make a program which extracts the text from a PDF document PDF documents contain ARABIC text written by different types of FONT

when I extract the text it works with some files and others not it gives me ambiguous Text

I am using c # and Itext7 to make this program

please show me the methodology to do this with some examples

thank you

What I have tried:

StringBuilder processed = new StringBuilder();

           var src = "d:\\text06.pdf";
           var pdfDocument = new PdfDocument(new PdfReader(src));
           var strategy = new LocationTextExtractionStrategy();

           for (int i = 1; i <= pdfDocument.GetNumberOfPages(); i++)
               PdfPage page = pdfDocument.GetPage(i);
               PdfDictionary fontResources = page.GetResources().GetResource(PdfName.Font);
               //foreach (PdfObject font in fontResources.Values(true))

                  // if (font is PdfDictionary)
                   //    fontResources.Put(PdfName.Encoding, PdfName.IdentityH);
              // }

               string output = PdfTextExtractor.GetTextFromPage(page);
           string[] lines = Regex.Split(processed.ToString(), "\n");

           List<String> Converted_Lines = new List<string>();
           foreach (string  s in lines)
               string converted_string = Inverse(s);

           textBox1.Text = String.Join(Environment.NewLine, Converted_Lines);
Asif 7969814 30-Aug-21 11:00am    
use Links to explore more
sahnoune_khaled 30-Aug-21 16:35pm    
Extract text process from pdf document is different than create new one
Extract text from pdf is very defficult
Asif 7969814 31-Aug-21 5:22am    
Yes, you are Right But Can We Use The way Of OCR Computer Vision API And C#.

They have the support of Language
ar (Arabic)
tr (Turkish)
ro (Romanian)
you can read the Full Article here

and this is the Github link

Microsoft Computer vision API link
sahnoune_khaled 31-Aug-21 8:40am    
HiBut My files contains Text Images Font It is ordinaire Pdf File the way of OCR is not good idea
i take the sconde way extarct data of document by parsing the file and search where is the text and Convert it by encoding it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900