Beispiel #1
0
        internal static bool CreateHocrFileFromPDF(PDDocument document, string outputfile, bool useWords)
        {
            bool flag;

            try
            {
                PDFHocr pDFHocr = new PDFHocr()
                {
                    getHOCRByWords = useWords
                };
                pDFHocr.setSortByPosition(true);
                pDFHocr.setStartPage(0);
                pDFHocr.setEndPage(document.getNumberOfPages());
                PDFHelper.DisplayTrialPopupIfNecessary();
                if (PDFHelper.AddStamp)
                {
                    pDFHocr.setEndPage(3);
                }
                pDFHocr.writeText(document, new OutputStreamWriter(new ByteArrayOutputStream()));
                if ((pDFHocr.lineList == null ? false : pDFHocr.lineList.Count > 0))
                {
                    HocrPageModel hocrPageModel = new HocrPageModel();
                    hocrPageModel.Lines.AddRange(pDFHocr.SortLineList(pDFHocr.lineList));
                    pDFHocr.pageList.Add(hocrPageModel);
                    pDFHocr.lineList.Clear();
                }
                pDFHocr.GetHocrFromPageList(pDFHocr.pageList, outputfile);
                flag = true;
            }
            catch (Exception exception)
            {
                flag = false;
            }
            return(flag);
        }
Beispiel #2
0
        internal static List <HocrPageModel> GetPageWordDetails(PDDocument document)
        {
            List <HocrPageModel> hocrPageModels;

            try
            {
                PDFHocr pDFHocr = new PDFHocr();
                pDFHocr.setSortByPosition(true);
                pDFHocr.setStartPage(0);
                pDFHocr.setEndPage(document.getNumberOfPages());
                Writer outputStreamWriter = new OutputStreamWriter(new ByteArrayOutputStream());
                PDFHelper.DisplayTrialPopupIfNecessary();
                if (PDFHelper.AddStamp)
                {
                    pDFHocr.setEndPage(3);
                }
                pDFHocr.writeText(document, outputStreamWriter);
                if ((pDFHocr.lineList == null ? false : pDFHocr.lineList.Count > 0))
                {
                    HocrPageModel hocrPageModel = new HocrPageModel();
                    hocrPageModel.Lines.AddRange(pDFHocr.SortLineList(pDFHocr.lineList));
                    pDFHocr.pageList.Add(hocrPageModel);
                    pDFHocr.lineList.Clear();
                }
                hocrPageModels = pDFHocr.pageList;
            }
            catch (Exception exception)
            {
                hocrPageModels = null;
            }
            return(hocrPageModels);
        }
Beispiel #3
0
 public List <HocrPageModel> GetDocumentWordData()
 {
     return(PDFHocr.GetPageWordDetails(this.PDFBoxDocument));
 }
Beispiel #4
0
 public bool GenerateHocrFromText(string outputFileName, bool useWords)
 {
     return(PDFHocr.CreateHocrFileFromPDF(this.PDFBoxDocument, outputFileName, useWords));
 }