예제 #1
0
파일: PdfTools.cs 프로젝트: labeuze/source
        public static void ProcessContentPage(PdfReader reader, int page, Test_iTextSharp.ITextExtractionStrategy strategy)
        {
            PdfReaderContentParser parser = new PdfReaderContentParser(reader);

            PdfDictionary pageDic = reader.GetPageN(page);
            PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);

            Test_iTextSharp.PdfContentStreamProcessor processor = new Test_iTextSharp.PdfContentStreamProcessor(strategy);
            byte[] bytes = ContentByteUtils.GetContentBytesForPage(reader, page);
            processor.ProcessContent(bytes, resourcesDic);
        }
예제 #2
0
파일: xpdf.cs 프로젝트: labeuze/source
        //public static void GetTextFromPage(PdfReader reader, int pageNumber, Test_iTextSharp.ITextExtractionStrategy strategy)
        //{
        //    PdfReaderContentParser parser = new PdfReaderContentParser(reader);

        //    PdfDictionary pageDic = reader.GetPageN(pageNumber);
        //    PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);

        //    Test_iTextSharp.PdfContentStreamProcessor processor = new Test_iTextSharp.PdfContentStreamProcessor(strategy);
        //    byte[] bytes = ContentByteUtils.GetContentBytesForPage(reader, pageNumber);
        //    processor.ProcessContent(bytes, resourcesDic);
        //}

        //public static string GetTextBlock(Test_iTextSharp.TextBlock textBlock)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    bool first = true;
        //    foreach (Test_iTextSharp.TextChunk chunk in textBlock.text)
        //    {
        //        if (first)
        //            first = false;
        //        else
        //            sb.Append(" ");
        //        sb.Append(chunk.text);
        //    }
        //    // attention les blocks enfants ne sont pas traités
        //    //foreach (Test_iTextSharp.TextBlock child in textBlock.childs)
        //    return sb.ToString();
        //}

        //public static string[] gettextblockbylines(test_itextsharp.textblock textblock, int maxcol)
        //{
        //    list<string> lines = new list<string>();
        //    stringbuilder sb = new stringbuilder();
        //    bool first = true;
        //    foreach (test_itextsharp.textchunk chunk in textblock.text)
        //    {
        //        if (sb.length + 1 + chunk.text.length > maxcol)
        //        {
        //            lines.add(sb.tostring());
        //            sb.clear();
        //            first = true;
        //        }
        //        if (first)
        //            first = false;
        //        else
        //            sb.append(" ");
        //        sb.append(chunk.text);
        //    }
        //    lines.add(sb.tostring());
        //    // attention les blocks enfants ne sont pas traités
        //    //foreach (test_itextsharp.textblock child in textblock.childs)
        //    return lines.toarray();
        //}

        public static void PrintTextBlock(TextWriter tw, Test_iTextSharp.TextBlock textBlock, int depth)
        {
            string indent = "";
            for (int i = 0; i < depth; i++) indent += "  ";
            tw.Write("{0}block {{", indent);
            //tw.WriteLine(indent + "{");
            int col = _outputMaxCol;

            foreach (Test_iTextSharp.TextChunk chunk in textBlock.text)
            {
                //tw.WriteLine("{0}  \"{1}\"", indent, chunk.text);
                if (col + chunk.text.Length + 4 > _outputMaxCol)
                {
                    tw.WriteLine();
                    tw.Write("{0}  ", indent);
                    col = indent.Length + 2;
                }
                else
                {
                    tw.Write(", ");
                    col += 2;
                }
                tw.Write("\"{0}\"", chunk.text);
                col += chunk.text.Length + 2;
            }
            tw.WriteLine();
            foreach (Test_iTextSharp.TextBlock child in textBlock.childs)
            {
                PrintTextBlock(tw, child, depth + 1);
            }
            tw.WriteLine(indent + "}");
        }