コード例 #1
0
        // ********************************************************************
        // Fct:     ParseDoc
        //
        // Descr:   -
        //
        // Owner:   erst
        // ********************************************************************
        public static void ParseDoc(String src, String dest)
        {
            try
            {
                PdfDocument ScrPdf = new PdfDocument(new PdfReader(src));
                // PdfDocument DestPdf = new PdfDocument(new PdfWriter(dest));

                PdfPage page = ScrPdf.GetFirstPage();

                // Collects all comment annotations in the document
                Collection <PdfAnnotation> annotations = new Collection <PdfAnnotation>(page.GetAnnotations());

                foreach (PdfAnnotation annot in annotations)
                {
                    if (annot.GetType().Equals((typeof(iText.Kernel.Pdf.Annot.PdfTextAnnotation))))
                    {
                        PdfDictionary annotDictionary = annot.GetPdfObject();

                        //Rect is the annotation rectangle defining the location of the annotation on the page
                        PdfArray Arr = annotDictionary.GetAsArray(PdfName.Rect);

                        int x = Arr.GetAsNumber(0).IntValue();
                        int y = Arr.GetAsNumber(1).IntValue();

                        Rectangle rect = annotDictionary.GetAsRectangle(PdfName.Rect);
                        float     recX = rect.GetX();
                        float     recY = rect.GetY();

                        //Read the content
                        String content = annotDictionary.Get(PdfName.Contents).ToString();
                        string output  = content;
                    }
                }

                //  DestPdf.Close();
                ScrPdf.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }
コード例 #2
0
        // ********************************************************************
        // Fct:     GetNextPdfComment
        //
        // Descr:   -
        //
        // Owner:   erst
        // ********************************************************************
        private static bool GetNextPdfComment(PdfPage page, ref float x, ref float y, ref string content, ref int annotNo)
        {
            // Collects all comment annotations in the document
            Collection <PdfAnnotation> annotations = new Collection <PdfAnnotation>(page.GetAnnotations());

            while (annotNo <= annotations.Count)
            {
                PdfAnnotation annot = annotations[annotNo - 1];   // Array starts with index 0, annotNo starts with 1
                if (annot.GetType().Equals((typeof(iText.Kernel.Pdf.Annot.PdfTextAnnotation))))
                {
                    PdfDictionary annotDictionary = annot.GetPdfObject();

                    //Rect is the annotation rectangle defining the location of the annotation on the page
                    PdfArray Arr = annotDictionary.GetAsArray(PdfName.Rect);

                    //int x = Arr.GetAsNumber(0).IntValue();
                    //int y = Arr.GetAsNumber(1).IntValue();

                    Rectangle rect = annotDictionary.GetAsRectangle(PdfName.Rect);
                    x = rect.GetX();
                    y = rect.GetY();

                    //Read the content
                    content = annotDictionary.Get(PdfName.Contents).ToString();

                    annotNo++;
                    return(true);
                }
                else
                {
                    annotNo++;
                }
            }

            return(false);
        }