ImageFile in hPage is Nothing

Jan 30, 2014 at 7:13 PM
Edited Jan 31, 2014 at 3:18 PM
Not sure if I am using the code properly (having to use VB.Net unfortunately), but I have the following and when it iterates through the pages in PdfCreator.cs, it throws an exception because page.ImageFile is Nothing. Below is my code:
Try
            Dim p As PdfCreator = New PdfCreator()
            Dim h As hDocument = New hDocument()

            h.AddFile("c:\out.html")
            Dim fi As IO.FileInfo = New IO.FileInfo("c:\eurotext.tif")
            h.ImageFile = fi

            p.WritePDF(h, "c:\eurotext.pdf", PdfWriteMode.DrawRects)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
What am I missing?

UPDATE:
Instead of using the pre-compiled assemblies in the hOcr2Pdf solution, I copied the project into my solution and added a reference to the output and it worked. Only problem is, I will need to have this as a pre-compiled assembly. Anyone else run into this issue?
Marked as answer by clockwiseq on 2/6/2014 at 11:37 AM
Coordinator
Feb 5, 2014 at 2:38 PM
Hi clockwiseq,
The ImageFile property gets set automatically when parsing the hocr file. It is the image file that was used for ocr and shouldn't be set directly.

The PDFCreator class does everything for you so that you don't need to use the hDocument class directly.

To build a searchable PDF from an image or images use the AddPage method on the PdfCreator class.

PdfCreator p = new PdfCreator(newPDFPath);

foreach(string i in images){
p.AddPage(i, PdfMode.Ocr);
}

P.SaveAndClose();

I hope this helps.

If you want to use the hDocument class directly, then look at the PdfCreator.AddPage methods for examples.

-Pizzle
Coordinator
Feb 5, 2014 at 2:41 PM
Edited Feb 5, 2014 at 2:43 PM
Here's the code to OCR an existing PDF. Maybe this will help.
    PdfReader reader = new PdfReader(inputPDF);
    PdfCreator writer = new PdfCreator(PdfSettings, outputPDf);
            try
            {
                for (int i = 1; i <= reader.PageCount; i++)
                {
                    string img = reader.GetPageImage (i);

                    if (img == null)
                        continue;

                    writer.AddPage (img, Mode);

                }
                writer.SaveAndClose();
                writer.Dispose();

            }
Feb 5, 2014 at 2:56 PM
Edited Feb 6, 2014 at 7:25 PM
I am so sorry. The code works beautifully when you have the latest version. I downloaded the wrong one. Works great and so appreciative to all your hard work!
Feb 5, 2014 at 5:56 PM
Edited Feb 6, 2014 at 7:37 PM
I have an issue and do not have the resources yet available to post here but will as soon as I have more details.