private void drawArea()
 {
     _template.SetColorStroke(BorderColor);
     _template.SetColorFill(BackgroundColor);
     _template.Rectangle(0, 0, _template.Width, _template.Height);
     _template.FillStroke();
 }
Пример #2
0
        private void ShowText(PdfContentByte cb, float x, float y, float xPrevious, float yPrevious, double xmidden, double ymidden, String character)
        {
            double corner = CalculateCorner(x, y, xPrevious, yPrevious);

            cb.SaveState();
            PdfTemplate template2 = cb.CreateTemplate(1000, 1000);

            template2.BeginText();
            template2.SetColorFill(BaseColor.BLACK);
            BaseFont bf = BaseFont.CreateFont();

            template2.SetFontAndSize(bf, fontsize);
            //template2.SetTextRise(10);
            //double halfWidthOfCharacter = cb.GetEffectiveStringWidth(character+"", true) / 2.0;
            template2.SetTextMatrix(0, 0);
            template2.ShowText(character + "");
            template2.EndText();
            Matrix translation = new Matrix();

            translation.Translate((float)xmidden, (float)ymidden);
            cb.ConcatCTM(translation);
            Matrix rotation = new Matrix();

            rotation.Rotate((float)corner);
            cb.ConcatCTM(rotation);
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);
            cb.AddTemplate(template2, 0, 0);
            cb.RestoreState();
        }
Пример #3
0
        static private PdfTemplate CreateBarcodeTemplate(PdfContentByte over, Barcode barcode, bool opaque, bool withBorder)
        {
            PdfTemplate template   = over.CreateTemplate(0, 0);
            float       borderSize = opaque && withBorder ? barcode.X * 3 : 0; // 3 ширины полоски

            if (opaque)
            {
                // Создадим п/у залитый белым цветом
                template.SetColorFill(BaseColor.WHITE);
                template.Rectangle(-borderSize, -borderSize, barcode.BarcodeSize.Width + borderSize * 2, barcode.BarcodeSize.Height + borderSize * 2);
                template.Fill();
            }

            iTextSharp.text.Rectangle boundingBox = barcode.PlaceBarcode(template, BaseColor.BLACK, BaseColor.BLACK);
            if (borderSize != 0.0)
            {
                boundingBox.Right += borderSize;
                boundingBox.Left  -= borderSize;
                boundingBox.Top   += borderSize;
                if (barcode.Font != null)
                {
                    // Если текст отображается, то не нужно расширять, потому что там и так место под текстом есть.
                    boundingBox.Bottom -= borderSize;
                }
            }
            // Обрежем шаблон до размера barCode + граница
            template.BoundingBox = boundingBox;
            return(template);
        }
Пример #4
0
 public sealed override void OnCloseDocument(PdfWriter writer, Document document)
 {
     base.OnCloseDocument(writer, document);
     template.BeginText();
     template.SetFontAndSize(font.BaseFont, font.Size);
     template.SetColorFill(font.Color);
     template.SetTextMatrix(0, 0);
     template.ShowText((writer.PageNumber).ToString());
     template.EndText();
 }
Пример #5
0
        public static Image CreateRectangle(PdfWriter writer, float x, float y, float width, float height, BaseColor backColor)
        {
            PdfTemplate template = writer.DirectContent.CreateTemplate(width, height);

            template.SetColorFill(backColor);
            template.Rectangle(x, y, width, height);
            template.Fill();
            writer.ReleaseTemplate(template);

            return(Image.GetInstance(template));
        }
Пример #6
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            headerTemplate.BeginText();
            headerTemplate.SetColorFill(BaseColor.RED);

            headerTemplate.SetFontAndSize(bf, 12);
            headerTemplate.SetTextMatrix(0, 0);
            headerTemplate.ShowText((writer.PageNumber - 1).ToString());
            headerTemplate.EndText();

            footerTemplate.BeginText();
            footerTemplate.SetFontAndSize(bf, 12);
            footerTemplate.SetTextMatrix(0, 0);
            footerTemplate.ShowText((writer.PageNumber - 1).ToString());
            footerTemplate.EndText();
        }
Пример #7
0
        public PdfTemplate AddPageFooter(int PageNumber)
        {
            PdfTemplate footerTemplate = cb.CreateTemplate(500, 55);

            footerTemplate.BeginText();
            BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

            footerTemplate.SetFontAndSize(bf2, 11);
            footerTemplate.SetColorStroke(BaseColor.DARK_GRAY);
            footerTemplate.SetColorFill(BaseColor.GRAY);
            int al = -200;

            footerTemplate.SetLineWidth(3);
            footerTemplate.LineTo(500, footerTemplate.YTLM);
            string texttoadd   = "Page: " + PageNumber.ToString();
            float  widthoftext = 500.0f - bf2.GetWidthPoint(texttoadd, 11);

            footerTemplate.ShowTextAligned(al, texttoadd, widthoftext, 30, 0);
            footerTemplate.EndText();
            return(footerTemplate);
        }
