Ejemplo n.º 1
0
        private static void CreateRubberStampAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] rubberStampAnnotationNames = new string[]
            {
                "Approved", "AsIs", "Confidential", "Departmental", "Draft", "Experimental", "Expired", "Final",
                "ForComment", "ForPublicRelease", "NotApproved", "NotForPublicRelease", "Sold", "TopSecret"
            };

            page.Graphics.DrawString("Rubber stamp annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < rubberStampAnnotationNames.Length; i++)
            {
                PdfRubberStampAnnotation rsa = new PdfRubberStampAnnotation();
                rsa.Author    = "Xfinium.Pdf";
                rsa.Contents  = "I am a " + rubberStampAnnotationNames[i] + " rubber stamp annotation.";
                rsa.StampName = rubberStampAnnotationNames[i];
                page.Annotations.Add(rsa);
                rsa.VisualRectangle = new PdfVisualRectangle(50, 70 + 50 * i, 200, 40);
                page.Graphics.DrawString(rubberStampAnnotationNames[i], font, blackBrush, 270, 85 + 50 * i);
            }

            page.Graphics.DrawString("Stamp annotations with custom appearance", font, blackBrush, 350, 50);
            PdfRubberStampAnnotation customRubberStampAnnotation = new PdfRubberStampAnnotation();

            customRubberStampAnnotation.Contents  = "Rubber stamp annotation with custom appearance.";
            customRubberStampAnnotation.StampName = "Custom";
            page.Annotations.Add(customRubberStampAnnotation);
            customRubberStampAnnotation.VisualRectangle = new PdfVisualRectangle(350, 70, 200, 40);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen  = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);

            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customRubberStampAnnotation.NormalAppearance = customAppearance;
        }
Ejemplo n.º 2
0
        private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] textAnnotationNames = new string[]
            {
                "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph",
                "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow"
            };

            page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author   = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            Random rnd = new Random();

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author   = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                rnd.NextBytes(rgb);
                ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700);
            PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation();

            customTextAnnotation.Author   = "Xfinium.Pdf";
            customTextAnnotation.Contents = "Text annotation with custom icon.";
            page.Annotations.Add(customTextAnnotation);
            customTextAnnotation.IconName = "Custom icon appearance";
            customTextAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen  = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);

            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customTextAnnotation.NormalAppearance = customAppearance;
        }
Ejemplo n.º 3
0
        private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            page.Rotation = 90;

            page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            Pdf3DView view0 = new Pdf3DView();

            view0.CameraToWorldMatrix    = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit          = 0.123106;
            view0.ExternalName           = "Default";
            view0.InternalName           = "Default";
            view0.Projection             = new Pdf3DProjection();
            view0.Projection.FieldOfView = 30;

            Pdf3DView view1 = new Pdf3DView();

            view1.CameraToWorldMatrix    = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit          = 0.123106;
            view1.ExternalName           = "Top";
            view1.InternalName           = "Top";
            view1.Projection             = new Pdf3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            Pdf3DView view2 = new Pdf3DView();

            view2.CameraToWorldMatrix    = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit          = 0.123106;
            view2.ExternalName           = "Side";
            view2.InternalName           = "Side";
            view2.Projection             = new Pdf3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            Pdf3DView view3 = new Pdf3DView();

            view3.CameraToWorldMatrix    = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit          = 0.123106;
            view3.ExternalName           = "Isometric";
            view3.InternalName           = "Isometric";
            view3.Projection             = new Pdf3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            Pdf3DView view4 = new Pdf3DView();

            view4.CameraToWorldMatrix    = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit          = 0.123106;
            view4.ExternalName           = "Front";
            view4.InternalName           = "Front";
            view4.Projection             = new Pdf3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            Pdf3DView view5 = new Pdf3DView();

            view5.CameraToWorldMatrix    = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit          = 0.123106;
            view5.ExternalName           = "Back";
            view5.InternalName           = "Back";
            view5.Projection             = new Pdf3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            Pdf3DStream _3dStream = new Pdf3DStream();

            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content          = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            Pdf3DAnnotation _3da = new Pdf3DAnnotation();

            _3da.Stream = _3dStream;

            PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200);

            appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Font  = font;
            sao.Brush = blackBrush;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);

            page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Graphics.DrawString("Top", sao, slo);

            PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction();

            gotoTopView.ViewIndex        = 1;
            gotoTopView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18);
            linkGotoTopView.Action          = gotoTopView;

            page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Graphics.DrawString("Side", sao, slo);

            PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction();

            gotoSideView.ViewIndex        = 2;
            gotoSideView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18);
            linkGotoSideView.Action          = gotoSideView;

            page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Graphics.DrawString("Isometric", sao, slo);

            PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction();

            gotoIsometricView.ViewIndex        = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action          = gotoIsometricView;

            page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Graphics.DrawString("Front", sao, slo);

            PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction();

            gotoFrontView.ViewIndex        = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action          = gotoFrontView;

            page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Graphics.DrawString("Back", sao, slo);

            PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction();

            gotoBackView.ViewIndex        = 5;
            gotoBackView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18);
            linkGotoBackView.Action          = gotoBackView;
        }
