Errors in PDF

Apr 4, 2013 at 8:28 AM
Hello,
I have wrote a small console application to convert the hocr to pdf.
Every PDF have errors! On acrobat 7 I got: Token Type not recognized.

here is my code:
static List<Image> GetAllPages(string file)
        {
            List<Image> images = new List<Image>();
            Image bitmap = Image.FromFile(file);
            int count = bitmap.GetFrameCount(FrameDimension.Page);
            for (int idx = 0; idx < count; idx++)
            {
                // save each frame to a bytestream
                bitmap.SelectActiveFrame(FrameDimension.Page, idx);
                MemoryStream byteStream = new MemoryStream();
                bitmap.Save(byteStream, ImageFormat.Tiff);

                // and then create a new Image from it
                images.Add(Image.FromStream(byteStream));
            }
            return images;
        }

        static void Main(string[] args)
        {
            Clock.hocr.Elements.hDocument hdoc = new Clock.hocr.Elements.hDocument();
            hdoc.AddFile("out2.html");
            Clock.hocr.PDFSettings pdfset = new Clock.hocr.PDFSettings();
            pdfset.ImageType = Clock.hocr.PdfImageType.JPeg;
            pdfset.ImageQuality = 50;

            pdfset.Dpi=300;

            pdfset.WriteTextMode = Clock.hocr.WriteTextMode.Word;
            
    
            
            Clock.hocr.PdfCreator pdfcreat = new Clock.hocr.PdfCreator(pdfset,"test2.pdf");
            List<Image> pages = GetAllPages("test2.tif");

            
            
            for (int i = 0; i<hdoc.Pages.Count;i++)
            {
                Clock.hocr.Elements.hPage hpage = hdoc.Pages[i];
                pdfcreat.AddPage(hpage, pages[i]);


            }

            
            pdfcreat.SaveAndClose();
        }
Coordinator
Jun 6, 2013 at 6:57 PM
Hi Ibaxx,
For what you are attempting to do, you only need to use the PDFCreator and PDFSettings class.
hDocument and related hPage, etc... classes are internals that are used by the PDFCreator class.
        Clock.hocr.PDFSettings pdfset = new Clock.hocr.PDFSettings();
        pdfset.ImageType = Clock.hocr.PdfImageType.JPeg;
        pdfset.ImageQuality = 50;
        pdfset.Dpi=300;
        pdfset.WriteTextMode = Clock.hocr.WriteTextMode.Word;

        Clock.hocr.PdfCreator pdfcreat = new Clock.hocr.PdfCreator(pdfset,"test2.pdf");
        pdfcreat.AddPage(Image.FromFile("test2.tif"));

        pdfcreat.SaveAndClose();
I hope this helps.

-Pizzle