0
votes

I am trying to get the text from a PDF stored in localStorage in a Windows Phone 8.1 application,but I always get an FileNotFoundException.

To explain the whole story, I get a PDF from an online source, I store it to a folder with name same as the username (The username is an email address, but I tried also without the @ sign) of the user and then I want to get some text from the PDF file. I use iTextSharp and follow the examples, but cannot succeed. When I send the PDF to the Launcher is opening succesfully with another app like Acrobat Reader.

My function is like below. I first send an PDF Object, which has an attribute called Path and it is stored to folder specific to the username of the user. Then I get the pdf as a StorageFile Item. When I create the PDFReader calling the constructor I get a FileNotFoundException. Does anybody knows or can guess what can be the problem? Is iTextSharp compatible with Windows Phone 8.1?

internal async Task<bool> OpenPdfFromDownloadedCollections(PDF pdfToOpen, string username)
    {
        try
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            var pdfFolder = await folder.GetFolderAsync(username + "PDFs");

            var pdf = await pdfFolder.GetFileAsync(Object.Path);

            StringBuilder text = new StringBuilder();
            using (PdfReader reader = new PdfReader(pdf.Path))
            {
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    string thePage = PdfTextExtractor.GetTextFromPage(reader, i, its);
                    string[] theLines = thePage.Split('\n');
                    foreach (var theLine in theLines)
                    {
                        text.AppendLine(theLine);
                    }
                }
            }
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
1
what version of itextsharp are you using? - Boot750
I am using 5.5.6.0 from nuget library - Andreas777
As I can understand from other Posts and videos it may not work with Windows Phone version because of some conflicts with System.Drawing.dll. - Andreas777
Same as i heard. I think you need to check if for other components that can do the trick for you. There is a blogpost of Microsoft blogs.msdn.com/b/eternalcoding/archive/2013/04/15/… maybe thats what you are looking for. - Boot750
The others are all paid and expensive, but are working as I tried a trial one. What I need is to get a barcode from a pdf and display it on screen. Do you know any free library to convert pdf to Image or Text except this one? - Andreas777

1 Answers

0
votes
var pdf = await pdfFolder.GetFileAsync(Object.Path);

In this line of code you should only pass the file name but you are giving the whole Path as parameter. As pdfFolder currently represents the path.