コード例 #1
0
        private static void CreateUriActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

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

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Canvas.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Canvas.DrawString("Go to o2sol.com", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PDFUriAction uriAction = new PDFUriAction();
                uriAction.URI = "http://www.o2sol.com";
                link.Action   = uriAction;
            }
        }
コード例 #2
0
        private static void CreateLaunchActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

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

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Canvas.DrawString("Launch actions:", font, blackBrush, 400, 360);

                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 380, 200, 20);
                slo.X = 500;
                slo.Y = 390;
                document.Pages[i].Canvas.DrawString("Launch samples explorer", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 380, 200, 20);

                // Create a launch action and attach it to the link.
                PDFLaunchAction launchAction = new PDFLaunchAction();
                launchAction.FileName = "O2S.Components.PDF4NET.SamplesExplorer.Win.exe";
                link.Action           = launchAction;
            }
        }
コード例 #3
0
        /// <summary>
        /// Extracts text fragments from the 3rd page and highlights the glyphs in the fragment.
        /// </summary>
        /// <param name="document"></param>
        private static void ExtractImagesAndHighlight(PDFFixedDocument document)
        {
            PDFPen                     pen       = new PDFPen(new PDFRgbColor(255, 0, 192), 0.5);
            PDFBrush                   brush     = new PDFBrush(new PDFRgbColor(0, 0, 0));
            PDFStandardFont            helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 8);
            PDFStringAppearanceOptions sao       = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = helvetica;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.Width = 1000;

            PDFContentExtractor      ce  = new PDFContentExtractor(document.Pages[2]);
            PDFVisualImageCollection eic = ce.ExtractImages(false);

            for (int i = 0; i < eic.Count; i++)
            {
                string imageProperties = string.Format("Image ID: {0}\nPixel width: {1} pixels\nPixel height: {2} pixels\n" +
                                                       "Display width: {3} points\nDisplay height: {4} points\nHorizonal Resolution: {5} dpi\nVertical Resolution: {6} dpi",
                                                       eic[i].ImageID, eic[i].Width, eic[i].Height, eic[i].DisplayWidth, eic[i].DisplayHeight, eic[i].DpiX, eic[i].DpiY);

                PDFPath boundingPath = new PDFPath();
                boundingPath.StartSubpath(eic[i].ImageCorners[0].X, eic[i].ImageCorners[0].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[1].X, eic[i].ImageCorners[1].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[2].X, eic[i].ImageCorners[2].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[3].X, eic[i].ImageCorners[3].Y);
                boundingPath.CloseSubpath();

                document.Pages[2].Canvas.DrawPath(pen, boundingPath);
                slo.X = eic[i].ImageCorners[3].X + 1;
                slo.Y = eic[i].ImageCorners[3].Y + 1;
                document.Pages[2].Canvas.DrawString(imageProperties, sao, slo);
            }
        }
コード例 #4
0
ファイル: Watermarks.cs プロジェクト: o2solutions/pdf4net
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkWithTransparency(PDFPage page)
        {
            PDFBrush        redBrush  = new PDFBrush(new PDFRgbColor(192, 0, 0));
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 36);

            // The page graphics is located by default on top of existing page content.
            //page.SetGraphicsPosition(PDFPageGraphicsPosition.OverExistingPageContent);

            page.Canvas.SaveGraphicsState();

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = redBrush;
            sao.Font  = helvetica;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X        = 130;
            slo.Y        = 670;
            slo.Rotation = 60;

            // Draw the watermark over page content but setting the transparency to a value lower than 1.
            // The page content will be partially visible through the watermark.
            PDFExtendedGraphicState gs1 = new PDFExtendedGraphicState();

            gs1.FillAlpha = 0.3;
            page.Canvas.SetExtendedGraphicState(gs1);
            page.Canvas.DrawString("Sample watermark over page content", sao, slo);

            page.Canvas.RestoreGraphicsState();
        }
コード例 #5
0
        private static void CreateJavaScriptActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

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

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Canvas.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Canvas.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PDFJavaScriptAction jsAction = new PDFJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"O2S.Components.PDF4NET Actions Sample\"});";
                link.Action     = jsAction;
            }
        }
コード例 #6
0
ファイル: Annotations.cs プロジェクト: sss-software/pdf4net
        private static void CreateTextMarkupAnnotations(PDFFixedDocument document, PDFFont font)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("Text markup annotations", font, blackBrush, 50, 50);

            PDFTextMarkupAnnotationType[] tmat = new PDFTextMarkupAnnotationType[]
            {
                PDFTextMarkupAnnotationType.Highlight, PDFTextMarkupAnnotationType.Squiggly, PDFTextMarkupAnnotationType.StrikeOut, PDFTextMarkupAnnotationType.Underline
            };

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            for (int i = 0; i < tmat.Length; i++)
            {
                PDFTextMarkupAnnotation tma = new PDFTextMarkupAnnotation();
                page.Annotations.Add(tma);
                tma.DisplayRectangle = new PDFDisplayRectangle(50, 100 + 50 * i, 200, font.Size + 2);
                tma.TextMarkupType   = tmat[i];

                slo.X = 150;
                slo.Y = 100 + 50 * i + font.Size;

                page.Canvas.DrawString(tmat[i].ToString() + " annotation.", sao, slo);
            }
        }
コード例 #7
0
ファイル: Barcodes.cs プロジェクト: sss-software/pdf4net
        private static void DrawPharmaBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont)
        {
            PDFBrush brush        = new PDFBrush();
            PDFPen   lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5);

            page.Canvas.DrawString("Pharma barcodes (barcodes used in the pharmaceutical industry)", titleFont, brush, 40, 20);
            for (int i = 0; i < 2; i++)
            {
                page.Canvas.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i);
            }
            page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 250);

            string[] barcodes = new string[] { "Code 32", "Pharmacode", "PZN (Pharma-Zentral-Nummer)" };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = barcodeFont;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;

            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 100 * (i / 2);

                page.Canvas.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign  = -sign;
            }

            // Code 32
            PDFCode32Barcode code32Barcode = new PDFCode32Barcode();

            code32Barcode.Data = "54925174";
            code32Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code32Barcode, 173 - code32Barcode.Width / 2, 70);

            // Pharmacode
            PDFPharmacodeBarcode pharmacodeBarcode = new PDFPharmacodeBarcode();

            pharmacodeBarcode.Data = "128128";
            pharmacodeBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(pharmacodeBarcode, 173 + 266 - pharmacodeBarcode.Width / 2, 70);

            // PZN
            PDFPznBarcode pznBarcode = new PDFPznBarcode();

            pznBarcode.Data = "903271";
            pznBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(pznBarcode, 173 - pznBarcode.Width / 2, 170);

            page.Canvas.CompressAndClose();
        }
コード例 #8
0
        private static PDFFixedDocument CreatePDFA1bDocument(Stream iccInput, Stream ttfInput)
        {
            iccInput.Position = 0;
            ttfInput.Position = 0;

            PDFFixedDocument document = new PDFFixedDocument();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PDFIccColorSpace icc = new PDFIccColorSpace();

            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PDFOutputIntent oi = new PDFOutputIntent();

            oi.Type = PDFOutputIntentType.PDFA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile  = icc;
            document.OutputIntents       = new PDFOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation          = new PDFDocumentInformation();
            document.DocumentInformation.Author   = "O2 Solutions";
            document.DocumentInformation.Title    = "PDF4NET PDF/A-1B Demo";
            document.DocumentInformation.Creator  = "PDF4NET PDF/A-1B Demo Application";
            document.DocumentInformation.Producer = "PDF4NET";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject  = "PDF/A-1B Sample produced by PDF4NET";
            document.XmpMetadata = new PDFXmpMetadata();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 128));

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Canvas.DrawString("PDF4NET", sao, slo);
            slo.Y             = page.Height / 2 + 10;
            slo.VerticalAlign = PDFStringVerticalAlign.Top;
            sao.Font.Size     = 16;
            page.Canvas.DrawString("This is a sample PDF/A-1B document that shows the PDF/A-1B capabilities in PDF4NET library", sao, slo);

            return(document);
        }
コード例 #9
0
        private static void CreateRemoteGoToActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

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

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            Random rnd = new Random();

            for (int i = 0; i < document.Pages.Count; i++)
            {
                int destinationPage = rnd.Next(document.Pages.Count);

                document.Pages[i].Canvas.DrawString("Go To Remote actions:", font, blackBrush, 400, 300);

                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 320, 200, 20);
                slo.X = 500;
                slo.Y = 330;
                document.Pages[i].Canvas.DrawString("Go To page " + (destinationPage + 1).ToString() + " in sample.pdf", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 320, 200, 20);

                // Create a GoToR action and attach it to the link.
                PDFPageNumberDestination pageDestination = new PDFPageNumberDestination();
                pageDestination.PageNumber = destinationPage;
                pageDestination.Left       = 0;
                pageDestination.Top        = 792;
                pageDestination.Zoom       = 0; // Keep current zoom
                PDFRemoteGoToAction remoteGoToAction = new PDFRemoteGoToAction();
                remoteGoToAction.FileName    = "sample.pdf";
                remoteGoToAction.Destination = pageDestination;
                link.Action = remoteGoToAction;
            }
        }
コード例 #10
0
ファイル: Watermarks.cs プロジェクト: o2solutions/pdf4net
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkUnderPageContent(PDFPage page)
        {
            PDFBrush        redBrush  = new PDFBrush(new PDFRgbColor(192, 0, 0));
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 36);

            // Set the page canvas to be located under existing page content.
            page.SetCanvasPosition(PDFPageCanvasPosition.UnderExistingPageContent);

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = redBrush;
            sao.Font  = helvetica;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X        = 130;
            slo.Y        = 670;
            slo.Rotation = 60;
            page.Canvas.DrawString("Sample watermark under page content", sao, slo);
        }
