Click here to Skip to main content
15,888,527 members
Home / Discussions / C#
   

C#

 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 8:28
mvePIEBALDconsult27-Dec-11 8:28 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
Jan Steyn28-Dec-11 2:08
Jan Steyn28-Dec-11 2:08 
AnswerRe: how can we write large source code in 2 or more seperate units? Pin
BillWoodruff27-Dec-11 5:14
professionalBillWoodruff27-Dec-11 5:14 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
PIEBALDconsult27-Dec-11 5:34
mvePIEBALDconsult27-Dec-11 5:34 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
BillWoodruff27-Dec-11 6:18
professionalBillWoodruff27-Dec-11 6:18 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
#realJSOP27-Dec-11 7:37
mve#realJSOP27-Dec-11 7:37 
GeneralRe: how can we write large source code in 2 or more seperate units? Pin
BillWoodruff27-Dec-11 15:46
professionalBillWoodruff27-Dec-11 15:46 
QuestionReading text using iTextSharp Pin
NarVish26-Dec-11 22:42
NarVish26-Dec-11 22:42 
Hi,

I'm using iTextSharp to read text contents and coordinates of text from PDF. Able to read the text. For few pdfs, it is reading on letter by letter basis.
For eg, instead of reading the below text completely, its retuning F, R, O, M, S, E, R,...
"FROM SERVICER CASSA DI RISPARMIO DI CESENA SPA"

please guide me to solve this issue. Thanks in advance

Code:
C#
private void button1_Click(object sender, EventArgs e)
{
   PdfReader reader = new PdfReader(@"C:\Original.pdf");
   PdfReaderContentParser parser = new PdfReaderContentParser(reader);
   int numberOfPages = reader.NumberOfPages;

   for (int num = 1; num <= numberOfPages; num++)
   {
       TextWithFontExtractionStategy S = new TextWithFontExtractionStategy();
       string F = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, num, S);
   }
}
public class TextInfo
    {
        private double x;
        private double y;
        private double iwidth;
        private double iheight;
        private string strtext;
        public double left
        {
            get
            {
                return x;
            }
            set
            {
                x = value;
            }
        }
        public double top
        {
            get
            {
                return y;
            }
            set
            {
                y = value;
            }
        }
        public double width
        {
            get
            {
                return iwidth;
            }
            set
            {
                iwidth = value;
            }
        }
        public double height
        {
            get
            {
                return iheight;
            }
            set
            {
                iheight = value;
            }
        }
        public string Text
        {
            get
            {
                return strtext;
            }
            set
            {
                strtext = value;
            }
        }
        public StringBuilder strXML = new StringBuilder();
        public string getTextInfo()//out string xmlString)
        {
            string strTextInfo = "";

            strTextInfo = "top:" + y.ToString() + "left:" + x.ToString() + "width:" + iwidth.ToString() + "height:" + iheight.ToString() + "Text:" + strtext;

            string xmlString = "<text top=\""+y.ToString()+" left=\""+x.ToString()+" width=\""+iwidth.ToString()+" height=\""+iheight.ToString()+" font=\"0\">" + strtext +"</text>";

            return strTextInfo;
        }   
    }
