Beispiel #1
0
        public void TestFileAttachmentAnnotation()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            FileAttachmentAnnotation annot = new FileAttachmentAnnotation(Bitmap1, 10, 10, 20, 20);

            annot.Icon  = FileAttachmentAnnotationIcon.Graph;
            annot.Color = new ColorRGB(0, 0, 0);
            document.Pages[0].Annotations.Add(annot);
            annot       = new FileAttachmentAnnotation(Bitmap1, 10, 50, 20, 20);
            annot.Icon  = FileAttachmentAnnotationIcon.Paperclip;
            annot.Color = new ColorRGB(0, 0, 0);
            document.Pages[0].Annotations.Add(annot);
            annot       = new FileAttachmentAnnotation(Bitmap1, 50, 10, 20, 20);
            annot.Icon  = FileAttachmentAnnotationIcon.PushPin;
            annot.Color = new ColorRGB(0, 0, 0);
            document.Pages[0].Annotations.Add(annot);
            annot       = new FileAttachmentAnnotation(Bitmap1, 50, 50, 20, 20);
            annot.Icon  = FileAttachmentAnnotationIcon.Tag;
            annot.Color = new ColorRGB(0, 0, 0);
            document.Pages[0].Annotations.Add(annot);
            document.Save(OutputFolder + @"\TestFileAttachmentAnnotation.pdf");
            document.Dispose();

            //Process.Start("TestFileAttachmentAnnotation.pdf");
        }
        public void PutFileAttachmentAnnotationExample()
        {
            //ExStart: PutFileAttachmentAnnotationExample
            UploadFile(AttachmentFile, AttachmentFile);
            FileAttachmentAnnotation annotation = new FileAttachmentAnnotation()
            {
                Name  = "Updated Example",
                Rect  = new Rectangle(100, 100, 200, 200),
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex   = 1,
                Title    = "Title Updated",
                Modified = "01/01/2018 00:00:00.000 AM",
                FilePath = Path.Combine(FolderName, AttachmentFile),
                FileName = AttachmentFile
            };

            var    lineResponse = api.GetDocumentFileAttachmentAnnotations(Name, folder: FolderName);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = api.PutFileAttachmentAnnotation(Name, annotationId, annotation, folder: FolderName);

            Console.WriteLine(response);
            //ExEnd: PutFileAttachmentAnnotationExample
        }
        static void Main()
        {
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // Load existing document
            pdfDocument.Load(@".\Invoice.pdf");

            // Attach ZUGFeRD XML file
            FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(@".\ZUGFeRD-invoice.xml", 0, 0, 0, 0);

            pdfDocument.Pages[0].Annotations.Add(fileAttachment);

            // Instruct PDF viewer applications to show attachments pane on startup (optional)
            pdfDocument.PageMode = PageMode.Attachment;

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Beispiel #4
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Attach file
            FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation("sample_attachment.txt", 20, 20, 20, 20);

            fileAttachment.Icon = FileAttachmentAnnotationIcon.Paperclip;
            page.Annotations.Add(fileAttachment);

            // Instruct PDF viewer application to show attachments pane on startup
            pdfDocument.PageMode = PageMode.Attachment;

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
        public void PutFileAttachmentAnnotationTest()
        {
            UploadFile(AttachmentFile, AttachmentFile);
            FileAttachmentAnnotation annotation = new FileAttachmentAnnotation(Rect: new Rectangle(100, 100, 200, 200))
            {
                Name  = "Updated Test",
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex   = 1,
                Title    = "Title Updated",
                Modified = "01/01/2018 00:00:00.000 AM",
                FilePath = Path.Combine(TempFolder, AttachmentFile),
                FileName = AttachmentFile
            };

            var    lineResponse = PdfApi.GetDocumentFileAttachmentAnnotations(Name, folder: TempFolder);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = PdfApi.PutFileAttachmentAnnotation(Name, annotationId, annotation, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
Beispiel #6
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);

            IPDFObject name = Dictionary["Name"];

            if (name != null)
            {
                res.AddItem("Name", name.Clone());
            }

            IPDFObject fs = Dictionary["FS"];

            if (fs != null)
            {
                res.AddItem("FS", fs.Clone());
            }

            FileAttachmentAnnotation annot = new FileAttachmentAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);
            return(annot);
        }