コード例 #11
0
ファイル: Annotations.cs プロジェクト: sss-software/pdf4net
        private static void CreateRedactionAnnotations(PDFFixedDocument document, PDFFont font, Stream flashStream)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Canvas.DrawString("Redaction annotations", font, blackBrush, 50, 50);

            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10);

            page.Canvas.DrawString(
                "Open the file with Adobe Acrobat, right click on the annotation and select \"Apply redactions\" The text under the annotation will be redacted.",
                helvetica, blackBrush, 50, 110);

            PDFFormXObject redactionAppearance = new PDFFormXObject(250, 150);

            redactionAppearance.Canvas.DrawRectangle(new PDFBrush(PDFRgbColor.LightGreen),
                                                     0, 0, redactionAppearance.Width, redactionAppearance.Height);
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = new PDFBrush(PDFRgbColor.DarkRed);
            sao.Font  = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 32);
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.Width           = redactionAppearance.Width;
            slo.Height          = redactionAppearance.Height;
            slo.X               = 0;
            slo.Y               = 0;
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            redactionAppearance.Canvas.DrawString("This content has been redacted", sao, slo);

            PDFRedactionAnnotation redactionAnnotation = new PDFRedactionAnnotation();

            page.Annotations.Add(redactionAnnotation);
            redactionAnnotation.Author            = "PDF4NET";
            redactionAnnotation.BorderColor       = new PDFRgbColor(192, 0, 0);
            redactionAnnotation.BorderWidth       = 1;
            redactionAnnotation.OverlayAppearance = redactionAppearance;
            redactionAnnotation.DisplayRectangle  = new PDFDisplayRectangle(50, 100, 250, 150);
        }
コード例 #12
0
ファイル: PDFUA.cs プロジェクト: o2solutions/pdf4net
        private static void SimpleText(PDFFixedDocument document, PDFStructureElement seParent, PDFAnsiTrueTypeFont font, Stream imageStream)
        {
            PDFAnsiTrueTypeFont headingFont = new PDFAnsiTrueTypeFont(font, 16);
            PDFAnsiTrueTypeFont textFont    = new PDFAnsiTrueTypeFont(font, 10);
            PDFBrush            blackBrush  = new PDFBrush(PDFRgbColor.Black);
            PDFPen  blackPen = new PDFPen(PDFRgbColor.Black, 1);
            PDFPage page     = document.Pages.Add();

            PDFStructureElement seSection = new PDFStructureElement(PDFStandardStructureTypes.Section);

            seSection.Title = "Simple text";
            seParent.AppendChild(seSection);

            PDFStructureElement seHeading = new PDFStructureElement(PDFStandardStructureTypes.Heading);

            seSection.AppendChild(seHeading);

            page.Graphics.BeginStructureElement(seHeading);
            page.Graphics.DrawString("Page heading", headingFont, blackBrush, 30, 50);
            page.Graphics.EndStructureElement();

            PDFStructureElement seParagraph1 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph);

            seSection.AppendChild(seParagraph1);

            page.Graphics.BeginStructureElement(seParagraph1);
            page.Graphics.DrawString("Sample paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in sodales ligula at lobortis.", textFont, blackBrush, 30, 70);
            page.Graphics.EndStructureElement();

            PDFStructureElement seFigure = new PDFStructureElement(PDFStandardStructureTypes.Figure);

            seFigure.ActualText           = "PDF4NET";
            seFigure.AlternateDescription = "PDF4NET Logo";
            seSection.AppendChild(seFigure);

            page.Graphics.BeginStructureElement(seFigure);
            PDFPngImage logoImage = new PDFPngImage(imageStream);

            page.Graphics.DrawImage(logoImage, 30, 90, 256, 128);
            page.Graphics.EndStructureElement();

            // A structure element with 2 content items and an artifact between them.
            PDFStructureElement seParagraph2 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph);

            seSection.AppendChild(seParagraph2);

            page.Graphics.BeginStructureElement(seParagraph2);
            page.Graphics.DrawString("First line of text.", textFont, blackBrush, 30, 230);
            page.Graphics.EndStructureElement();

            page.Graphics.BeginArtifactMarkedContent();
            page.Graphics.DrawLine(blackPen, 30, 242, 100, 242);
            page.Graphics.EndMarkedContent();

            page.Graphics.BeginStructureElement(seParagraph2);
            page.Graphics.DrawString("Second line of text.", textFont, blackBrush, 30, 245);
            page.Graphics.EndStructureElement();

            PDFStructureElement seParagraph3 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph);

            seSection.AppendChild(seParagraph3);

            string text = "Paragraph with underlined text. The structure element is passed as parameter to DrawString method in order to properly tag graphic artifacts such as underlines. " +
                          "Morbi pulvinar eros sit amet diam lacinia, ut feugiat ligula bibendum. Suspendisse ultrices cursus condimentum. " +
                          "Pellentesque semper iaculis luctus. Sed ac maximus urna. Aliquam erat volutpat. Vivamus vel sollicitudin dui. Aenean efficitur " +
                          "fringilla dui, at varius lacus luctus ac. Quisque tellus dui, lacinia non lectus nec, semper faucibus erat.";
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush          = blackBrush;
            sao.Font           = textFont;
            sao.Font.Underline = true;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X     = 30;
            slo.Y     = 260;
            slo.Width = 550;
            page.Graphics.DrawString(text, sao, slo, seParagraph3);

            // A custom structure element that will be mapped to standard Pargraph structure.
            PDFStructureElement seSpecialParagraph = new PDFStructureElement("SpecialParagraph");

            // The structure element specifies an ID that needs to be added to document's IDMap.
            seSpecialParagraph.ID = "specialpara";
            seSection.AppendChild(seSpecialParagraph);

            page.Graphics.BeginStructureElement(seSpecialParagraph);
            textFont.Underline = false;
            textFont.Size      = 18;
            page.Graphics.DrawString("A special paragraph with custom structure element type.", textFont, blackBrush, 30, 350);
            page.Graphics.EndStructureElement();

            // Map the custom structure type to a known structure type.
            document.StructureTree.RoleMap = new PDFRoleMap();
            document.StructureTree.RoleMap["SpecialParagraph"] = PDFStandardStructureTypes.Paragraph;

            // Include the ID of the structure element in the document's identifiers map.
            document.StructureTree.IdentifierMap = new PDFIdMap();
            document.StructureTree.IdentifierMap["specialpara"] = seSpecialParagraph;
        }
コード例 #13
0
ファイル: 3D.cs プロジェクト: sss-software/pdf4net
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            // Create a blank page
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            // Create the annotation that will display the 3D artwork.
            PDF3DAnnotation annot3d = new PDF3DAnnotation();

            // Add the annotation to the page.
            page.Annotations.Add(annot3d);

            //PDF4NET v5: annot3d.Rectangle = new RectangleF(50, 50, 400, 400);
            annot3d.DisplayRectangle = new PDFDisplayRectangle(50, 50, 400, 400);

            annot3d.Stream = Create3DStream();

            //PDF4NET v5: annot3d.Appearance = new PDFAnnotationAppearance();
            annot3d.NormalAppearance = new PDFAnnotationAppearance(annot3d.DisplayRectangle.Width, annot3d.DisplayRectangle.Height);

            //PDF4NET v5: annot3d.Appearance.Canvas.DrawText("Click to activate", new PDFFont(),
            //                null, new PDFBrush(new PDFRgbColor()), 200, 200, 0, PDFTextAlign.MiddleCenter);
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X = 200;
            slo.Y = 200;
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10);
            sao.Brush = new PDFBrush(PDFRgbColor.Black);
            annot3d.NormalAppearance.Canvas.DrawString("Click to activate", sao, slo);

            // Create the default view.
            //PDF4NET v5: PDF3DProjection projection1 = new PDF3DProjection(PDF3DProjectionType.Perspective);
            PDF3DProjection projection1 = new PDF3DProjection()
            {
                Type = PDF3DProjectionType.Perspective
            };

            projection1.FieldOfView = 30;
            PDF3DLightingScheme lightScheme1 = null;
            //PDF4NET v5: PDF3DRenderMode renderMode1 = new PDF3DRenderMode(PDF3DRenderStyle.Solid);
            PDF3DRenderMode renderMode1 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.Solid
            };

            //PDF4NET v5: PDF3DBackground background1 = new PDF3DBackground(new PDFRgbColor(255, 255, 255));
            PDF3DBackground background1 = new PDF3DBackground()
            {
                Color = PDFRgbColor.White
            };

            PDF3DView defaultView = CreateView("Default view",
                                               new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                               131.695f, background1, projection1, renderMode1, lightScheme1);

            // Create a wireframe view.
            //PDF4NET v5: PDF3DRenderMode renderMode2 = new PDF3DRenderMode(PDF3DRenderStyle.Wireframe);
            PDF3DRenderMode renderMode2 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.Wireframe
            };

            PDF3DView wireframeView = CreateView("Wireframe view",
                                                 new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                                 131.695f, background1, projection1, renderMode2, lightScheme1);

            // Create a transparent wireframe view.
            //PDF4NET v5: PDF3DRenderMode renderMode3 = new PDF3DRenderMode(PDF3DRenderStyle.TransparentWireframe);
            PDF3DRenderMode renderMode3 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.TransparentWireframe
            };

            renderMode3.AuxiliaryColor = new PDFRgbColor(0, 192, 0);
            PDF3DView transparentWireframeView = CreateView("Transparent wireframe view",
                                                            new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                                            131.695f, background1, projection1, renderMode3, lightScheme1);

            annot3d.Stream.Views.Add(defaultView);
            annot3d.Stream.Views.Add(wireframeView);
            annot3d.Stream.Views.Add(transparentWireframeView);
            //PDF4NET v5: annot3d.Stream.DefaultView = 0;
            annot3d.Stream.DefaultView = defaultView;

            doc.Save("Sample_3D.pdf");
        }