Ejemplo n.º 4
0
        private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();
            Random   rnd        = new Random();

            // Random binary data to be used a file content for file attachment annotations.
            byte[] fileData = new byte[256];

            PdfPage page = document.Pages.Add();

            string[] fileAttachmentAnnotationNames = new string[]
            {
                "Graph", "Paperclip", "PushPin", "Tag"
            };

            page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author   = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload  = fileData;
                faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat";
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author   = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload  = fileData;
                faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat";
                rnd.NextBytes(rgb);
                faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700);
            PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation();

            customFileAttachmentAnnotation.Author   = "Xfinium.Pdf";
            customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon.";
            page.Annotations.Add(customFileAttachmentAnnotation);
            customFileAttachmentAnnotation.IconName = "Custom icon appearance";
            customFileAttachmentAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen  = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);

            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customFileAttachmentAnnotation.NormalAppearance = customAppearance;
        }
Ejemplo n.º 5
0
        private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();
            page.Rotation = 90;

            page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            Pdf3DView view0 = new Pdf3DView();
            view0.CameraToWorldMatrix = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit = 0.123106;
            view0.ExternalName = "Default";
            view0.InternalName = "Default";
            view0.Projection = new Pdf3DProjection();
            view0.Projection.FieldOfView = 30;

            Pdf3DView view1 = new Pdf3DView();
            view1.CameraToWorldMatrix = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit = 0.123106;
            view1.ExternalName = "Top";
            view1.InternalName = "Top";
            view1.Projection = new Pdf3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            Pdf3DView view2 = new Pdf3DView();
            view2.CameraToWorldMatrix = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit = 0.123106;
            view2.ExternalName = "Side";
            view2.InternalName = "Side";
            view2.Projection = new Pdf3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            Pdf3DView view3 = new Pdf3DView();
            view3.CameraToWorldMatrix = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit = 0.123106;
            view3.ExternalName = "Isometric";
            view3.InternalName = "Isometric";
            view3.Projection = new Pdf3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            Pdf3DView view4 = new Pdf3DView();
            view4.CameraToWorldMatrix = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit = 0.123106;
            view4.ExternalName = "Front";
            view4.InternalName = "Front";
            view4.Projection = new Pdf3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            Pdf3DView view5 = new Pdf3DView();
            view5.CameraToWorldMatrix = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit = 0.123106;
            view5.ExternalName = "Back";
            view5.InternalName = "Back";
            view5.Projection = new Pdf3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            Pdf3DStream _3dStream = new Pdf3DStream();
            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            Pdf3DAnnotation _3da = new Pdf3DAnnotation();
            _3da.Stream = _3dStream;

            PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200);
            appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Font = font;
            sao.Brush = blackBrush;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);

            page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Graphics.DrawString("Top", sao, slo);

            PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction();
            gotoTopView.ViewIndex = 1;
            gotoTopView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18);
            linkGotoTopView.Action = gotoTopView;

            page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Graphics.DrawString("Side", sao, slo);

            PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction();
            gotoSideView.ViewIndex = 2;
            gotoSideView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18);
            linkGotoSideView.Action = gotoSideView;

            page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Graphics.DrawString("Isometric", sao, slo);

            PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction();
            gotoIsometricView.ViewIndex = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action = gotoIsometricView;

            page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Graphics.DrawString("Front", sao, slo);

            PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction();
            gotoFrontView.ViewIndex = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action = gotoFrontView;

            page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Graphics.DrawString("Back", sao, slo);

            PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction();
            gotoBackView.ViewIndex = 5;
            gotoBackView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18);
            linkGotoBackView.Action = gotoBackView;
        }