Beispiel #7
0
        public void CreatePDF(Stream stream)
        {
            var doc  = new GcPdfDocument();
            var page = doc.NewPage();
            var g    = page.Graphics;

            var rc = Common.Util.AddNote(
                "Some files from the sample's Resources/Images folder are attached to this page.\n" +
                "Some viewers may not show attachments, so we draw rectangles to indicate their (usually clickable) locations.",
                page);
            var ip      = new PointF(rc.X, rc.Bottom + 9);
            var attSize = new SizeF(36, 12);
            var gap     = 8;

            string[] files = new string[]
            {
                "tudor.jpg",
                "sea.jpg",
                "puffins.jpg",
                "lavender.jpg",
                "skye.jpg",
                "fiord.jpg",
                "out.jpg"
            };
            foreach (string fn in files)
            {
                string file = Path.Combine("Resources", "Images", fn);
                FileAttachmentAnnotation faa = new FileAttachmentAnnotation()
                {
                    Color    = Color.FromArgb(unchecked ((int)0xFFc540a5)),
                    UserName = "******",
                    Rect     = new RectangleF(ip.X, ip.Y, attSize.Width, attSize.Height),
                    Contents = "Attached file: " + file,
                    Icon     = FileAttachmentAnnotationIcon.Paperclip,
                    File     = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file)),
                };
                page.Annotations.Add(faa);
                g.FillRectangle(faa.Rect, Color.FromArgb(unchecked ((int)0xFF40c5a3)));
                g.DrawRectangle(faa.Rect, Color.FromArgb(unchecked ((int)0xFF6040c5)));
                ip.Y += attSize.Height + gap;
            }
            // Done:
            doc.Save(stream);
        }
Beispiel #8
0
        private void parseAnnotations()
        {
            for (int i = 0; i < _array.Count; ++i)
            {
                PDFDictionary annotDict = _array[i] as PDFDictionary;
                if (annotDict != null)
                {
                    if (annotDict["IRT"] == null)
                    {
                        PDFName subtype = annotDict["Subtype"] as PDFName;
                        if (subtype != null)
                        {
                            Annotation annot = null;
                            switch (subtype.GetValue())
                            {
                            case "Text":
                                annot = new TextAnnotation(annotDict, _owner);
                                break;

                            case "Link":
                                annot = new LinkAnnotation(annotDict, _owner);
                                break;

                            case "FreeText":
                                annot = new FreeTextAnnotation(annotDict, _owner);
                                break;

                            case "Line":
                                annot = new LineAnnotation(annotDict, _owner);
                                break;

                            case "Square":
                                annot = new SquareAnnotation(annotDict, _owner);
                                break;

                            case "Circle":
                                annot = new CircleAnnotation(annotDict, _owner);
                                break;

                            case "Polygon":
                                annot = new PolygonAnnotation(annotDict, _owner);
                                break;

                            case "PolyLine":
                                annot = new PolylineAnnotation(annotDict, _owner);
                                break;

                            case "Highlight":
                                annot = new HighlightAnnotation(annotDict, _owner);
                                break;

                            case "Underline":
                                annot = new UnderlineAnnotation(annotDict, _owner);
                                break;

                            case "Squiggly":
                                annot = new SquigglyAnnotation(annotDict, _owner);
                                break;

                            case "StrikeOut":
                                annot = new StrikeOutAnnotation(annotDict, _owner);
                                break;

                            case "Stamp":
                                annot = new RubberStampAnnotation(annotDict, _owner);
                                break;

                            case "Caret":
                                annot = new CaretAnnotation(annotDict, _owner);
                                break;

                            case "Ink":
                                annot = new InkAnnotation(annotDict, _owner);
                                break;

                            case "FileAttachment":
                                annot = new FileAttachmentAnnotation(annotDict, _owner);
                                break;

                            case "Sound":
                                annot = new SoundAnnotation(annotDict, _owner);
                                break;

                            case "Movie":
                                annot = new MovieAnnotation(annotDict, _owner);
                                break;

                            case "Screen":
                                annot = new ScreenAnnotation(annotDict, _owner);
                                break;

                            case "3D":
                                annot = new ThreeDAnnotation(annotDict, _owner);
                                break;

                            case "Widget":
                                PDFName ft = annotDict["FT"] as PDFName;
                                if (ft == null)
                                {
                                    PDFDictionary parent = annotDict["Parent"] as PDFDictionary;
                                    if (parent != null)
                                    {
                                        ft = parent["FT"] as PDFName;
                                    }
                                }

                                if (ft != null)
                                {
                                    switch (ft.GetValue())
                                    {
                                    case "Tx":
                                        annot = new EditBox(annotDict, _owner);
                                        break;

                                    case "Ch":
                                        uint flag = getFlag(annotDict);
                                        if ((flag >> 17) % 2 != 0)
                                        {
                                            annot = new ComboBox(annotDict, _owner);
                                        }
                                        else
                                        {
                                            annot = new ListBox(annotDict, _owner);
                                        }
                                        break;

                                    case "Btn":
                                        flag = getFlag(annotDict);
                                        if ((flag >> 16) % 2 != 0)
                                        {
                                            annot = new PushButton(annotDict, _owner);
                                        }
                                        else if ((flag >> 15) % 2 != 0)
                                        {
                                            annot = new RadioButton(annotDict, _owner);
                                        }
                                        else
                                        {
                                            annot = new CheckBox(annotDict, _owner);
                                        }
                                        break;
                                    }
                                }
                                break;
                            }

                            if (annot != null)
                            {
                                annot.SetPage(_page, false);
                                _annotations.Add(annot);
                            }
                        }
                    }
                }
            }
        }