コード例 #14
0
ファイル: Encryption.cs プロジェクト: sss-software/pdf4net
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument();
            PDFFixedDocument pdfDoc = new PDFFixedDocument();

            // set the security options
            //PDF4NET v5: pdfDoc.SecurityManager = new PDFSecurityManager();
            PDFAesSecurityHandler aesSecurityHandler = new PDFAesSecurityHandler();

            // use 128 bit encryption
            //PDF4NET v5: pdfDoc.SecurityManager.KeySize = EncryptionKeySize.Use128BitKey;
            aesSecurityHandler.KeySize = 256;
            // set user password to "userpass"
            //PDF4NET v5: pdfDoc.SecurityManager.UserPassword = Encoding.ASCII.GetBytes("userpass");
            aesSecurityHandler.UserPassword = "******";
            // set owner password to "ownerpass"
            //PDF4NET v5: pdfDoc.SecurityManager.OwnerPassword = Encoding.ASCII.GetBytes("ownerpass");
            aesSecurityHandler.OwnerPassword = "******";
            // allow to print the pdf document
            //PDF4NET v5: pdfDoc.SecurityManager.AllowPrint = true;
            aesSecurityHandler.EnablePrint = true;
            // do not allow high quality print
            //PDF4NET v5: pdfDoc.SecurityManager.FullQualityPrint = false;
            aesSecurityHandler.HighQualityPrint = false;
            // do not alow to modify the document
            //PDF4NET v5: pdfDoc.SecurityManager.AllowModifyDocument = false;
            aesSecurityHandler.EnableDocumentChange = false;
            // do not allow to extract content (text and images) from the document
            //PDF4NET v5: pdfDoc.SecurityManager.AllowExtractContent = false;
            aesSecurityHandler.EnableContentExtraction = false;
            // do not allow to fill forms or to create annotations
            //PDF4NET v5: pdfDoc.SecurityManager.AllowInteractiveEdit = false;
            aesSecurityHandler.EnableAnnotationsAndFieldsEdit = false;
            // do not allow forms fill
            //PDF4NET v5: pdfDoc.SecurityManager.AllowFormsFill = false;
            aesSecurityHandler.EnableFormsFill = false;
            // allow to extract content in support for accessibility
            //PDF4NET v5: pdfDoc.SecurityManager.AllowAccessibilityExtractContent = true;
            aesSecurityHandler.EnableContentExtractionForAccessibility = true;
            // do not allow to assemble document
            //PDF4NET v5: pdfDoc.SecurityManager.AllowAssembleDocument = false;
            aesSecurityHandler.EnableDocumentAssembly = false;

            // Create one page
            //PDF4NET v5: PDFPage pdfPage = pdfDoc.AddPage();
            PDFPage pdfPage = pdfDoc.Pages.Add();

            // Draw "Encrypted Hello world" in the center of the page
            //PDF4NET v5:
            //pdfPage.Canvas.DrawText("Encrypted",
            //    new PDFFont(PDFFontFace.Helvetica, 100), new PDFPen(new PDFRgbColor(255, 0, 0), 1),
            //    new PDFBrush(new PDFRgbColor(0, 0, 255)), pdfPage.Width / 2, pdfPage.Height / 2 - 3,
            //    0, PDFTextAlign.BottomCenter);
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X = pdfPage.Width / 2;
            slo.Y = pdfPage.Height / 2 - 3;
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFStandardFont(PDFStandardFontFace.Helvetica, 100);
            sao.Pen   = new PDFPen(new PDFRgbColor(255, 0, 0), 1);
            sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 255));
            pdfPage.Canvas.DrawString("Encrypted", sao, slo);
            slo.Y             = pdfPage.Height / 2 + 3;
            slo.VerticalAlign = PDFStringVerticalAlign.Top;
            pdfPage.Canvas.DrawString("Hello world !", sao, slo);

            // Save the document to disk
            //PDF4NET v5:pdfDoc.Save("Sample_Encryption.pdf");
            pdfDoc.Save("Sample_Encryption.pdf", aesSecurityHandler);
        }
コード例 #15
0
        private static PDFFixedDocument CreatePDFA2uDocument(Stream iccInput, Stream ttfInput)
        {
            iccInput.Position = 0;
            ttfInput.Position = 0;

            PDFFixedDocument document = new PDFFixedDocument();

            document.OptionalContentProperties = new PDFOptionalContentProperties();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PDFIccColorSpace icc = new PDFIccColorSpace();

            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PDFOutputIntent oi = new PDFOutputIntent();

            oi.Type = PDFOutputIntentType.PDFA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile  = icc;
            document.OutputIntents       = new PDFOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation          = new PDFDocumentInformation();
            document.DocumentInformation.Author   = "O2 Solutions";
            document.DocumentInformation.Title    = "PDF4NET PDF/A-2B/U Demo";
            document.DocumentInformation.Creator  = "PDF4NET PDF/A-2B/U Demo Application";
            document.DocumentInformation.Producer = "PDF4NET";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject  = "PDF/A-2B/U Sample produced by PDF4NET";
            document.XmpMetadata = new PDFXmpMetadata();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 128));

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Canvas.DrawString("PDF4NET", sao, slo);
            slo.Y             = page.Height / 2 + 10;
            slo.VerticalAlign = PDFStringVerticalAlign.Top;
            sao.Font.Size     = 14;
            page.Canvas.DrawString("This is a sample PDF/A-2B/U document that shows the PDF/A-2B/U capabilities in PDF4NET library", sao, slo);

            // PDF/A-2 documents support optional content and transparency.
            PDFOptionalContentGroup ocgPage1 = new PDFOptionalContentGroup();

            ocgPage1.Name = "Green Rectangle";
            page.Canvas.BeginOptionalContentGroup(ocgPage1);
            page.Canvas.SaveGraphicsState();
            PDFExtendedGraphicState gs = new PDFExtendedGraphicState();

            gs.FillAlpha   = 0.8;
            gs.StrokeAlpha = 0.2;
            gs.BlendMode   = PDFBlendMode.Luminosity;
            page.Canvas.SetExtendedGraphicState(gs);

            PDFBrush greenBrush = new PDFBrush(PDFRgbColor.DarkGreen);
            PDFPen   bluePen    = new PDFPen(PDFRgbColor.DarkBlue, 5);

            page.Canvas.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40);

            page.Canvas.RestoreGraphicsState();
            page.Canvas.EndOptionalContentGroup();

            // Build the display tree for the optional content,
            // how its structure and relationships between optional content groups are presented to the user.
            PDFOptionalContentDisplayTreeNode ocgPage1Node = new PDFOptionalContentDisplayTreeNode(ocgPage1);

            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node);

            return(document);
        }
コード例 #16
0
ファイル: Barcodes.cs プロジェクト: sss-software/pdf4net
        private static void Draw2DBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont)
        {
            PDFBrush brush        = new PDFBrush();
            PDFPen   lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5);

            page.Canvas.DrawString("2D barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 3; i++)
            {
                page.Canvas.DrawLine(lightGrayPen, 40, 50 + 150 * i, 570, 50 + 150 * i);
            }
            page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 500);

            string[] barcodes = new string[] { "Codablock F", "Code 16K", "PDF417", "Micro PDF417", "DataMatrix", "QR" };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = barcodeFont;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;

            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 150 * (i / 2);

                page.Canvas.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign  = -sign;
            }

            // Codablock F
            PDFCodablockFBarcode codablockFBarcode = new PDFCodablockFBarcode();

            codablockFBarcode.Data    = "*** O2S.Components.PDF4NET ***";
            codablockFBarcode.Columns = 10;
            codablockFBarcode.Rows    = 5;
            page.Canvas.DrawBarcode(codablockFBarcode, 173 - codablockFBarcode.Width / 2, 70);

            // Code 16K
            PDFCode16KBarcode code16KBarcode = new PDFCode16KBarcode();

            code16KBarcode.Data = "*** O2S.Components.PDF4NET ***";
            code16KBarcode.Rows = 6;
            page.Canvas.DrawBarcode(code16KBarcode, 173 + 266 - code16KBarcode.Width / 2, 70);

            // PDF 417
            PDF417RegularBarcode pdf417Barcode = new PDF417RegularBarcode();

            pdf417Barcode.Data    = "*** O2S.Components.PDF4NET ***";
            pdf417Barcode.Columns = 10;
            pdf417Barcode.Rows    = 0;
            page.Canvas.DrawBarcode(pdf417Barcode, 173 - pdf417Barcode.Width / 2, 220);

            // MicroPDF 417
            PDF417MicroBarcode microPDF417Barcode = new PDF417MicroBarcode();

            microPDF417Barcode.Data        = "* O2S.Components.PDF4NET *";
            microPDF417Barcode.BarcodeSize = PDF417MicroBarcodeSize.Rows6Columns4;
            page.Canvas.DrawBarcode(microPDF417Barcode, 173 + 266 - microPDF417Barcode.Width / 2, 220);

            // DataMatrix
            PDFDataMatrixBarcode datamatrixBarcode = new PDFDataMatrixBarcode();

            datamatrixBarcode.Data        = "*** O2S.Components.PDF4NET ***";
            datamatrixBarcode.XDimension  = 2;
            datamatrixBarcode.BarcodeSize = DataMatrixBarcodeSize.Auto;
            page.Canvas.DrawBarcode(datamatrixBarcode, 173 - datamatrixBarcode.Width / 2, 370);

            // QR Barcode
            PDFQrBarcode qrBarcode = new PDFQrBarcode();

            qrBarcode.XDimension   = 2;
            qrBarcode.Data         = "PDF4NET: http://www.o2sol.com/";
            qrBarcode.CharacterSet = PDFQrBarcodeCharacterSet.ISO88591;
            page.Canvas.DrawBarcode(qrBarcode, 173 + 266 - qrBarcode.Width / 2, 370);

            page.Canvas.CompressAndClose();
        }