public class TextWithFontExtractionStategy : iTextSharp.text.pdf.parser.ITextExtractionStrategy
    {  
        private List<TextInfo> lstTextInfo = new List<TextInfo>();
        private StringBuilder result = new StringBuilder(); 
        //Store last used properties   
        private enum TextRenderMode  
        {
            FillText = 0,  
            StrokeText = 1,
            FillThenStrokeText = 2,    
            Invisible = 3,  
            FillTextAndAddToPathForClipping = 4,  
            StrokeTextAndAddToPathForClipping = 5, 
            FillThenStrokeTextAndAddToPathForClipping = 6,
            AddTextToPaddForClipping = 7 
        } 

        public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            TextInfo txtInfo = getTextInfo(renderInfo);
            Console.WriteLine(txtInfo.getTextInfo());
            lstTextInfo.Add(txtInfo);
        }

        private TextInfo getTextInfo(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
        {
            TextInfo txtInfo = new TextInfo();
            Vector asStartpoint = renderInfo.GetAscentLine().GetStartPoint();
            Vector asEndpoint = renderInfo.GetAscentLine().GetEndPoint();
            Vector dsStartPoint = renderInfo.GetDescentLine().GetEndPoint();
            txtInfo.left = Math.Round(asStartpoint[0]);
            txtInfo.top = Math.Round(612-asStartpoint[1]);
            txtInfo.height = Math.Round(asStartpoint[1] - dsStartPoint[1]);
            txtInfo.width = Math.Round(asEndpoint[0] - asStartpoint[0]);
            txtInfo.Text = renderInfo.GetText();
            if (txtInfo.Text.Contains("closin")) { }
            return txtInfo;
        }
        
        public string GetResultantText()
        {
            return result.ToString(); 
        }
        
        public List<TextInfo> GetTextInfo()
        {
            return lstTextInfo;
        }
        //Not needed 
        public void BeginTextBlock() { }   
        public void EndTextBlock() { }
        public void RenderImage(ImageRenderInfo renderInfo) { }
    } 


modified 27-Dec-11 4:53am.

Questionremoving checkboxes for bool datatypes in DEVEXPRESS grid view Pin
MahaKh26-Dec-11 9:59
MahaKh26-Dec-11 9:59 
AnswerRe: removing checkboxes for bool datatypes in DEVEXPRESS grid view Pin
Richard Andrew x6426-Dec-11 11:18
professionalRichard Andrew x6426-Dec-11 11:18 
AnswerRe: removing checkboxes for bool datatypes in DEVEXPRESS grid view Pin
AmitGajjar26-Dec-11 19:10
professionalAmitGajjar26-Dec-11 19:10 
QuestionHow to add large icon for my app Pin
skylarkcob26-Dec-11 3:13
professionalskylarkcob26-Dec-11 3:13 
AnswerRe: How to add large icon for my app Pin
Shameel26-Dec-11 3:54
professionalShameel26-Dec-11 3:54 
QuestionOOP Advice Pin
Natepizzle24-Dec-11 23:28
Natepizzle24-Dec-11 23:28 
AnswerRe: OOP Advice Pin
#realJSOP25-Dec-11 1:01
mve#realJSOP25-Dec-11 1:01 
GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 9:30
Natepizzle25-Dec-11 9:30 
AnswerRe: OOP Advice Pin
PIEBALDconsult25-Dec-11 4:36
mvePIEBALDconsult25-Dec-11 4:36 
GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 9:33
Natepizzle25-Dec-11 9:33 
GeneralRe: OOP Advice Pin
PIEBALDconsult25-Dec-11 9:57
mvePIEBALDconsult25-Dec-11 9:57 
AnswerRe: OOP Advice Pin
Luc Pattyn25-Dec-11 11:36
sitebuilderLuc Pattyn25-Dec-11 11:36 
AnswerRe: OOP Advice Pin
BillWoodruff25-Dec-11 14:21
professionalBillWoodruff25-Dec-11 14:21 
GeneralRe: OOP Advice Pin
Natepizzle25-Dec-11 22:13
Natepizzle25-Dec-11 22:13 
Questionvalue of using Func and lambdas vs. Delegates vs. Interface ? Pin
BillWoodruff23-Dec-11 23:20
professionalBillWoodruff23-Dec-11 23:20 
AnswerRe: value of using Func and lambdas vs. Delegates vs. Interface ? Pin
PIEBALDconsult24-Dec-11 2:57
mvePIEBALDconsult24-Dec-11 2:57 
AnswerRe: value of using Func and lambdas vs. Delegates vs. Interface ? Pin
Eddy Vluggen24-Dec-11 10:00
professionalEddy Vluggen24-Dec-11 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.