Пример #8
0
        public void Sign(String src, String name, String dest, ICollection <X509Certificate> chain, ICipherParameters pk,
                         String digestAlgorithm, CryptoStandard subfilter, String reason, String location)
        {
            // Creating the reader and the stamper
            PdfReader  reader  = new PdfReader(src);
            FileStream os      = new FileStream(dest, FileMode.Create);
            PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0');
            // Creating the appearance
            PdfSignatureAppearance appearance = stamper.SignatureAppearance;

            appearance.Reason   = reason;
            appearance.Location = location;
            appearance.SetVisibleSignature(name);
            // Creating the appearance for layer 0
            PdfTemplate n0     = appearance.GetLayer(0);
            float       x      = n0.BoundingBox.Left;
            float       y      = n0.BoundingBox.Bottom;
            float       width  = n0.BoundingBox.Width;
            float       height = n0.BoundingBox.Height;

            n0.SetColorFill(BaseColor.LIGHT_GRAY);
            n0.Rectangle(x, y, width, height);
            n0.Fill();
            // Creating the appearance for layer 2
            PdfTemplate n2 = appearance.GetLayer(2);
            ColumnText  ct = new ColumnText(n2);

            ct.SetSimpleColumn(n2.BoundingBox);
            Paragraph p = new Paragraph("This document was signed by Bruno Specimen.");

            ct.AddElement(p);
            ct.Go();
            // Creating the signature
            IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm);

            MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, subfilter);
        }
Пример #9
0
        public PdfTemplate AddAddressFooter()
        {
            PdfTemplate footerTemplate = cb.CreateTemplate(500, (FooterLines.Count * 45 + 10));

            footerTemplate.BeginText();
            BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

            footerTemplate.SetFontAndSize(bf2, 11);
            footerTemplate.SetColorStroke(BaseColor.DARK_GRAY);
            footerTemplate.SetColorFill(BaseColor.GRAY);
            int al = -200;
            int p  = 0; // current line
            int v;      // vertical positioning

            foreach (string FooterLine in FooterLines)
            {
                v = 45 - (15 * p);
                float widthoftext = 500.0f - bf2.GetWidthPoint(FooterLine, 11);
                footerTemplate.ShowTextAligned(al, FooterLine, widthoftext, v, 0);
                p++;
            }
            footerTemplate.EndText();
            return(footerTemplate);
        }
Пример #10
0
        public Chap1013()
        {
            Console.WriteLine("Chapter 10 Example 13: Spot Color");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1013.pdf", FileMode.Create));
                BaseFont  bf     = BaseFont.CreateFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED);

                // step 3: we open the document
                document.Open();

                // step 4: we add some content
                PdfContentByte cb = writer.DirectContent;

                // Note: I made up these names unless someone give me a PANTONE swatch as gift ([email protected])
                PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f));
                PdfSpotColor spc_rgb  = new PdfSpotColor("PANTONE 147", 0.9f, new Color(114, 94, 38));
                PdfSpotColor spc_g    = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f));

                // Stroke a rectangle with CMYK alternate
                cb.SetColorStroke(spc_cmyk, .5f);
                cb.SetLineWidth(10f);
                // draw a rectangle
                cb.Rectangle(100, 700, 100, 100);
                // add the diagonal
                cb.MoveTo(100, 700);
                cb.LineTo(200, 800);
                // stroke the lines
                cb.Stroke();

                // Fill a rectangle with CMYK alternate
                cb.SetColorFill(spc_cmyk, spc_cmyk.Tint);
                cb.Rectangle(250, 700, 100, 100);
                cb.Fill();

                // Stroke a circle with RGB alternate
                cb.SetColorStroke(spc_rgb, spc_rgb.Tint);
                cb.SetLineWidth(5f);
                cb.Circle(150f, 500f, 100f);
                cb.Stroke();

                // Fill the circle with RGB alternate
                cb.SetColorFill(spc_rgb, spc_rgb.Tint);
                cb.Circle(150f, 500f, 50f);
                cb.Fill();

                // example with colorfill
                cb.SetColorFill(spc_g, spc_g.Tint);
                cb.MoveTo(100f, 200f);
                cb.LineTo(200f, 250f);
                cb.LineTo(400f, 150f);
                cb.Fill();
                document.NewPage();
                String text = "Some text to show";
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f))));

                // example with template
                PdfTemplate t = cb.CreateTemplate(500f, 500f);
                // Stroke a rectangle with CMYK alternate
                t.SetColorStroke(new SpotColor(spc_cmyk, .5f));
                t.SetLineWidth(10f);
                // draw a rectangle
                t.Rectangle(100, 10, 100, 100);
                // add the diagonal
                t.MoveTo(100, 10);
                t.LineTo(200, 100);
                // stroke the lines
                t.Stroke();

                // Fill a rectangle with CMYK alternate
                t.SetColorFill(spc_g, spc_g.Tint);
                t.Rectangle(100, 125, 100, 100);
                t.Fill();
                t.BeginText();
                t.SetFontAndSize(bf, 20f);
                t.SetTextMatrix(1f, 0f, 0f, 1f, 10f, 10f);
                t.ShowText("Template text upside down");
                t.EndText();
                t.Rectangle(0, 0, 499, 499);
                t.Stroke();
                cb.AddTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f);
            }
            catch (Exception de)
            {
                Console.Error.WriteLine(de.Message);
                Console.Error.WriteLine(de.StackTrace);
            }

            // step 5: we close the document
            document.Close();
        }