Ejemplo n.º 6
0
        private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] textAnnotationNames = new string[]
                {
                    "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph",
                    "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow"
                };

            page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            Random rnd = new Random();
            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                rnd.NextBytes(rgb);
                ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700);
            PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation();
            customTextAnnotation.Author = "Xfinium.Pdf";
            customTextAnnotation.Contents = "Text annotation with custom icon.";
            page.Annotations.Add(customTextAnnotation);
            customTextAnnotation.IconName = "Custom icon appearance";
            customTextAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customTextAnnotation.NormalAppearance = customAppearance;
        }
Ejemplo n.º 7
0
        private static void CreateRubberStampAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] rubberStampAnnotationNames = new string[]
                {
                    "Approved", "AsIs", "Confidential", "Departmental", "Draft", "Experimental", "Expired", "Final",
                    "ForComment", "ForPublicRelease", "NotApproved", "NotForPublicRelease", "Sold", "TopSecret"
                };

            page.Graphics.DrawString("Rubber stamp annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < rubberStampAnnotationNames.Length; i++)
            {
                PdfRubberStampAnnotation rsa = new PdfRubberStampAnnotation();
                rsa.Author = "Xfinium.Pdf";
                rsa.Contents = "I am a " + rubberStampAnnotationNames[i] + " rubber stamp annotation.";
                rsa.StampName = rubberStampAnnotationNames[i];
                page.Annotations.Add(rsa);
                rsa.VisualRectangle = new PdfVisualRectangle(50, 70 + 50 * i, 200, 40);
                page.Graphics.DrawString(rubberStampAnnotationNames[i], font, blackBrush, 270, 85 + 50 * i);
            }

            page.Graphics.DrawString("Stamp annotations with custom appearance", font, blackBrush, 350, 50);
            PdfRubberStampAnnotation customRubberStampAnnotation = new PdfRubberStampAnnotation();
            customRubberStampAnnotation.Contents = "Rubber stamp annotation with custom appearance.";
            customRubberStampAnnotation.StampName = "Custom";
            page.Annotations.Add(customRubberStampAnnotation);
            customRubberStampAnnotation.VisualRectangle = new PdfVisualRectangle(350, 70, 200, 40);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customRubberStampAnnotation.NormalAppearance = customAppearance;
        }
Ejemplo n.º 8
0
        private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();
            Random rnd = new Random();
            // Random binary data to be used a file content for file attachment annotations.
            byte[] fileData = new byte[256];

            PdfPage page = document.Pages.Add();

            string[] fileAttachmentAnnotationNames = new string[]
                {
                    "Graph", "Paperclip", "PushPin", "Tag"
                };

            page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload = fileData;
                faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat";
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload = fileData;
                faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat";
                rnd.NextBytes(rgb);
                faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700);
            PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation();
            customFileAttachmentAnnotation.Author = "Xfinium.Pdf";
            customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon.";
            page.Annotations.Add(customFileAttachmentAnnotation);
            customFileAttachmentAnnotation.IconName = "Custom icon appearance";
            customFileAttachmentAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customFileAttachmentAnnotation.NormalAppearance = customAppearance;
        }