コード例 #17
0
ファイル: Barcodes.cs プロジェクト: sss-software/pdf4net
        private static void DrawGenericBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont)
        {
            PDFBrush brush        = new PDFBrush();
            PDFPen   lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5);

            page.Canvas.DrawString("Generic barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 7; i++)
            {
                page.Canvas.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i);
            }
            page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 750);

            string[] barcodes = new string[] { "Codabar", "Code 11", "Code 25", "Code 25 Interleaved", "Code 39", "Code 39 Extended",
                                               "Code 93", "Code 93 Extended", "Code 128 A", "Code 128 B", "Code 128 C", "COOP 25", "Matrix 25", "MSI/Plessey" };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = barcodeFont;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;

            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 100 * (i / 2);

                page.Canvas.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign  = -sign;
            }

            // Codabar
            PDFCodabarBarcode codabarBarcode = new PDFCodabarBarcode();

            codabarBarcode.Data = "523408943724";
            codabarBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(codabarBarcode, 173 - codabarBarcode.Width / 2, 70);

            // Code 11
            PDFCode11Barcode code11Barcode = new PDFCode11Barcode();

            code11Barcode.Data = "42376524534";
            code11Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code11Barcode, 173 + 266 - code11Barcode.Width / 2, 70);

            // Code 25
            PDFCode25Barcode code25Barcode = new PDFCode25Barcode();

            code25Barcode.Data = "857621354312";
            code25Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code25Barcode, 173 - code25Barcode.Width / 2, 170);

            // Code 25 Interleaved
            PDFCode25InterleavedBarcode code25InterleavedBarcode = new PDFCode25InterleavedBarcode();

            code25InterleavedBarcode.Data = "42376524534";
            code25InterleavedBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code25InterleavedBarcode, 173 + 266 - code25InterleavedBarcode.Width / 2, 170);

            // Code 39
            PDFCode39Barcode code39Barcode = new PDFCode39Barcode();

            code39Barcode.Data = "6430784327";
            code39Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code39Barcode, 173 - code39Barcode.Width / 2, 270);

            // Code 39 Extended
            PDFCode39ExtendedBarcode code39ExtendedBarcode = new PDFCode39ExtendedBarcode();

            code39ExtendedBarcode.Data = "8990436322";
            code39ExtendedBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code39ExtendedBarcode, 173 + 266 - code39ExtendedBarcode.Width / 2, 270);

            // Code 93
            PDFCode93Barcode code93Barcode = new PDFCode93Barcode();

            code93Barcode.Data = "6345212344";
            code93Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code93Barcode, 173 - code93Barcode.Width / 2, 370);

            // Code 39 Extended
            PDFCode93ExtendedBarcode code93ExtendedBarcode = new PDFCode93ExtendedBarcode();

            code93ExtendedBarcode.Data = "125436732";
            code93ExtendedBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code93ExtendedBarcode, 173 + 266 - code93ExtendedBarcode.Width / 2, 370);

            // Code 128 A
            PDFCode128ABarcode code128ABarcode = new PDFCode128ABarcode();

            code128ABarcode.Data = "PDF4NET";
            code128ABarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code128ABarcode, 173 - code128ABarcode.Width / 2, 470);

            // Code 128 B
            PDFCode128BBarcode code128BBarcode = new PDFCode128BBarcode();

            code128BBarcode.Data = "pdf4net";
            code128BBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code128BBarcode, 173 + 266 - code128BBarcode.Width / 2, 470);

            // Code 128 C
            PDFCode128CBarcode code128CBarcode = new PDFCode128CBarcode();

            code128CBarcode.Data = "423409865432";
            code128CBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(code128CBarcode, 173 - code128CBarcode.Width / 2, 570);

            // COOP 25
            PDFCoop25Barcode coop25Barcode = new PDFCoop25Barcode();

            coop25Barcode.Data = "43256565543";
            coop25Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(coop25Barcode, 173 + 266 - coop25Barcode.Width / 2, 570);

            // Matrix 25
            PDFMatrix25Barcode matrix25Barcode = new PDFMatrix25Barcode();

            matrix25Barcode.Data = "500540024300";
            matrix25Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(matrix25Barcode, 173 - matrix25Barcode.Width / 2, 670);

            // MSI/Plessey
            PDFMsiPlesseyBarcode msiPlesseyBarcode = new PDFMsiPlesseyBarcode();

            msiPlesseyBarcode.Data = "1124332556";
            msiPlesseyBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(msiPlesseyBarcode, 173 + 266 - msiPlesseyBarcode.Width / 2, 670);

            page.Canvas.CompressAndClose();
        }
コード例 #18
0
ファイル: Barcodes.cs プロジェクト: sss-software/pdf4net
        private static void DrawPostAndTransportantionBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont)
        {
            PDFBrush brush        = new PDFBrush();
            PDFPen   lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5);

            page.Canvas.DrawString("Post and transportation barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 7; i++)
            {
                page.Canvas.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i);
            }
            page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 750);

            string[] barcodes = new string[] { "FedEx Ground 96", "IATA 25", "Identcode", "Leitcode", "KIX", "Planet",
                                               "PostNet", "RM4SCC", "SCC-14", "SingaporePost", "SSCC-18", "USPS FIM", "USPS Horizontal", "USPS PIC" };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = barcodeFont;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;

            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 100 * (i / 2);

                page.Canvas.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign  = -sign;
            }

            // FedEx Ground 96
            PDFFedExGround96Barcode fedexGround96Barcode = new PDFFedExGround96Barcode();

            fedexGround96Barcode.Data = "962343237687543423123";
            fedexGround96Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(fedexGround96Barcode, 173 - fedexGround96Barcode.Width / 2, 70);

            // IATA 25
            PDFIata25Barcode iata25Barcode = new PDFIata25Barcode();

            iata25Barcode.Data = "54366436563";
            iata25Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(iata25Barcode, 173 + 266 - iata25Barcode.Width / 2, 70);

            // Identcode
            PDFIdentcodeBarcode identcodeBarcode = new PDFIdentcodeBarcode();

            identcodeBarcode.Data = "12435678214";
            identcodeBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(identcodeBarcode, 173 - identcodeBarcode.Width / 2, 170);

            // Leitcode
            PDFLeitcodeBarcode leitcodeBarcode = new PDFLeitcodeBarcode();

            leitcodeBarcode.Data = "1243657687321";
            leitcodeBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(leitcodeBarcode, 173 + 266 - leitcodeBarcode.Width / 2, 170);

            // KIX
            PDFKixBarcode kixBarcode = new PDFKixBarcode();

            kixBarcode.Data = "PDF4NET";
            kixBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(kixBarcode, 173 - kixBarcode.Width / 2, 270);

            // Planet
            PDFPlanetBarcode planetBarcode = new PDFPlanetBarcode();

            planetBarcode.Data = "645316643300";
            planetBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(planetBarcode, 173 + 266 - planetBarcode.Width / 2, 270);

            // PostNet
            PDFPostNetBarcode postNetBarcode = new PDFPostNetBarcode();

            postNetBarcode.Data = "04231454322";
            postNetBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(postNetBarcode, 173 - postNetBarcode.Width / 2, 370);

            // RM4SCC
            PDFRm4sccBarcode rm4sccBarcode = new PDFRm4sccBarcode();

            rm4sccBarcode.Data = "PDF4NET";
            rm4sccBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(rm4sccBarcode, 173 + 266 - rm4sccBarcode.Width / 2, 370);

            // SCC-14
            PDFScc14Barcode scc14Barcode = new PDFScc14Barcode();

            scc14Barcode.Data = "3255091205412";
            scc14Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(scc14Barcode, 173 - scc14Barcode.Width / 2, 470);

            // Singapore Post
            PDFSingaporePostBarcode singaporePostBarcode = new PDFSingaporePostBarcode();

            singaporePostBarcode.Data = "PDF4NET";
            singaporePostBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(singaporePostBarcode, 173 + 266 - singaporePostBarcode.Width / 2, 470);

            // SSCC-18
            PDFSscc18Barcode sscc18Barcode = new PDFSscc18Barcode();

            sscc18Barcode.Data = "09876543219832435";
            sscc18Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(sscc18Barcode, 173 - sscc18Barcode.Width / 2, 570);

            // USPS FIM
            PDFUspsFimBarcode uspsFimBarcode = new PDFUspsFimBarcode();

            uspsFimBarcode.Data = "A";
            uspsFimBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(uspsFimBarcode, 173 + 266 - uspsFimBarcode.Width / 2, 570);

            // USPS Horizontal
            PDFUspsHorizontalBarcode uspsHorizontalBarcode = new PDFUspsHorizontalBarcode();

            uspsHorizontalBarcode.Data = "1111";
            uspsHorizontalBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.None;
            page.Canvas.DrawBarcode(uspsHorizontalBarcode, 173 - uspsHorizontalBarcode.Width / 2, 670);

            // USPS PIC
            PDFUspsPicBarcode uspsPicBarcode = new PDFUspsPicBarcode();

            uspsPicBarcode.Data = "914354657901234354019";
            uspsPicBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(uspsPicBarcode, 173 + 266 - uspsPicBarcode.Width / 2, 670);

            page.Canvas.CompressAndClose();
        }
コード例 #19
0
ファイル: Annotations.cs プロジェクト: sss-software/pdf4net
        private static void Create3DAnnotations(PDFFixedDocument document, PDFFont font, Stream u3dStream)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            page.Canvas.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.Canvas.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.DisplayRectangle = new PDFDisplayRectangle(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.Canvas.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Canvas.DrawString("Top", sao, slo);

            PDFGoTo3DViewAction gotoTopView = new PDFGoTo3DViewAction();

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

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

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

            PDFGoTo3DViewAction gotoSideView = new PDFGoTo3DViewAction();

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

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

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

            PDFGoTo3DViewAction gotoIsometricView = new PDFGoTo3DViewAction();

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

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

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

            PDFGoTo3DViewAction gotoFrontView = new PDFGoTo3DViewAction();

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

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

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

            PDFGoTo3DViewAction gotoBackView = new PDFGoTo3DViewAction();

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

            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.DisplayRectangle = new PDFDisplayRectangle(610, 585, 120, 18);
            linkGotoBackView.Action           = gotoBackView;
        }
