logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Paul Rayman  
#1 Posted : Tuesday, January 5, 2016 3:03:03 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Question:
Hi. I want to extract a particular text from a PDF file and store it in a string variable and later use it in forms.
Is there any method to get certain text from the PDF?
I searched Google. I got some examples, but they were not working. Or can u suggest any .Net components that can do the work, with the code examples.

Answer:
The following code example demonstrates how to extract all the text from any pdf page.
This example requires a pdf document named Test001.pdf to be located in the root directory of the drive C.

Code:

public void ExtractText()
{
    //Initialize the SDK library
    //You have to call this function before you can call any PDF processing functions.
    PdfCommon.Initialize();

    //Open and load a PDF document from a file.
    using (var doc = PdfDocument.Load(@"c:\test001.pdf"))
    {
        foreach (var page in doc.Pages)
        {
            //Gets number of characters in a page or -1 for error.
            //Generated characters, like additional space characters, new line characters, are also counted.
            int totalCharCount = page.Text.CountChars;

            //Extract text from page to the string
            string text = page.Text.GetText(0, totalCharCount);

            page.Dispose();
        }
    }

    //Release all resources allocated by the SDK library
    PdfCommon.Release();
}

Edited by user Saturday, October 15, 2016 8:00:52 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.