Beispiel #1
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfPage     page   = pdfDoc.GetFirstPage();

            PdfAnnotation sticky          = page.GetAnnotations()[0];
            Rectangle     stickyRectangle = sticky.GetRectangle().ToRectangle();
            PdfAnnotation replySticky     = new PdfTextAnnotation(stickyRectangle)
                                            .SetStateModel(new PdfString("Review"))
                                            .SetState(new PdfString("Accepted"))
                                            .SetIconName(new PdfName("Comment"))

                                            // This method sets an annotation to which the current annotation is "in reply".
                                            // Both annotations shall be on the same page of the document.
                                            .SetInReplyTo(sticky)

                                            // This method sets the text label that will be displayed in the title bar of the annotation's pop-up window
                                            // when open and active. This entry shall identify the user who added the annotation.
                                            .SetText(new PdfString("Bruno"))

                                            // This method sets the text that will be displayed for the annotation or the alternate description,
                                            // if this type of annotation does not display text.
                                            .SetContents("Accepted by Bruno")

                                            // This method sets a complete set of enabled and disabled flags at once. If not set specifically
                                            // the default value is 0.
                                            // The argument is an integer interpreted as set of one-bit flags
                                            // specifying various characteristics of the annotation.
                                            .SetFlags(sticky.GetFlags() + PdfAnnotation.HIDDEN);

            pdfDoc.GetFirstPage().AddAnnotation(replySticky);

            pdfDoc.Close();
        }
        public virtual void NoForbidReleaseObjectsModifyingTest()
        {
            String srcFile       = sourceFolder + "noForbidReleaseObjectsModifying.pdf";
            String stampReleased = sourceFolder + "noForbidReleaseObjectsModified.pdf";

            using (PdfDocument doc = new PdfDocument(new PdfReader(srcFile), new PdfWriter(destinationFolder + "noForbidReleaseObjectsModifying.pdf"
                                                                                           ), new StampingProperties().UseAppendMode())) {
                PdfAnnotation annots = doc.GetPage(1).GetAnnotations()[0];
                annots.SetRectangle(new PdfArray(new Rectangle(100, 100, 80, 50)));
                annots.GetRectangle().Release();
            }
            using (PdfDocument openPrev = new PdfDocument(new PdfReader(stampReleased))) {
                NUnit.Framework.Assert.IsTrue(new Rectangle(100, 100, 80, 50).EqualsWithEpsilon(openPrev.GetPage(1).GetAnnotations
                                                                                                    ()[0].GetRectangle().ToRectangle()));
            }
            NUnit.Framework.Assert.IsNotNull(new CompareTool().CompareByContent(srcFile, stampReleased, destinationFolder
                                                                                ));
        }