コード例 #20
0
ファイル: Text.cs プロジェクト: sss-software/pdf4net
        private static void DrawTextLines(PDFPage page, PDFStandardFont titleFont)
        {
            PDFBrush        brush     = new PDFBrush();
            PDFPen          redPen    = new PDFPen(PDFRgbColor.Red, 0.5);
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);

            page.Canvas.DrawString("Text lines", titleFont, brush, 20, 50);

            page.Canvas.DrawLine(redPen, 20, 70, 150, 70);
            page.Canvas.DrawLine(redPen, 20, 70, 20, 80);
            page.Canvas.DrawString("Simple text line with default top left text alignment and no rotation", helvetica, brush, 20, 70);

            page.Canvas.DrawString("Text align", helvetica, brush, 20, 110);

            redPen.DashPattern = new double[] { 1, 1 };
            page.Canvas.DrawLine(redPen, 20, 125, 590, 125);
            page.Canvas.DrawLine(redPen, 20, 165, 590, 165);
            page.Canvas.DrawLine(redPen, 20, 205, 590, 205);
            page.Canvas.DrawLine(redPen, 20, 125, 20, 205);
            page.Canvas.DrawLine(redPen, 305, 125, 305, 205);
            page.Canvas.DrawLine(redPen, 590, 125, 590, 205);

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = helvetica;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            // Top left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 20;
            slo.Y = 125;
            page.Canvas.DrawString("Top Left", sao, slo);

            // Top center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 305;
            slo.Y = 125;
            page.Canvas.DrawString("Top Center", sao, slo);

            // Top right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 590;
            slo.Y = 125;
            page.Canvas.DrawString("Top Right", sao, slo);

            // Middle left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 20;
            slo.Y = 165;
            page.Canvas.DrawString("Middle Left", sao, slo);

            // Middle center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 305;
            slo.Y = 165;
            page.Canvas.DrawString("Middle Center", sao, slo);

            // Middle right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 590;
            slo.Y = 165;
            page.Canvas.DrawString("Middle Right", sao, slo);

            // Bottom left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 20;
            slo.Y = 205;
            page.Canvas.DrawString("Bottom Left", sao, slo);

            // Bottom center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 305;
            slo.Y = 205;
            page.Canvas.DrawString("Bottom Center", sao, slo);

            // Bottom right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 590;
            slo.Y = 205;
            page.Canvas.DrawString("Bottom Right", sao, slo);

            page.Canvas.DrawString("Text rotation", helvetica, brush, 20, 250);

            redPen.DashPattern = new double[] { 1, 1 };
            page.Canvas.DrawLine(redPen, 20, 265, 590, 265);
            page.Canvas.DrawLine(redPen, 20, 305, 590, 305);
            page.Canvas.DrawLine(redPen, 20, 345, 590, 345);
            page.Canvas.DrawLine(redPen, 20, 265, 20, 345);
            page.Canvas.DrawLine(redPen, 305, 265, 305, 345);
            page.Canvas.DrawLine(redPen, 590, 265, 590, 345);

            slo.Rotation = 30;
            // Top left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 20;
            slo.Y = 265;
            page.Canvas.DrawString("Top Left", sao, slo);

            // Top center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 305;
            slo.Y = 265;
            page.Canvas.DrawString("Top Center", sao, slo);

            // Top right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X = 590;
            slo.Y = 265;
            page.Canvas.DrawString("Top Right", sao, slo);

            // Middle left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 20;
            slo.Y = 305;
            page.Canvas.DrawString("Middle Left", sao, slo);

            // Middle center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 305;
            slo.Y = 305;
            page.Canvas.DrawString("Middle Center", sao, slo);

            // Middle right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            slo.X = 590;
            slo.Y = 305;
            page.Canvas.DrawString("Middle Right", sao, slo);

            // Bottom left aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Left;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 20;
            slo.Y = 345;
            page.Canvas.DrawString("Bottom Left", sao, slo);

            // Bottom center aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 305;
            slo.Y = 345;
            page.Canvas.DrawString("Bottom Center", sao, slo);

            // Bottom right aligned text
            slo.HorizontalAlign = PDFStringHorizontalAlign.Right;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = 590;
            slo.Y = 345;
            page.Canvas.DrawString("Bottom Right", sao, slo);

            page.Canvas.CompressAndClose();
        }
コード例 #21
0
ファイル: Text.cs プロジェクト: sss-software/pdf4net
        private static void DrawTextRenderingModes(PDFPage page, PDFStandardFont titleFont)
        {
            PDFBrush        brush         = new PDFBrush();
            PDFPen          redPen        = new PDFPen(PDFRgbColor.Red, 0.5);
            PDFStandardFont helvetica     = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);
            PDFStandardFont helveticaBold = new PDFStandardFont(PDFStandardFontFace.Helvetica, 80);

            page.Canvas.DrawString("Text rendering modes", titleFont, brush, 20, 50);

            page.Canvas.DrawString("Fill text", helvetica, brush, 20, 90);
            page.Canvas.DrawString("Stroke text", helvetica, brush, 20, 160);
            page.Canvas.DrawString("Fill and stroke text", helvetica, brush, 20, 230);
            page.Canvas.DrawString("Invisible text", helvetica, brush, 20, 300);
            page.Canvas.DrawString("Fill and clip text", helvetica, brush, 20, 370);
            page.Canvas.DrawString("Stroke and clip text", helvetica, brush, 20, 440);
            page.Canvas.DrawString("Fill, stroke and clip text", helvetica, brush, 20, 510);
            page.Canvas.DrawString("Clip text", helvetica, brush, 20, 580);

            // Fill text - text interior is filled because only the brush is available for drawing.
            page.Canvas.DrawString("A B C", helveticaBold, brush, 300, 90);

            // Stroke text - text outline is stroked becuase only the pen is available for drawing.
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X = 300;
            slo.Y = 160;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = helveticaBold;
            sao.Pen   = redPen;
            sao.Brush = null;
            page.Canvas.DrawString("A B C", sao, slo);

            // Fill and stroke text - text interior is filled and text outline is stroked
            // because both pen and brush are available.
            slo.Y     = 230;
            sao.Pen   = redPen;
            sao.Brush = brush;
            page.Canvas.DrawString("A B C", sao, slo);

            // Invisible text - text is not displayed because both pen and brush are not available.
            slo.Y     = 300;
            sao.Pen   = null;
            sao.Brush = null;
            page.Canvas.DrawString("A B C", sao, slo);

            // Fill and clip text - text interior is filled and then text outline is added to current clipping path.
            page.Canvas.SaveGraphicsState();
            helveticaBold.TextRenderingMode = PDFTextRenderingMode.FillAndClipText;
            slo.Y     = 370;
            sao.Pen   = null;
            sao.Brush = brush;
            page.Canvas.DrawString("A B C", sao, slo);
            DrawHorizontalLines(page.Canvas, redPen, slo.X, slo.Y, 250, 70);
            page.Canvas.RestoreGraphicsState();

            // Stroke and clip text - text outline is stroked and then text outline is added to current clipping path.
            page.Canvas.SaveGraphicsState();
            helveticaBold.TextRenderingMode = PDFTextRenderingMode.StrokeAndClipText;
            slo.Y     = 440;
            sao.Pen   = redPen;
            sao.Brush = null;
            page.Canvas.DrawString("A B C", sao, slo);
            DrawHorizontalLines(page.Canvas, redPen, slo.X, slo.Y, 250, 70);
            page.Canvas.RestoreGraphicsState();

            // Fill, Stroke and clip text - text interior is filled, text outline is stroked and then text outline is added to current clipping path.
            page.Canvas.SaveGraphicsState();
            helveticaBold.TextRenderingMode = PDFTextRenderingMode.FillStrokeAndClipText;
            slo.Y     = 510;
            sao.Pen   = redPen;
            sao.Brush = brush;
            page.Canvas.DrawString("A B C", sao, slo);
            DrawHorizontalLines(page.Canvas, redPen, slo.X, slo.Y, 250, 70);
            page.Canvas.RestoreGraphicsState();

            // Clip text - text outline is added to current clipping path.
            page.Canvas.SaveGraphicsState();
            helveticaBold.TextRenderingMode = PDFTextRenderingMode.ClipText;
            slo.Y     = 580;
            sao.Pen   = redPen;
            sao.Brush = brush;
            page.Canvas.DrawString("A B C", sao, slo);
            DrawHorizontalLines(page.Canvas, redPen, slo.X, slo.Y, 250, 70);
            page.Canvas.RestoreGraphicsState();
        }
