示例#1
0
        /// <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();
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        private static void DrawWatermarkOverPageContent(PDFPage page)
        {
            PDFBrush        redBrush  = new PDFBrush(new PDFRgbColor(192, 0, 0));
            PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 32);

            // The page canvas is located by default on top of existing page content.
            //page.SetCanvasPosition(PDFPageCanvasPosition.OverExistingPageContent);

            // Draw the watermark over page content.
            // Page content under the watermark will be masked.
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 335);

            page.Canvas.SaveGraphicsState();

            // Draw the watermark over page content but using the Multiply blend mode.
            // The watermak will appear as if drawn under the page content, useful when watermarking scanned documents.
            // If the watermark is drawn under page content for scanned documents, it will not be visible because the scanned image will block it.
            PDFExtendedGraphicState gs1 = new PDFExtendedGraphicState();

            gs1.BlendMode = PDFBlendMode.Multiply;
            page.Canvas.SetExtendedGraphicState(gs1);
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 385);

            // Draw the watermark over page content but using the Luminosity blend mode.
            // Both the page content and the watermark will be visible.
            PDFExtendedGraphicState gs2 = new PDFExtendedGraphicState();

            gs2.BlendMode = PDFBlendMode.Luminosity;
            page.Canvas.SetExtendedGraphicState(gs2);
            page.Canvas.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 435);

            page.Canvas.RestoreGraphicsState();
        }
示例#3
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);
        }