コード例 #1
0
ファイル: XForm.cs プロジェクト: RefactorForce/PDFSharp
        /// <summary>
        /// Initializes a new instance of the XForm class such that it can be drawn on the specified graphics
        /// object.
        /// </summary>
        /// <param name="gfx">The graphics object that later is used to draw this form.</param>
        /// <param name="size">The size in points of the form.</param>
        public XForm(XGraphics gfx, XSize size)
        {
            if (gfx == null)
            {
                throw new ArgumentNullException("gfx");
            }
            if (size.Width < 1 || size.Height < 1)
            {
                throw new ArgumentNullException("size", "The size of the XPDFForm is to small.");
            }

            _formState = FormState.Created;
            //templateSize = size;
            _viewBox.Width  = size.Width;
            _viewBox.Height = size.Height;

            // If gfx belongs to a PDFPage also create the PDFFormXObject
            if (gfx.PDFPage != null)
            {
                _document = gfx.PDFPage.Owner;
                _pdfForm  = new PDFFormXObject(_document, this);
                PDFRectangle rect = new PDFRectangle(new XPoint(), size);
                _pdfForm.Elements.SetRectangle(PDFFormXObject.Keys.BBox, rect);
            }
        }
コード例 #2
0
ファイル: VectorGraphics.cs プロジェクト: o2solutions/pdf4net
        private static void DrawFormXObjects(PDFPage page, PDFFont titleFont, PDFFont sectionFont)
        {
            PDFBrush brush    = new PDFBrush();
            PDFPen   blackPen = new PDFPen(PDFRgbColor.Black, 1);

            PDFRgbColor randomPenColor   = new PDFRgbColor();
            PDFPen      randomPen        = new PDFPen(randomPenColor, 1);
            PDFRgbColor randomBrushColor = new PDFRgbColor();
            PDFBrush    randomBrush      = new PDFBrush(randomBrushColor);

            page.Canvas.DrawString("Form XObjects", titleFont, brush, 20, 50);
            page.Canvas.DrawString("Scaling", sectionFont, brush, 20, 70);

            // Create the XObject content - random rectangles
            PDFFormXObject xobject = new PDFFormXObject(300, 300);
            Random         rnd     = new Random();

            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                double left        = rnd.NextDouble() * xobject.Width;
                double top         = rnd.NextDouble() * xobject.Height;
                double width       = rnd.NextDouble() * xobject.Width;
                double height      = rnd.NextDouble() * xobject.Height;
                double orientation = rnd.Next(360);
                xobject.Canvas.DrawRectangle(randomPen, randomBrush, left, top, width, height, orientation);
            }

            xobject.Canvas.DrawRectangle(blackPen, 0, 0, xobject.Width, xobject.Height);
            xobject.Canvas.CompressAndClose();

            // Draw the form XObject 3 times on the page at different sizes.
            page.Canvas.DrawFormXObject(xobject, 3, 90, 100, 100);
            page.Canvas.DrawFormXObject(xobject, 106, 90, 200, 200);
            page.Canvas.DrawFormXObject(xobject, 309, 90, 300, 300);

            page.Canvas.DrawString("Flipping", sectionFont, brush, 20, 420);
            page.Canvas.DrawFormXObject(xobject, 20, 440, 150, 150);
            page.Canvas.DrawFormXObject(xobject, 200, 440, 150, 150, 0, PDFFlipDirection.VerticalFlip);
            page.Canvas.DrawFormXObject(xobject, 20, 620, 150, 150, 0, PDFFlipDirection.HorizontalFlip);
            page.Canvas.DrawFormXObject(xobject, 200, 620, 150, 150, 0, PDFFlipDirection.VerticalFlip | PDFFlipDirection.HorizontalFlip);

            page.Canvas.CompressAndClose();
        }
コード例 #3
0
ファイル: XForm.cs プロジェクト: RefactorForce/PDFSharp
        /// <summary>
        /// Initializes a new instance of the <see cref="XForm"/> class that represents a page of a PDF document.
        /// </summary>
        /// <param name="document">The PDF document.</param>
        /// <param name="viewBox">The view box of the page.</param>
        public XForm(PDFDocument document, XRect viewBox)
        {
            if (viewBox.Width < 1 || viewBox.Height < 1)
            {
                throw new ArgumentNullException("viewBox", "The size of the XPDFForm is to small.");
            }
            _formState = FormState.Created;
            Owner      = document ?? throw new ArgumentNullException("document", "An XPDFForm template must be associated with a document at creation time.");
            _pdfForm   = new PDFFormXObject(document, this);
            //_templateSize = size;
            ViewBox = viewBox;
            PDFRectangle rect = new PDFRectangle(viewBox);

            _pdfForm.Elements.SetRectangle(PDFFormXObject.Keys.BBox, rect);
        }
コード例 #4
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);
        }