コード例 #22
0
ファイル: Text.cs プロジェクト: sss-software/pdf4net
        private static void DrawTextWrap(PDFPage page, PDFStandardFont titleFont)
        {
            PDFBrush        brush     = new PDFBrush();
            PDFPen          redPen    = new PDFPen(PDFRgbColor.Red, 0.5);
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12);

            page.Canvas.DrawString("Text wrapping", titleFont, brush, 20, 50);

            page.Canvas.DrawLine(redPen, 20, 70, 20, 150);
            page.Canvas.DrawLine(redPen, 300, 70, 300, 150);
            page.Canvas.DrawLine(redPen, 20, 70, 300, 70);

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = helvetica;

            // Height is not set, text has no vertical limit.
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Justified;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;
            slo.X     = 20;
            slo.Y     = 70;
            slo.Width = 280;
            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
                          "Sed vel euismod risus. Fusce viverra, nisi auctor ullamcorper porttitor, " +
                          "ipsum lacus lobortis metus, sit amet dictum lacus velit nec diam. " +
                          "Morbi arcu diam, euismod a auctor nec, aliquam in lectus." +
                          "Ut ultricies iaculis augue sit amet adipiscing. Aenean blandit tortor a nisi " +
                          "dignissim fermentum id adipiscing mauris. Aenean libero turpis, varius nec ultricies " +
                          "faucibus, pretium quis lectus. Morbi mollis lorem vel erat condimentum mattis mollis " +
                          "nulla sollicitudin. Nunc ut massa id felis laoreet feugiat eget at eros.";

            page.Canvas.DrawString(text, sao, slo);

            page.Canvas.DrawLine(redPen, 310, 70, 310, 147);
            page.Canvas.DrawLine(redPen, 590, 70, 590, 147);
            page.Canvas.DrawLine(redPen, 310, 70, 590, 70);
            page.Canvas.DrawLine(redPen, 310, 147, 590, 147);

            // Height is set, text is limited on vertical.
            slo.X      = 310;
            slo.Y      = 70;
            slo.Width  = 280;
            slo.Height = 77;
            page.Canvas.DrawString(text, sao, slo);

            PDFPath clipPath = new PDFPath();

            clipPath.AddRectangle(310, 160, 280, 77);
            page.Canvas.DrawPath(redPen, clipPath);

            page.Canvas.SaveGraphicsState();
            page.Canvas.SetClip(clipPath);

            // Height is not set but text is cliped on vertical.
            slo.X      = 310;
            slo.Y      = 160;
            slo.Width  = 280;
            slo.Height = 0;
            page.Canvas.DrawString(text, sao, slo);

            page.Canvas.RestoreGraphicsState();

            page.Canvas.DrawLine(redPen, 10, 400, 300, 400);
            page.Canvas.DrawLine(redPen, 20, 300, 20, 500);
            // Wrapped text is always rotated around top left corner, no matter the text alignment
            page.Canvas.DrawRectangle(redPen, 20, 400, 280, 80, 30);
            slo.X        = 20;
            slo.Y        = 400;
            slo.Width    = 280;
            slo.Height   = 80;
            slo.Rotation = 30;
            page.Canvas.DrawString(text, sao, slo);

            page.Canvas.DrawLine(redPen, 310, 600, 590, 600);
            page.Canvas.DrawLine(redPen, 450, 450, 450, 750);

            // Rotation around the center of the box requires some affine transformations.
            page.Canvas.SaveGraphicsState();
            page.Canvas.TranslateTransform(450, 600);
            page.Canvas.RotateTransform(30);
            page.Canvas.DrawRectangle(redPen, -140, -40, 280, 80);
            slo.X        = -140;
            slo.Y        = -40;
            slo.Width    = 280;
            slo.Height   = 80;
            slo.Rotation = 0;
            page.Canvas.DrawString(text, sao, slo);

            page.Canvas.RestoreGraphicsState();
        }
コード例 #23
0
        private static void CreateNamedActions(PDFFixedDocument document, PDFFont font)
        {
            PDFPen   blackPen   = new PDFPen(new PDFRgbColor(0, 0, 0), 1);
            PDFBrush blackBrush = new PDFBrush();

            font.Size = 12;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

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

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Canvas.DrawString("Named actions:", font, blackBrush, 400, 20);

                /////////////
                // First page
                /////////////
                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 40, 200, 20);
                slo.X = 500;
                slo.Y = 50;
                document.Pages[i].Canvas.DrawString("Go To First Page", sao, slo);

                // Create a link annotation on top of the widget.
                PDFLinkAnnotation link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 40, 200, 20);

                // Create a named action and attach it to the link.
                PDFNamedAction namedAction = new PDFNamedAction();
                namedAction.NamedAction = PDFActionName.FirstPage;
                link.Action             = namedAction;

                /////////////
                // Prev page
                /////////////
                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 80, 200, 20);
                slo.Y = 90;
                document.Pages[i].Canvas.DrawString("Go To Previous Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 80, 200, 20);

                // Create a named action and attach it to the link.
                namedAction             = new PDFNamedAction();
                namedAction.NamedAction = PDFActionName.PrevPage;
                link.Action             = namedAction;

                /////////////
                // Next page
                /////////////
                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 120, 200, 20);
                slo.Y = 130;
                document.Pages[i].Canvas.DrawString("Go To Next Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 120, 200, 20);

                // Create a named action and attach it to the link.
                namedAction             = new PDFNamedAction();
                namedAction.NamedAction = PDFActionName.NextPage;
                link.Action             = namedAction;

                /////////////
                // Last page
                /////////////
                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 160, 200, 20);
                slo.Y = 170;
                document.Pages[i].Canvas.DrawString("Go To Last Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 160, 200, 20);

                // Create a named action and attach it to the link.
                namedAction             = new PDFNamedAction();
                namedAction.NamedAction = PDFActionName.LastPage;
                link.Action             = namedAction;

                /////////////
                // Print document
                /////////////
                document.Pages[i].Canvas.DrawRectangle(blackPen, 400, 200, 200, 20);
                slo.Y = 210;
                document.Pages[i].Canvas.DrawString("Print Document", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PDFLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.DisplayRectangle = new PDFDisplayRectangle(400, 200, 200, 20);

                // Create a named action and attach it to the link.
                namedAction             = new PDFNamedAction();
                namedAction.NamedAction = PDFActionName.Print;
                link.Action             = namedAction;
            }
        }
コード例 #24
0
ファイル: Annotations.cs プロジェクト: sss-software/pdf4net
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            // Create one page
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            PDFBrush blackBrush = new PDFBrush(new PDFRgbColor(0, 0, 0));
            //PDF4NET v5: PDFFont fontSection = new PDFFont(PDFFontFace.Helvetica, 10);
            PDFStandardFont fontSection = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10);

            fontSection.Bold = true;
            //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 8);
            PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 8);

            //PDF4NET v5: page.Canvas.DrawText("Text annotations", fontSection, null, blackBrush, 20, 45, 0, PDFTextAlign.BottomLeft);
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions()
            {
                X = 20, Y = 45, VerticalAlign = PDFStringVerticalAlign.Bottom
            };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions()
            {
                Font = fontSection, Brush = blackBrush
            };

            page.Canvas.DrawString("Text annotations", sao, slo);

            // Create all available text annotations
            //PDF4NET v5: PDFTextAnnotation ta = new PDFTextAnnotation("Comment", "Comment annotation");
            PDFTextAnnotation ta = new PDFTextAnnotation()
            {
                Author = "Comment", Contents = "Comment annotation"
            };

            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Comment;
            //PDF4NET v5: ta.Rectangle = new RectangleF(20, 60, 20, 20);
            ta.Location = new PDFPoint(20, 60);
            //PDF4NET v5: page.Canvas.DrawText("Comment", fontText, null, blackBrush, 20, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Comment", fontText, blackBrush, 20, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("Help", "Help annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "Help", Contents = "Help annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Help;
            //PDF4NET v5: ta.Rectangle = new RectangleF(100, 60, 20, 20);
            ta.Location = new PDFPoint(100, 60);
            //PDF4NET v5: page.Canvas.DrawText("Help", fontText, null, blackBrush, 100, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Help", fontText, blackBrush, 100, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("Insert", "Insert annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "Insert", Contents = "Insert annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Insert;
            //PDF4NET v5: ta.Rectangle = new RectangleF(180, 60, 20, 20);
            ta.Location = new PDFPoint(180, 60);
            //PDF4NET v5: page.Canvas.DrawText("Insert", fontText, null, blackBrush, 180, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Insert", fontText, blackBrush, 180, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("Key", "Key annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "Key", Contents = "Key annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Key;
            //PDF4NET v5: ta.Rectangle = new RectangleF(260, 60, 20, 20);
            ta.Location = new PDFPoint(260, 60);
            //PDF4NET v5: page.Canvas.DrawText("Key", fontText, null, blackBrush, 260, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Key", fontText, blackBrush, 260, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("New paragraph", "New paragraph annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "New paragraph", Contents = "New paragraph annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.NewParagraph;
            //PDF4NET v5: ta.Rectangle = new RectangleF(340, 60, 20, 20);
            ta.Location = new PDFPoint(340, 60);
            //PDF4NET v5: page.Canvas.DrawText("New paragraph", fontText, null, blackBrush, 340, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("New paragraph", fontText, blackBrush, 340, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("Note", "Note annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "Note", Contents = "Note annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Note;
            //PDF4NET v5: ta.Rectangle = new RectangleF(420, 60, 20, 20);
            ta.Location = new PDFPoint(420, 60);
            //PDF4NET v5: page.Canvas.DrawText("Note", fontText, null, blackBrush, 420, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Note", fontText, blackBrush, 420, 80);

            //PDF4NET v5: ta = new PDFTextAnnotation("Paragraph", "Paragraph annotation");
            ta = new PDFTextAnnotation()
            {
                Author = "Paragraph", Contents = "Paragraph annotation"
            };
            page.Annotations.Add(ta);
            ta.Icon = PDFTextAnnotationIcon.Paragraph;
            //PDF4NET v5: ta.Rectangle = new RectangleF(500, 60, 20, 20);
            ta.Location = new PDFPoint(500, 60);
            //PDF4NET v5: page.Canvas.DrawText("Paragraph", fontText, null, blackBrush, 500, 80, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Paragraph", fontText, blackBrush, 500, 80);

            // Rubber stamp annotations

            //PDF4NET v5: page.Canvas.DrawText("Rubber stamp annotations", fontSection, null, blackBrush, 20, 120, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Rubber stamp annotations", fontSection, blackBrush, 20, 120);

            // Create all available rubber stamp annotations
            //PDF4NET v5: PDFRubberStampAnnotation rsa = new PDFRubberStampAnnotation("Approved", "Approved annotation");
            PDFRubberStampAnnotation rsa = new PDFRubberStampAnnotation()
            {
                Author = "Approved", Contents = "Approved annotation"
            };

            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Approved;
            rsa.StampName = PDFRubberStampAnnotationName.Approved;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(20, 140, 100, 30);
            rsa.Opacity          = 50;
            //PDF4NET v5: page.Canvas.DrawText("Approved", fontText, null, blackBrush, 20, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Approved", fontText, blackBrush, 20, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("As Is", "As Is annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "As Is", Contents = "As Is annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.AsIs;
            rsa.StampName = PDFRubberStampAnnotationName.AsIs;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(120, 140, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("As Is", fontText, null, blackBrush, 120, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("As Is", fontText, blackBrush, 120, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Confidential", "Confidential annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Confidential", Contents = "Confidential annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Confidential;
            rsa.StampName = PDFRubberStampAnnotationName.Confidential;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(220, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(220, 140, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Confidential", fontText, null, blackBrush, 220, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Confidential", fontText, blackBrush, 220, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Departmental", "Departmental annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Departmental", Contents = "Departmental annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Departmental;
            rsa.StampName = PDFRubberStampAnnotationName.Departmental;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(320, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(320, 140, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Departmental", fontText, null, blackBrush, 320, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Departmental", fontText, blackBrush, 320, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Draft", "Draft annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Draft", Contents = "Draft annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Draft;
            rsa.StampName = PDFRubberStampAnnotationName.Draft;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(420, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(420, 140, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Draft", fontText, null, blackBrush, 420, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Draft", fontText, blackBrush, 420, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Experimental", "Experimental annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Experimental", Contents = "Experimental annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Experimental;
            rsa.StampName = PDFRubberStampAnnotationName.Experimental;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(520, 140, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(520, 140, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Experimental", fontText, null, blackBrush, 520, 180, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Experimental", fontText, blackBrush, 520, 180);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Expired", "Expired annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Expired", Contents = "Expired annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Expired;
            rsa.StampName = PDFRubberStampAnnotationName.Expired;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(20, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Expired", fontText, null, blackBrush, 20, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Expired", fontText, blackBrush, 20, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Final", "Final annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Final", Contents = "Final annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Final;
            rsa.StampName = PDFRubberStampAnnotationName.Final;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(120, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Final", fontText, null, blackBrush, 120, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Final", fontText, blackBrush, 120, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("ForComment", "ForComment annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "ForComment", Contents = "ForComment annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.ForComment;
            rsa.StampName = PDFRubberStampAnnotationName.ForComment;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(220, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(220, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("ForComment", fontText, null, blackBrush, 220, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("ForComment", fontText, blackBrush, 220, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("ForPublicRelease", "ForPublicRelease annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "ForPublicRelease", Contents = "ForPublicRelease annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.ForPublicRelease;
            rsa.StampName = PDFRubberStampAnnotationName.ForPublicRelease;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(320, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(320, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("ForPublicRelease", fontText, null, blackBrush, 320, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("ForPublicRelease", fontText, blackBrush, 320, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("NotApproved", "NotApproved annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "NotApproved", Contents = "NotApproved annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.NotApproved;
            rsa.StampName = PDFRubberStampAnnotationName.NotApproved;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(420, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(420, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("NotApproved", fontText, null, blackBrush, 420, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("NotApproved", fontText, blackBrush, 420, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("NotForPublicRelease", "NotForPublicRelease annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "NotForPublicRelease", Contents = "NotForPublicRelease annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.NotForPublicRelease;
            rsa.StampName = PDFRubberStampAnnotationName.NotForPublicRelease;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(520, 200, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(520, 200, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("NotForPublicRelease", fontText, null, blackBrush, 520, 240, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("NotForPublicRelease", fontText, blackBrush, 520, 240);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Sold", "Sold annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "Sold", Contents = "Sold annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Sold;
            rsa.StampName = PDFRubberStampAnnotationName.Sold;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 260, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(20, 260, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("Sold", fontText, null, blackBrush, 20, 300, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Sold", fontText, blackBrush, 20, 300);

            //PDF4NET v5: rsa = new PDFRubberStampAnnotation("TopSecret", "TopSecret annotation");
            rsa = new PDFRubberStampAnnotation()
            {
                Author = "TopSecret", Contents = "TopSecret annotation"
            };
            page.Annotations.Add(rsa);
            //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.TopSecret;
            rsa.StampName = PDFRubberStampAnnotationName.TopSecret;
            //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 260, 100, 30);
            rsa.DisplayRectangle = new PDFDisplayRectangle(120, 260, 100, 30);
            //PDF4NET v5: page.Canvas.DrawText("TopSecret", fontText, null, blackBrush, 120, 300, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("TopSecret", fontText, blackBrush, 120, 300);

            // Line annotations

            //PDF4NET v5: page.Canvas.DrawText("Line annotations", fontSection, null, blackBrush, 20, 350, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Line annotations", fontSection, blackBrush, 20, 350);
            //PDF4NET v5: PDFLineAnnotation la = new PDFLineAnnotation("Line", "Line annotation");
            PDFLineAnnotation la = new PDFLineAnnotation()
            {
                Author = "Line", Contents = "Line annotation"
            };

            page.Annotations.Add(la);
            //PDF4NET v5: la.BeginLineStyle = PDFLineEndingStyle.Circle;
            la.StartLineSymbol = PDFLineEndingStyle.Circle;
            //PDF4NET v5: la.EndLineStyle = PDFLineEndingStyle.OpenArrow;
            la.EndLineSymbol = PDFLineEndingStyle.OpenArrow;
            //PDF4NET v5: la.LineDirection = PDFLineDirection.TopLeftToBottomRight;

            //PDF4NET v5: la.Rectangle = new RectangleF(20, 370, 150, 30);
            la.StartPoint = new PDFPoint(20, 370);
            la.EndPoint   = new PDFPoint(170, 400);
            //PDF4NET v5: la.Border = new PDFAnnotationBorder(1, PDFBorderStyle.Solid);
            la.LineWidth = 1;
            //PDF4NET v5: la.Color = new PDFRgbColor(Color.Red);
            la.LineColor = PDFRgbColor.Red;
            //PDF4NET v5: la.InteriorColor = new PDFRgbColor(Color.CornflowerBlue);
            la.InteriorColor = PDFRgbColor.CornflowerBlue;
            //PDF4NET v5: page.Canvas.DrawText("Line annotation with a circle and open arrow", fontText, null, blackBrush, 20, 420, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Line annotation with a circle and open arrow", fontText, blackBrush, 20, 420);

            // File attachment annotations

            //PDF4NET v5: page.Canvas.DrawText("File attachment annotations", fontSection, null, blackBrush, 20, 450, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("File attachment annotations", fontSection, blackBrush, 20, 450);
            // Create all available file attachment annotations
            //PDF4NET v5: PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation("Graph", "Graph icon");
            PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation()
            {
                Author = "Graph", Contents = "Graph icon"
            };

            page.Annotations.Add(faa);
            faa.Icon = PDFFileAttachmentAnnotationIcon.Graph;
            //PDF4NET v5: faa.Rectangle = new RectangleF(20, 470, 20, 20);
            faa.Location = new PDFPoint(20, 470);
            faa.FileName = "sample.pdf";
            faa.Payload  = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf");
            //PDF4NET v5: page.Canvas.DrawText("Graph", fontText, null, blackBrush, 20, 500, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Graph", fontText, blackBrush, 20, 500);

            //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("Paperclip", "Paperclip icon");
            faa = new PDFFileAttachmentAnnotation()
            {
                Author = "Paperclip", Contents = "Paperclip icon"
            };
            page.Annotations.Add(faa);
            faa.Icon = PDFFileAttachmentAnnotationIcon.Paperclip;
            //PDF4NET v5: faa.Rectangle = new RectangleF(100, 470, 20, 20);
            faa.Location = new PDFPoint(100, 470);
            faa.FileName = "sample.pdf";
            faa.Payload  = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf");
            //PDF4NET v5: page.Canvas.DrawText("Paperclip", fontText, null, blackBrush, 100, 500, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Paperclip", fontText, blackBrush, 100, 500);

            //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("PushPin", "PushPin icon");
            faa = new PDFFileAttachmentAnnotation()
            {
                Author = "PushPin", Contents = "PushPin icon"
            };
            page.Annotations.Add(faa);
            faa.Icon = PDFFileAttachmentAnnotationIcon.PushPin;
            //PDF4NET v5: faa.Rectangle = new RectangleF(180, 470, 20, 20);
            faa.Location = new PDFPoint(180, 470);
            faa.FileName = "sample.pdf";
            faa.Payload  = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf");
            //PDF4NET v5: page.Canvas.DrawText("PushPin", fontText, null, blackBrush, 180, 500, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("PushPin", fontText, blackBrush, 180, 500);

            //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("Tag", "Tag icon");
            faa = new PDFFileAttachmentAnnotation()
            {
                Author = "Tag", Contents = "Tag icon"
            };
            page.Annotations.Add(faa);
            faa.Icon = PDFFileAttachmentAnnotationIcon.Tag;
            //PDF4NET v5: faa.Rectangle = new RectangleF(260, 470, 20, 20);
            faa.Location = new PDFPoint(260, 470);
            faa.FileName = "sample.pdf";
            faa.Payload  = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf");
            //PDF4NET v5: page.Canvas.DrawText("Graph", fontText, null, blackBrush, 260, 500, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Graph", fontText, blackBrush, 260, 500);

            // Highlight annotation

            //PDF4NET v5: page.Canvas.DrawText("Markup annotation - this text will be highlighted", fontSection, null, blackBrush, 20, 610);
            page.Canvas.DrawString("Markup annotation - this text will be highlighted", fontSection, blackBrush, 20, 610);
            //PDF4NET v5: PDFHighlightAnnotation ha = new PDFHighlightAnnotation("Markup annotation", "Markup annotation with highlight style");
            PDFTextMarkupAnnotation tma = new PDFTextMarkupAnnotation()
            {
                Author = "Markup annotation", Contents = "Markup annotation with highlight style"
            };

            tma.TextMarkupType = PDFTextMarkupAnnotationType.Highlight;
            page.Annotations.Add(tma);
            //PDF4NET v5: ha.Rectangle = new RectangleF(100, 610, 100, 10);
            tma.DisplayRectangle = new PDFDisplayRectangle(100, 610, 100, 10);
            tma.TextMarkupColor  = new PDFRgbColor(255, 255, 0);

            // Square and circle annotations

            //PDF4NET v5: page.Canvas.DrawText("Square and circle annotations", fontSection, null, blackBrush, 20, 650);
            page.Canvas.DrawString("Square and circle annotations", fontSection, blackBrush, 20, 650);
            //PDF4NET v5: PDFEllipseAnnotation ea = new PDFEllipseAnnotation("Ellipse annotation", "An ellipse annotation");
            PDFCircleAnnotation ca = new PDFCircleAnnotation()
            {
                Author = "Ellipse annotation", Contents = "An ellipse annotation"
            };

            page.Annotations.Add(ca);
            //PDF4NET v5: ea.Rectangle = new RectangleF(20, 670, 150, 75);
            ca.DisplayRectangle = new PDFDisplayRectangle(20, 670, 150, 75);
            //PDF4NET v5: ea.Color = new PDFRgbColor(255, 255, 0);
            ca.BorderColor   = new PDFRgbColor(255, 255, 0);
            ca.InteriorColor = new PDFRgbColor(0, 255, 0);

            //PDF4NET v5: PDFRectangleAnnotation ra = new PDFRectangleAnnotation("Rectangle annotation", "A rectangle annotation");
            PDFSquareAnnotation sa = new PDFSquareAnnotation()
            {
                Author = "Rectangle annotation", Contents = "A rectangle annotation"
            };

            page.Annotations.Add(sa);
            //PDF4NET v5: ra.Rectangle = new RectangleF(200, 670, 150, 75);
            sa.DisplayRectangle = new PDFDisplayRectangle(200, 670, 150, 75);
            //PDF4NET v5: ra.Color = new PDFRgbColor(255, 64, 0);
            sa.BorderColor   = new PDFRgbColor(255, 64, 0);
            sa.InteriorColor = new PDFRgbColor(64, 0, 255);

            // Create 2nd page
            //PDF4NET v5: page = doc.AddPage();
            page = doc.Pages.Add();

            //PDF4NET v5: page.Canvas.DrawText("Annotations with custom appearance", fontSection, null, blackBrush, 20, 45, 0, PDFTextAlign.BottomLeft);
            slo.Y = 45;
            page.Canvas.DrawString("Annotations with custom appearance", sao, slo);

            //PDF4NET v5: page.Canvas.DrawText("a. Annotations with image appearance", fontSection, null, blackBrush, 20, 60, 0, PDFTextAlign.BottomLeft);
            slo.Y = 60;
            page.Canvas.DrawString("a. Annotations with image appearance", sao, slo);

            //PDF4NET v5: PDFRubberStampAnnotation isa = new PDFRubberStampAnnotation("ImageAppearance", "Annotation with image appearance.");
            PDFRubberStampAnnotation isa = new PDFRubberStampAnnotation()
            {
                Author = "ImageAppearance", Contents = "Annotation with image appearance."
            };

            page.Annotations.Add(isa);
            //PDF4NET v5: isa.Rectangle = new RectangleF(20, 70, 200, 100);
            isa.DisplayRectangle = new PDFDisplayRectangle(20, 70, 200, 100);
            //PDF4NET v5: Bitmap img = new Bitmap("..\\SupportFiles\\auto1.jpg");
            //PDF4NET v5: isa.Appearance = new PDFImageAppearance(img);
            //PDF4NET v5: img.Dispose();

            FileStream   imgStream = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\auto1.jpg");
            PDFJpegImage img       = new PDFJpegImage(imgStream);

            imgStream.Dispose();
            PDFAnnotationAppearance ia = new PDFAnnotationAppearance(isa.DisplayRectangle.Width, isa.DisplayRectangle.Height);

            ia.Canvas.DrawImage(img, 0, 0, ia.Width, ia.Height);
            isa.NormalAppearance = ia;

            //PDF4NET v5: page.Canvas.DrawText("Image appearance", fontText, null, blackBrush, 20, 175, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Image appearance", fontText, blackBrush, 20, 175);

            //PDF4NET v5: page.Canvas.DrawText("b. Annotations with owner draw appearance", fontSection, null, blackBrush, 20, 200, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("b. Annotations with owner draw appearance", fontSection, blackBrush, 20, 200);
            //PDF4NET v5: PDFRubberStampAnnotation odsa = new PDFRubberStampAnnotation("OwnerDrawAppearance", "Annotation with owner draw appearance.");
            PDFRubberStampAnnotation odsa = new PDFRubberStampAnnotation()
            {
                Author = "OwnerDrawAppearance", Contents = "Annotation with owner draw appearance."
            };

            page.Annotations.Add(odsa);
            //PDF4NET v5: odsa.Rectangle = new RectangleF(20, 220, 200, 100);
            odsa.DisplayRectangle = new PDFDisplayRectangle(20, 220, 200, 100);
            //PDF4NET v5: odsa.Appearance = new PDFAnnotationAppearance();
            //PDF4NET v5: odsa.Appearance.Width = odsa.Rectangle.Width;
            //PDF4NET v5: odsa.Appearance.Height = odsa.Rectangle.Height;
            odsa.NormalAppearance = new PDFAnnotationAppearance(odsa.DisplayRectangle.Width, odsa.DisplayRectangle.Height);
            PDFBrush redBrush = new PDFBrush(new PDFRgbColor(192, 0, 0));

            //PDF4NET v5: odsa.Appearance.Canvas.DrawRoundRectangle(redBrush, 0, 0, odsa.Rectangle.Width, odsa.Rectangle.Height, 40, 40);
            odsa.NormalAppearance.Canvas.DrawRoundRectangle(redBrush, 0, 0, odsa.DisplayRectangle.Width, odsa.DisplayRectangle.Height, 40, 40);
            PDFBrush blueBrush = new PDFBrush(new PDFRgbColor(0, 0, 128));

            //PDF4NET v5: odsa.Appearance.Canvas.DrawEllipse(blueBrush, (odsa.Rectangle.Width - odsa.Rectangle.Height) / 2, 0, odsa.Rectangle.Height, odsa.Rectangle.Height);
            odsa.NormalAppearance.Canvas.DrawEllipse(blueBrush,
                                                     (odsa.DisplayRectangle.Width - odsa.DisplayRectangle.Height) / 2, 0, odsa.DisplayRectangle.Height, odsa.DisplayRectangle.Height);
            //PDF4NET v5: page.Canvas.DrawText("Owner draw appearance", fontText, null, blackBrush, 20, 325, 0, PDFTextAlign.TopLeft);
            page.Canvas.DrawString("Owner draw appearance", fontText, blackBrush, 20, 325);

            // Save the document to disk
            doc.Save("Sample_Annotations.pdf");
        }
コード例 #25
0
ファイル: Barcodes.cs プロジェクト: sss-software/pdf4net
        private static void DrawEanUpcBarcodes(PDFPage page, PDFFont titleFont, PDFFont barcodeFont)
        {
            PDFBrush brush        = new PDFBrush();
            PDFPen   lightGrayPen = new PDFPen(PDFRgbColor.LightGray, 0.5);

            page.Canvas.DrawString("EAN/UPC barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 7; i++)
            {
                page.Canvas.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i);
            }
            page.Canvas.DrawLine(lightGrayPen, 306, 50, 306, 750);

            string[] barcodes = new string[] { "EAN 128", "EAN-13", "EAN-8", "ISBN", "ISMN", "ISSN", "JAN-13", "UPC-A", "UPC-E" };
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = barcodeFont;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;

            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 100 * (i / 2);

                page.Canvas.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign  = -sign;
            }

            // EAN 128
            PDFEan128Barcode ean128Barcode = new PDFEan128Barcode();

            ean128Barcode.Data                  = "WWW.O2SOL.COM";
            ean128Barcode.QuietZones.Left       = 0;
            ean128Barcode.QuietZones.Right      = 0;
            ean128Barcode.BarcodeTextPosition   = PDFBarcodeTextPosition.Bottom;
            ean128Barcode.ApplicationIdentifier = "URL";
            page.Canvas.DrawBarcode(ean128Barcode, 173 - ean128Barcode.Width / 2, 70);

            // EAN-13
            PDFEan13Barcode ean13Barcode = new PDFEan13Barcode();

            ean13Barcode.Data = "437612735617";
            ean13Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(ean13Barcode, 173 + 266 - ean13Barcode.Width / 2, 70);

            // EAN-8
            PDFEan8Barcode ean8Barcode = new PDFEan8Barcode();

            ean8Barcode.Data = "5423731";
            ean8Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(ean8Barcode, 173 - ean8Barcode.Width / 2, 170);

            // ISBN
            PDFIsbnBarcode isbnBarcode = new PDFIsbnBarcode();

            isbnBarcode.Data = "436314378";
            isbnBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(isbnBarcode, 173 + 266 - isbnBarcode.Width / 2, 170);

            // ISMN
            PDFIsmnBarcode ismnBarcode = new PDFIsmnBarcode();

            ismnBarcode.Data = "437612489";
            ismnBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(ismnBarcode, 173 - ismnBarcode.Width / 2, 270);

            // ISSN
            PDFIssnBarcode issnBarcode = new PDFIssnBarcode();

            issnBarcode.Data = "546712341";
            issnBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(issnBarcode, 173 + 266 - issnBarcode.Width / 2, 270);

            // JAN-13
            PDFJan13Barcode jan13Barcode = new PDFJan13Barcode();

            jan13Barcode.Data = "1256127634";
            jan13Barcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(jan13Barcode, 173 - jan13Barcode.Width / 2, 370);

            // UPC-A
            PDFUpcaBarcode upcaBarcode = new PDFUpcaBarcode();

            upcaBarcode.Data = "12543267841";
            upcaBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(upcaBarcode, 173 + 266 - upcaBarcode.Width / 2, 370);

            // UPC-E
            PDFUpceBarcode upceBarcode = new PDFUpceBarcode();

            upceBarcode.Data = "1234532";
            upceBarcode.BarcodeTextPosition = PDFBarcodeTextPosition.Bottom;
            page.Canvas.DrawBarcode(upceBarcode, 173 - upceBarcode.Width / 2, 470);

            page.Canvas.CompressAndClose();
        }