Example #1
0
        private void TransformImage(PdfPageBase page)
        {
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            int skewX = 20;
            int skewY = 20;
            float scaleX = 0.2f;
            float scaleY = 0.6f;
            int width = (int)((image.Width + image.Height * Math.Tan(Math.PI * skewX/ 180)) * scaleX);
            int height = (int)((image.Height + image.Width * Math.Tan(Math.PI * skewY/ 180)) * scaleY);
            PdfTemplate template = new PdfTemplate(width, height);
            template.Graphics.ScaleTransform(scaleX, scaleY);
            template.Graphics.SkewTransform(skewX, skewY);
            template.Graphics.DrawImage(image, 0, 0);

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();
            page.Canvas.TranslateTransform(page.Canvas.ClientSize.Width - 50, 260);
            float offset = (page.Canvas.ClientSize.Width - 100) / 12;
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.TranslateTransform(-offset, 0);
                page.Canvas.SetTransparency(i / 12.0f);
                page.Canvas.DrawTemplate(template, new PointF(0, 0));
            }

            //restor graphics
            page.Canvas.Restore(state);
        }
Example #2
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         bf       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb       = writer.DirectContent;
         template = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
     }
     catch (IOException ioe)
     {
     }
 }
 public override void OnOpenDocument(PdfWriter writer, iTextSharp.text.Document document)
 {
     try
     {
         footerBaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         contentByte    = writer.DirectContent;
         template       = contentByte.CreateTemplate(50, 50);
     }
     catch (DocumentException)
     {
     }
     catch (IOException)
     {
     }
 }
Example #4
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime = DateTime.Now;
         helv      = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
         cb        = writer.DirectContent;
         cbLocal   = writer.DirectContent;
         total     = total = writer.DirectContent.CreateTemplate(100, 100);
     }
     catch (DocumentException de)
     {
         Console.Write(de);
     }
 }
Example #5
0
    //public pdfEvents()
    //{
    //    //
    //    // TODO: Add constructor logic here
    //    //
    //}
    #endregion

    public override void OnOpenDocument(PdfWriter writer, Document document)
    {
        try
        {
            bf       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb       = writer.DirectContent;
            template = cb.CreateTemplate(100, 100);
        }
        catch //(DocumentException de)
        {
        }
        //catch //(System.IO.IOException ioe)
        //{

        //}
    }
Example #6
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try {
         baseFont       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         pdfContentByte = writer.DirectContent;
         pdfTemplate    = pdfContentByte.CreateTemplate(50, 50);
     } catch (DocumentException documentException) {
         Log    log     = new Log(LogFileType.TXT, LogType.EXCEPTION);
         string logData = DateTime.Now.ToString() + "\t\t documentException \t\t" + documentException.Message;
         log.write(logData);
     } catch (System.IO.IOException ioException) {
         Log    log     = new Log(LogFileType.TXT, LogType.EXCEPTION);
         string logData = DateTime.Now.ToString() + "\t\t documentException \t\t" + ioException.Message;
         log.write(logData);
     }
 }
Example #7
0
        public void AddTemplateResourceToCurrentPage(string resourceFileName)
        {
            if (CurrentPage == null)
            {
                return;
            }
            //doc: https://help.syncfusion.com/file-formats/pdf/working-with-pdf-templates

            byte[] file = resourceFileName.LoadAppResourceFromFile();

            var         loadedDocument = new PdfLoadedDocument(file);
            var         loadedPage     = loadedDocument.Pages[0] as PdfLoadedPage;
            PdfTemplate template       = loadedPage.CreateTemplate();

            CurrentPageGraphics.DrawPdfTemplate(template, PointF.Empty, new SizeF(CurrentPage.Size.Width, CurrentPage.Size.Height));
        }
Example #8
0
 /// <summary>
 /// Creats an Image from a PdfTemplate.
 /// </summary>
 /// <param name="template">the PdfTemplate</param>
 public ImgTemplate(PdfTemplate template)
     : base((Uri)null)
 {
     if (template == null)
         throw new BadElementException("The template can not be null.");
     if (template.Type == PdfTemplate.TYPE_PATTERN)
         throw new BadElementException("A pattern can not be used as a template to create an image.");
     type = Element.IMGTEMPLATE;
     scaledHeight = template.Height;
     this.Top = scaledHeight;
     scaledWidth = template.Width;
     this.Right = scaledWidth;
     TemplateData = template;
     plainWidth = this.Width;
     plainHeight = this.Height;
 }
Example #9
0
        // Escribimos el header al inicio de cada página
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            Image headerImage = ImageReport.GetHeader("Header/drawable-hdpi/Header");

            //headerImage.SetAbsolutePosition(-280, 700);
            headerImage.SetAbsolutePosition(-230, 0);

            PdfContentByte cbhead = writer.DirectContent;
            PdfTemplate    tp     = cbhead.CreateTemplate(500, 500);

            tp.AddImage(headerImage);
            cbhead.AddTemplate(tp, -20, 700);

            //base.OnStartPage(writer, document);
            header.WriteSelectedRows(0, -1, 5, 780, writer.DirectContent);
        }
Example #10
0
// ===========================================================================
        public override void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document(PageSize.A4)) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                Rectangle art    = new Rectangle(50, 50, 545, 792);
                writer.SetBoxSize("art", art);
                // step 3
                document.Open();
                // step 4
                PdfContentByte content  = writer.DirectContent;
                PdfTemplate    template = CreateTemplate(content, PageSize.A4, 1);
                content.AddTemplate(template, 0, 0);
            }
        }
        private void InsertCharacteristics(PdfStamper Stamper, string str, int X, int Y)
        {
            iTextSharp.text.pdf.PdfContentByte underContent;
            underContent = Stamper.GetOverContent(1);

            PdfTemplate template = underContent.CreateTemplate(500, 300);

            template.BeginText();
            BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            template.SetFontAndSize(bf, 9);
            template.SetTextMatrix(100, 100);
            template.ShowText(str);
            template.EndText();
            underContent.AddTemplate(template, X, Y);
        }
Example #12
0
 /// <summary>
 /// override the onOpenDocument method
 /// </summary>
 /// <param name="writer">PdfWriter</param>
 /// <param name="document">Document</param>
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime = DateTime.Now;
         bf        = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb        = writer.DirectContent;
         template  = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException)
     {
     }
     catch (System.IO.IOException)
     {
     }
 }
        public ActionResult OverlayDocuments(string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            string dataPath1 = dataPath + "BorderTemplate.pdf";
            string dataPath2 = dataPath + "SourceTemplate.pdf";

            Stream            stream1 = new FileStream(dataPath2, FileMode.Open, FileAccess.Read);
            FileStream        file    = new FileStream(dataPath1, FileMode.Open, FileAccess.Read, FileShare.Read);
            PdfLoadedDocument ldDoc1  = new PdfLoadedDocument(file);
            PdfLoadedDocument ldDoc2  = new PdfLoadedDocument(stream1);
            PdfDocument       doc     = new PdfDocument();

            for (int i = 0, count = ldDoc2.Pages.Count; i < count; ++i)
            {
                PdfPage     page = doc.Pages.Add();
                PdfGraphics g    = page.Graphics;

                PdfPageBase lpage    = ldDoc2.Pages[i];
                PdfTemplate template = lpage.CreateTemplate();

                g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());

                lpage    = ldDoc1.Pages[0];
                template = lpage.CreateTemplate();

                g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());
            }
            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            doc.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "Overlay.pdf";
            return(fileStreamResult);
        }
        public void ImageTaggingExpansionTest()
        {
            String    filename = "TextExpansionTest.pdf";
            Document  doc      = new Document(PageSize.LETTER, 72, 72, 72, 72);
            PdfWriter writer   = PdfWriter.GetInstance(doc, new FileStream(DEST_FOLDER + filename, FileMode.Create));

            writer.SetTagged();
            doc.Open();

            Chunk c1 = new Chunk("ABC");

            c1.SetTextExpansion("the alphabet");
            Paragraph p1 = new Paragraph();

            p1.Add(c1);
            doc.Add(p1);

            PdfTemplate t = writer.DirectContent.CreateTemplate(6, 6);

            t.SetLineWidth(1f);
            t.Circle(3f, 3f, 1.5f);
            t.SetGrayFill(0);
            t.FillStroke();
            Image i  = Image.GetInstance(t);
            Chunk c2 = new Chunk(i, 100, -100);

            doc.Add(c2);

            Chunk c3 = new Chunk("foobar");

            c3.SetTextExpansion("bar bar bar");
            Paragraph p3 = new Paragraph();

            p3.Add(c3);
            doc.Add(p3);

            doc.Close();


            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.CompareByContent(DEST_FOLDER + filename, SOURCE_FOLDER + "cmp_" + filename, DEST_FOLDER, "diff_");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }
        private void InsertCharacteristics(PdfStamper Stamper, int totalpages, string totalstr, int X, int Y, int Z, int W, int D_x, int D_y, int R_x, int R_y)
        {
            iTextSharp.text.pdf.PdfContentByte underContent;
            for (int i = 1; i <= totalpages; i++)
            {
                underContent = Stamper.GetOverContent(i);
                PdfTemplate template = underContent.CreateTemplate(500, 300);
                template.BeginText();
                BaseFont bf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                template.SetFontAndSize(bf, 9);
                template.SetTextMatrix(100, 100);
                template.ShowText(totalstr);
                template.EndText();
                underContent.AddTemplate(template, X, Y);

                string      NoStr       = "第" + i + "页";
                PdfTemplate newtemplate = underContent.CreateTemplate(500, 300);
                newtemplate.BeginText();
                BaseFont newbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                newtemplate.SetFontAndSize(newbf, 9);
                newtemplate.SetTextMatrix(100, 100);
                newtemplate.ShowText(NoStr);
                newtemplate.EndText();
                underContent.AddTemplate(newtemplate, Z, W);


                string      DrawingStr      = "图号: " + drawing;
                PdfTemplate drawingtemplate = underContent.CreateTemplate(500, 300);
                drawingtemplate.BeginText();
                BaseFont drawingbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                drawingtemplate.SetFontAndSize(drawingbf, 12);
                drawingtemplate.SetTextMatrix(100, 100);
                drawingtemplate.ShowText(DrawingStr);
                drawingtemplate.EndText();
                underContent.AddTemplate(drawingtemplate, D_x, D_y);

                string      RevStr      = "REV." + version.ToString();
                PdfTemplate revtemplate = underContent.CreateTemplate(500, 300);
                revtemplate.BeginText();
                BaseFont revbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                revtemplate.SetFontAndSize(revbf, 9);
                revtemplate.SetTextMatrix(100, 100);
                revtemplate.ShowText(RevStr);
                revtemplate.EndText();
                underContent.AddTemplate(revtemplate, R_x, R_y);
            }
        }
Example #16
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         _printTime      = DateTime.Now;
         _baseFont       = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         _cb             = writer.DirectContent;
         _headerTemplate = _cb.CreateTemplate(100, 100);
         _footerTemplate = _cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
     }
     catch (IOException ioe)
     {
     }
 }
Example #17
0
        // we override the onOpenDocument method
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            string error;

            try {
                PrintTime = DateTime.Now;
                baseFont  = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb        = writer.DirectContent;
                template  = cb.CreateTemplate(50, 50);
            }
            catch (DocumentException de) {
                error = de.Message;
            }
            catch (System.IO.IOException ioe) {
                error = ioe.Message;
            }
        }
Example #18
0
 internal PdfGraphics(string filename, int width, int height)
 {
     originalWidth  = currentWidth = width;
     originalHeight = currentHeight = height;
     document       = new Document(new iTextSharp.text.Rectangle(width, height), 50, 50, 50, 50);
     document.AddAuthor("");
     document.AddSubject("");
     try{
         writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
         document.Open();
         content  = writer.DirectContent;
         template = topTemplate = content.CreateTemplate(width, height);
         content.AddTemplate(template, 0, 0);
     } catch (DocumentException de) {
         throw new IOException(de.Message);
     }
 }
Example #19
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime      = DateTime.Now;
         DateFormated   = PrintTime.ToString("dd/MM/yyyy");
         bf             = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb             = writer.DirectContent;
         headerTemplate = cb.CreateTemplate(100, 100);
     }
     catch (DocumentException de)
     {
     }
     catch (System.IO.IOException ioe)
     {
     }
 }
Example #20
0
 public override void OnOpenDocument(PdfWriter writer, Document doc)
 {
     try
     {
         footerBaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         contentByte    = writer.DirectContent;
         template       = contentByte.CreateTemplate(50, 50);
     }
     catch (DocumentException dex)
     {
         FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Check deposit slip printing" + dex.Message);
     }
     catch (IOException ioe)
     {
         FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Check deposit slip printing" + ioe.Message);
     }
 }
Example #21
0
        public Image CreateBarcode(PdfContentByte cb, String text, float mh, float mw, int segmentId)
        {
            BarcodePDF417 pf = new BarcodePDF417();

            // MacroPDF417 setup
            pf.Options           = BarcodePDF417.PDF417_USE_MACRO;
            pf.MacroFileId       = "12";
            pf.MacroSegmentCount = 2;
            pf.MacroSegmentId    = segmentId;

            pf.SetText(text);
            Rectangle   size     = pf.GetBarcodeSize();
            PdfTemplate template = cb.CreateTemplate(mw * size.Width, mh * size.Height);

            pf.PlaceBarcode(template, BaseColor.BLACK, mh, mw);
            return(Image.GetInstance(template));
        }
Example #22
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime      = DateTime.Now;
         bf             = BaseFont.CreateFont(HttpContext.Current.Server.MapPath("fonts/THSarabunNew.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
         cb             = writer.DirectContent;
         headerTemplate = cb.CreateTemplate(document.PageSize.Width, document.PageSize.Height);
         footerTemplate = cb.CreateTemplate(document.PageSize.Width, document.PageSize.Height);
     }
     catch (DocumentException de)
     {
     }
     catch (System.IO.IOException ioe)
     {
     }
 }
Example #23
0
 public PdfGraphics(Stream stream, int width, int height)
 {
     originalWidth  = currentWidth = width;
     originalHeight = currentHeight = height;
     document       = new Document(new Rectangle(width, height), 50, 50, 50, 50);
     document.AddAuthor("");
     document.AddSubject("");
     try {
         writer = PdfWriter.GetInstance(document, stream);
         document.Open();
         PdfContentByte content = writer.DirectContent;
         template = topTemplate = content.CreateTemplate(width, height);
         content.AddTemplate(template, 0, -20);
     } catch (DocumentException de) {
         throw new IOException(de.Message);
     }
 }
        private void btnImport_Click(object sender, System.EventArgs e)
        {
            PdfLoadedDocument ldDoc1 = new PdfLoadedDocument(txtTemplate1.Tag.ToString());
            PdfLoadedDocument ldDoc2 = new PdfLoadedDocument(txtTemplate2.Tag.ToString());
            PdfDocument       doc    = new PdfDocument();

            for (int i = 0, count = ldDoc2.Pages.Count; i < count; ++i)
            {
                PdfPage     page = doc.Pages.Add();
                PdfGraphics g    = page.Graphics;

                PdfPageBase lpage    = ldDoc2.Pages[i];
                PdfTemplate template = lpage.CreateTemplate();
                if ((template.Width < page.GetClientSize().Width) || (template.Height < page.GetClientSize().Height))
                {
                    g.DrawPdfTemplate(template, new PointF((page.GetClientSize().Width - template.Width) / 2, (page.GetClientSize().Height - template.Height) / 2));
                }

                else
                {
                    g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());
                }

                lpage    = ldDoc1.Pages[0];
                template = lpage.CreateTemplate();

                g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());
            }

            doc.Save("sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                System.Diagnostics.Process.Start("Sample.pdf");
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
Example #25
0
// ---------------------------------------------------------------------------    
    /**
     * Creates a template based on a stream of PDF syntax.
     * @param content The direct content
     * @param rect The dimension of the templare
     * @param factor A magnification factor
     * @return A PdfTemplate
     */
    public virtual PdfTemplate CreateTemplate(
      PdfContentByte content, Rectangle rect, int factor)
    {
      PdfTemplate template = content.CreateTemplate(rect.Width, rect.Height);
      template.ConcatCTM(factor, 0, 0, factor, 0, 0);
      string hero = Path.Combine(Utility.ResourceText, "hero.txt");
      if (!File.Exists(hero)) {
        throw new ArgumentException(hero + " NOT FOUND!");  
      }    
      var fi = new FileInfo(hero);
      using ( var sr = fi.OpenText() ) {
        while (sr.Peek() >= 0) {
          template.SetLiteral((char) sr.Read());
        }
      }
      return template;
    }    
Example #26
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            // step 1
            Rectangle rect = new Rectangle(-595, -842, 595, 842);

            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document(rect)) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    PdfContentByte canvas = writer.DirectContent;
                    canvas.MoveTo(-595, 0);
                    canvas.LineTo(595, 0);
                    canvas.MoveTo(0, -842);
                    canvas.LineTo(0, 842);
                    canvas.Stroke();
                    // Read the PDF containing the logo
                    PdfReader   reader   = new PdfReader(RESOURCE);
                    PdfTemplate template = writer.GetImportedPage(reader, 1);
                    // add it at different positions using different transformations
                    canvas.SaveState();
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(0.5f, 0, 0, 0.5f, -595, 0);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(1, 0, 0, 1, 595, 595);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();

                    canvas.SaveState();
                    canvas.ConcatCTM(1, 0, 0.4f, 1, -750, -650);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();

                    canvas.SaveState();
                    canvas.ConcatCTM(0, -1, -1, 0, 650, 0);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.ConcatCTM(0.2f, 0, 0, 0.5f, 0, 300);
                    canvas.AddTemplate(template, 0, 0);
                    canvas.RestoreState();
                }
                return(ms.ToArray());
            }
        }
Example #27
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         bf             = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb             = writer.DirectContent;
         headerTemplate = cb.CreateTemplate(100, 100);
         footerTemplate = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
         //handle exception here
     }
     catch (System.IO.IOException ioe)
     {
         //handle exception here
     }
 }
Example #28
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         printDateTime  = DateTime.Now;
         bf             = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb             = writer.DirectContent;
         headerTemplate = cb.CreateTemplate(0f, 0f);
         headerTemplate.SetHorizontalScaling(3f);
         footerTemplate = cb.CreateTemplate(40, 40);
     }
     catch (DocumentException de)
     {
     }
     catch (System.IO.IOException ioe)
     {
     }
 }
Example #29
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     base.OnOpenDocument(writer, document);
     try
     {
         bf       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb       = writer.DirectContent;
         template = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException e)
     {
         Console.WriteLine("error: " + e);
     }
     catch (System.IO.IOException e)
     {
         Console.WriteLine("error: " + e);
     }
 }
Example #30
0
 /// <summary>
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="document"></param>
 /// Called when the document is opened.
 /// @param writer the <CODE>PdfWriter</CODE> for this document
 /// @param document the document
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime = DateTime.Now;
         bf        = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb        = writer.DirectContent;
         cb.MoveTo(40, document.PageSize.Height - 110);
         headerTemplate = cb.CreateTemplate(100, 100);
         footerTemplate = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
     }
     catch (System.IO.IOException ioe)
     {
     }
 }
Example #31
0
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            try
            {
                PrintTime = DateTime.Now;
                bf        = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb        = writer.DirectContent;
                if (document.PageNumber == 1)
                {
                    headerTemplate = cb.CreateTemplate(100, 100);
                }

                footerTemplate = cb.CreateTemplate(50, 50);
            }
            catch (Exception e)
            {
            }
        }
Example #32
0
        public static byte[] getPdf(string html, string css)
        {
            byte[] array;
            Image  instance = Image.GetInstance(HttpContext.Current.Server.MapPath("~/images/logobav_edocta.jpg"));

            instance.SetAbsolutePosition(0f, 0f);
            instance.ScalePercent(72f);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (Document document = new Document(PageSize.LETTER))
                {
                    using (PdfWriter pdfWriter = PdfWriter.GetInstance(document, memoryStream))
                    {
                        document.Open();
                        try
                        {
                            try
                            {
                                using (MemoryStream memoryStream1 = new MemoryStream(Encoding.UTF8.GetBytes(css)))
                                {
                                    using (MemoryStream memoryStream2 = new MemoryStream(Encoding.UTF8.GetBytes(html)))
                                    {
                                        XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, document, memoryStream2, memoryStream1);
                                        PdfContentByte directContent = pdfWriter.DirectContent;
                                        PdfTemplate    pdfTemplate   = directContent.CreateTemplate(644f, 52f);
                                        pdfTemplate.AddImage(instance);
                                        directContent.AddTemplate(pdfTemplate, 0f, 747f);
                                    }
                                }
                            }
                            catch (Exception exception)
                            {
                            }
                        }
                        finally
                        {
                            document.Close();
                        }
                    }
                }
                array = memoryStream.ToArray();
            }
            return(array);
        }
Example #33
0
 /**
  * Constructs a <CODE>PdfFormXObject</CODE>-object.
  *
  * @param        template        the template
  * @param   compressionLevel    the compression level for the stream
  * @since   2.1.3 (Replacing the existing constructor with param compressionLevel)
  */
 internal PdfFormXObject(PdfTemplate template, int compressionLevel)
     : base()
 {
     Put(PdfName.TYPE, PdfName.XOBJECT);
     Put(PdfName.SUBTYPE, PdfName.FORM);
     Put(PdfName.RESOURCES, template.Resources);
     Put(PdfName.BBOX, new PdfRectangle(template.BoundingBox));
     Put(PdfName.FORMTYPE, ONE);
     PdfArray matrix = template.Matrix;
     if (template.Layer != null)
         Put(PdfName.OC, template.Layer.Ref);
     if (template.Group != null)
         Put(PdfName.GROUP, template.Group);
     if (matrix == null)
         Put(PdfName.MATRIX, MATRIX);
     else
         Put(PdfName.MATRIX, matrix);
     bytes = template.ToPdf(null);
     Put(PdfName.LENGTH, new PdfNumber(bytes.Length));
     FlateCompress(compressionLevel);
 }
Example #34
0
        private void DrawCover(PdfSection section, PdfMargins margin)
        {
            section.PageNumber = new PdfPageNumber();
            section.PageNumber.NumberStyle = PdfNumberStyle.LowerRoman;
            section.PageNumber.Prefix = "cover ";
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins.All = 0;
            PdfPageBase page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, true);

            //refenrence content
            PdfBrush brush1 = PdfBrushes.LightGray;
            PdfBrush brush2 = PdfBrushes.Blue;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f));
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            String text1 = "(All text and picture from ";
            String text2 = "Wikipedia";
            String text3 = ", the free encyclopedia)";
            float x = 0, y = 10;
            x = x + margin.Left;
            y = y + margin.Top;
            page.Canvas.DrawString(text1, font1, brush1, x, y, format);
            x = x + font1.MeasureString(text1, format).Width;
            page.Canvas.DrawString(text2, font1, brush2, x, y, format);
            x = x + font1.MeasureString(text2, format).Width;
            page.Canvas.DrawString(text3, font1, brush1, x, y, format);

            //cover
            PdfBrush brush3 = PdfBrushes.Black;
            PdfBrush brush4 = new PdfSolidBrush(new PdfRGBColor(0xf9, 0xf9, 0xf9));
            PdfImage image
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            String text = Pagination.Properties.Resources.ImageDescription;
            float r = image.PhysicalDimension.Height / image.Height;
            PdfPen pen = new PdfPen(brush1, r);
            SizeF size = font1.MeasureString(text, image.PhysicalDimension.Width - 2);
            PdfTemplate template
                = new PdfTemplate(image.PhysicalDimension.Width + 4 * r + 4,
                    image.PhysicalDimension.Height + 4 * r + 7 + size.Height);
            template.Graphics.DrawRectangle(pen, brush4, 0, 0, template.Width, template.Height);
            x = y = r + 2;
            template.Graphics.DrawRectangle(brush1, x, y,
                image.PhysicalDimension.Width + 2 * r,
                image.PhysicalDimension.Height + 2 * r);
            x = y = x + r;
            template.Graphics.DrawImage(image, x, y);

            x = x - 1;
            y = y + image.PhysicalDimension.Height + r + 2;
            template.Graphics.DrawString(text, font1, brush3,
                new RectangleF(new PointF(x, y), size));

            float x1 = (page.Canvas.ClientSize.Width - template.Width) / 2;
            float y1 = (page.Canvas.ClientSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f) - template.Height / 2 + margin.Top;
            template.Draw(page.Canvas, x1, y1);

            //title
            format.Alignment = PdfTextAlignment.Center;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 24f, FontStyle.Bold));
            x = page.Canvas.ClientSize.Width / 2;
            y = y1 + template.Height + 10;
            page.Canvas.DrawString(Pagination.Properties.Resources.Title, font2, brush3, x, y, format);
        }
Example #35
0
 /**
 * Gets the button appearance.
 * @throws IOException on error
 * @throws DocumentException on error
 * @return the button appearance
 */
 public PdfAppearance GetAppearance()
 {
     PdfAppearance app = GetBorderAppearance();
     Rectangle box = new Rectangle(app.BoundingBox);
     if ((text == null || text.Length == 0) && (layout == LAYOUT_LABEL_ONLY || (image == null && template == null && iconReference == null))) {
         return app;
     }
     if (layout == LAYOUT_ICON_ONLY && image == null && template == null && iconReference == null)
         return app;
     BaseFont ufont = RealFont;
     bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
     float h = box.Height - borderWidth * 2;
     float bw2 = borderWidth;
     if (borderExtra) {
         h -= borderWidth * 2;
         bw2 *= 2;
     }
     float offsetX = (borderExtra ? 2 * borderWidth : borderWidth);
     offsetX = Math.Max(offsetX, 1);
     float offX = Math.Min(bw2, offsetX);
     tp = null;
     float textX = float.NaN;
     float textY = 0;
     float fsize = fontSize;
     float wt = box.Width - 2 * offX - 2;
     float ht = box.Height - 2 * offX;
     float adj = (iconFitToBounds ? 0 : offX + 1);
     int nlayout = layout;
     if (image == null && template == null && iconReference == null)
         nlayout = LAYOUT_LABEL_ONLY;
     Rectangle iconBox = null;
     while (true) {
         switch (nlayout) {
             case LAYOUT_LABEL_ONLY:
             case LAYOUT_LABEL_OVER_ICON:
                 if (text != null && text.Length > 0 && wt > 0 && ht > 0) {
                     fsize = CalculateFontSize(wt, ht);
                     textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2;
                     textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                 }
                 goto case LAYOUT_ICON_ONLY;
             case LAYOUT_ICON_ONLY:
                 if (nlayout == LAYOUT_LABEL_OVER_ICON || nlayout == LAYOUT_ICON_ONLY)
                     iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, box.Top - adj);
                 break;
             case LAYOUT_ICON_TOP_LABEL_BOTTOM:
                 if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) {
                     nlayout = LAYOUT_ICON_ONLY;
                     continue;
                 }
                 float nht = box.Height * 0.35f - offX;
                 if (nht > 0)
                     fsize = CalculateFontSize(wt, nht);
                 else
                     fsize = 4;
                 textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2;
                 textY = offX - ufont.GetFontDescriptor(BaseFont.DESCENT, fsize);
                 iconBox = new Rectangle(box.Left + adj, textY + fsize, box.Right - adj, box.Top - adj);
                 break;
             case LAYOUT_LABEL_TOP_ICON_BOTTOM:
                 if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) {
                     nlayout = LAYOUT_ICON_ONLY;
                     continue;
                 }
                 nht = box.Height * 0.35f - offX;
                 if (nht > 0)
                     fsize = CalculateFontSize(wt, nht);
                 else
                     fsize = 4;
                 textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2;
                 textY = box.Height - offX - fsize;
                 if (textY < offX)
                     textY = offX;
                 iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, textY + ufont.GetFontDescriptor(BaseFont.DESCENT, fsize));
                 break;
             case LAYOUT_LABEL_LEFT_ICON_RIGHT:
                 if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) {
                     nlayout = LAYOUT_ICON_ONLY;
                     continue;
                 }
                 float nw = box.Width * 0.35f - offX;
                 if (nw > 0)
                     fsize = CalculateFontSize(wt, nw);
                 else
                     fsize = 4;
                 if (ufont.GetWidthPoint(text, fsize) >= wt) {
                     nlayout = LAYOUT_LABEL_ONLY;
                     fsize = fontSize;
                     continue;
                 }
                 textX = offX + 1;
                 textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                 iconBox = new Rectangle(textX + ufont.GetWidthPoint(text, fsize), box.Bottom + adj, box.Right - adj, box.Top - adj);
                 break;
             case LAYOUT_ICON_LEFT_LABEL_RIGHT:
                 if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) {
                     nlayout = LAYOUT_ICON_ONLY;
                     continue;
                 }
                 nw = box.Width * 0.35f - offX;
                 if (nw > 0)
                     fsize = CalculateFontSize(wt, nw);
                 else
                     fsize = 4;
                 if (ufont.GetWidthPoint(text, fsize) >= wt) {
                     nlayout = LAYOUT_LABEL_ONLY;
                     fsize = fontSize;
                     continue;
                 }
                 textX = box.Width - ufont.GetWidthPoint(text, fsize) - offX - 1;
                 textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2;
                 iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, textX - 1, box.Top - adj);
                 break;
         }
         break;
     }
     if (textY < box.Bottom + offX)
         textY = box.Bottom + offX;
     if (iconBox != null && (iconBox.Width <= 0 || iconBox.Height <= 0))
         iconBox = null;
     bool haveIcon = false;
     float boundingBoxWidth = 0;
     float boundingBoxHeight = 0;
     PdfArray matrix = null;
     if (iconBox != null) {
         if (image != null) {
             tp = new PdfTemplate(writer);
             tp.BoundingBox = new Rectangle(image);
             writer.AddDirectTemplateSimple(tp, PdfName.FRM);
             tp.AddImage(image, image.Width, 0, 0, image.Height, 0, 0);
             haveIcon = true;
             boundingBoxWidth = tp.BoundingBox.Width;
             boundingBoxHeight = tp.BoundingBox.Height;
         }
         else if (template != null) {
             tp = new PdfTemplate(writer);
             tp.BoundingBox = new Rectangle(template.Width, template.Height);
             writer.AddDirectTemplateSimple(tp, PdfName.FRM);
             tp.AddTemplate(template, template.BoundingBox.Left, template.BoundingBox.Bottom);
             haveIcon = true;
             boundingBoxWidth = tp.BoundingBox.Width;
             boundingBoxHeight = tp.BoundingBox.Height;
         }
         else if (iconReference != null) {
             PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(iconReference);
             if (dic != null) {
                 Rectangle r2 = PdfReader.GetNormalizedRectangle(dic.GetAsArray(PdfName.BBOX));
                 matrix = dic.GetAsArray(PdfName.MATRIX);
                 haveIcon = true;
                 boundingBoxWidth = r2.Width;
                 boundingBoxHeight = r2.Height;
             }
         }
     }
     if (haveIcon) {
         float icx = iconBox.Width / boundingBoxWidth;
         float icy = iconBox.Height / boundingBoxHeight;
         if (proportionalIcon) {
             switch (scaleIcon) {
                 case SCALE_ICON_IS_TOO_BIG:
                     icx = Math.Min(icx, icy);
                     icx = Math.Min(icx, 1);
                     break;
                 case SCALE_ICON_IS_TOO_SMALL:
                     icx = Math.Min(icx, icy);
                     icx = Math.Max(icx, 1);
                     break;
                 case SCALE_ICON_NEVER:
                     icx = 1;
                     break;
                 default:
                     icx = Math.Min(icx, icy);
                     break;
             }
             icy = icx;
         }
         else {
             switch (scaleIcon) {
                 case SCALE_ICON_IS_TOO_BIG:
                     icx = Math.Min(icx, 1);
                     icy = Math.Min(icy, 1);
                     break;
                 case SCALE_ICON_IS_TOO_SMALL:
                     icx = Math.Max(icx, 1);
                     icy = Math.Max(icy, 1);
                     break;
                 case SCALE_ICON_NEVER:
                     icx = icy = 1;
                     break;
                 default:
                     break;
             }
         }
         float xpos = iconBox.Left + (iconBox.Width - (boundingBoxWidth * icx)) * iconHorizontalAdjustment;
         float ypos = iconBox.Bottom + (iconBox.Height - (boundingBoxHeight * icy)) * iconVerticalAdjustment;
         app.SaveState();
         app.Rectangle(iconBox.Left, iconBox.Bottom, iconBox.Width, iconBox.Height);
         app.Clip();
         app.NewPath();
         if (tp != null)
             app.AddTemplate(tp, icx, 0, 0, icy, xpos, ypos);
         else {
             float cox = 0;
             float coy = 0;
             if (matrix != null && matrix.Size == 6) {
                 PdfNumber nm = matrix.GetAsNumber(4);
                 if (nm != null)
                     cox = nm.FloatValue;
                 nm = matrix.GetAsNumber(5);
                 if (nm != null)
                     coy = nm.FloatValue;
             }
             app.AddTemplateReference(iconReference, PdfName.FRM, icx, 0, 0, icy, xpos - cox * icx, ypos - coy * icy);
         }
         app.RestoreState();
     }
     if (!float.IsNaN(textX)) {
         app.SaveState();
         app.Rectangle(offX, offX, box.Width - 2 * offX, box.Height - 2 * offX);
         app.Clip();
         app.NewPath();
         if (textColor == null)
             app.ResetGrayFill();
         else
             app.SetColorFill(textColor);
         app.BeginText();
         app.SetFontAndSize(ufont, fsize);
         app.SetTextMatrix(textX, textY);
         app.ShowText(text);
         app.EndText();
         app.RestoreState();
     }
     return app;
 }
 /**
 * Gets a template layer to create a signature appearance. The layers can go from 0 to 4.
 * <p>
 * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A>
 * for further details.
 * @param layer the layer
 * @return a template
 */
 public PdfTemplate GetLayer(int layer)
 {
     if (layer < 0 || layer >= app.Length)
         return null;
     PdfTemplate t = app[layer];
     if (t == null) {
         t = app[layer] = new PdfTemplate(writer);
         t.BoundingBox = rect;
         writer.AddDirectTemplateSimple(t, new PdfName("n" + layer));
     }
     return t;
 }
Example #37
0
 /// <summary>
 /// Reads the WMF into a template.
 /// </summary>
 /// <param name="template">the template to read to</param>
 public void ReadWMF(PdfTemplate template)
 {
     TemplateData = template;
     template.Width = this.Width;
     template.Height = this.Height;
     Stream istr = null;
     try {
         if (rawData == null){
             WebRequest w = WebRequest.Create(url);
             istr = w.GetResponse().GetResponseStream();
         }
         else{
             istr = new MemoryStream(rawData);
         }
         MetaDo meta = new MetaDo(istr, template);
         meta.ReadAll();
     }
     finally {
         if (istr != null) {
             istr.Close();
         }
     }
 }
        /**
        * Gets the main appearance layer.
        * <p>
        * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A>
        * for further details.
        * @return the main appearance layer
        * @throws DocumentException on error
        * @throws IOException on error
        */
        public PdfTemplate GetAppearance()
        {
            if (IsInvisible()) {
                PdfTemplate t = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(0, 0);
                writer.AddDirectTemplateSimple(t, null);
                return t;
            }
            if (app[0] == null) {
                PdfTemplate t = app[0] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n0"));
                t.SetLiteral("% DSBlank\n");
            }
            if (app[1] == null && !acro6Layers) {
                PdfTemplate t = app[1] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n1"));
                t.SetLiteral(questionMark);
            }
            if (app[2] == null) {
                String text;
                if (layer2Text == null) {
                    StringBuilder buf = new StringBuilder();
                    buf.Append("Digitally signed by ").Append(PdfPKCS7.GetSubjectFields((X509Certificate)certChain[0]).GetField("CN")).Append('\n');
                    buf.Append("Date: ").Append(signDate.ToString("yyyy.MM.dd HH:mm:ss zzz"));
                    if (reason != null)
                        buf.Append('\n').Append("Reason: ").Append(reason);
                    if (location != null)
                        buf.Append('\n').Append("Location: ").Append(location);
                    text = buf.ToString();
                }
                else
                    text = layer2Text;
                PdfTemplate t = app[2] = new PdfTemplate(writer);
                t.BoundingBox = rect;
                writer.AddDirectTemplateSimple(t, new PdfName("n2"));
                if (image != null) {
                    if (imageScale == 0) {
                        t.AddImage(image, rect.Width, 0, 0, rect.Height, 0, 0);
                    }
                    else {
                        float usableScale = imageScale;
                        if (imageScale < 0)
                            usableScale = Math.Min(rect.Width / image.Width, rect.Height / image.Height);
                        float w = image.Width * usableScale;
                        float h = image.Height * usableScale;
                        float x = (rect.Width - w) / 2;
                        float y = (rect.Height - h) / 2;
                        t.AddImage(image, w, 0, 0, h, x, y);
                    }
                }
                Font font;
                if (layer2Font == null)
                    font = new Font();
                else
                    font = new Font(layer2Font);
                float size = font.Size;

                Rectangle dataRect = null;
                Rectangle signatureRect = null;

                if (Render == SignatureRender.NameAndDescription ||
                    (Render == SignatureRender.GraphicAndDescription && this.SignatureGraphic != null)) {
                    // origin is the bottom-left
                    signatureRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.Width / 2 - MARGIN,
                        rect.Height - MARGIN);
                    dataRect = new Rectangle(
                        rect.Width / 2 +  MARGIN / 2,
                        MARGIN,
                        rect.Width - MARGIN / 2,
                        rect.Height - MARGIN);

                    if (rect.Height > rect.Width) {
                        signatureRect = new Rectangle(
                            MARGIN,
                            rect.Height / 2,
                            rect.Width - MARGIN,
                            rect.Height);
                        dataRect = new Rectangle(
                            MARGIN,
                            MARGIN,
                            rect.Width - MARGIN,
                            rect.Height / 2 - MARGIN);
                    }
                }
                else {
                    dataRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.Width - MARGIN,
                        rect.Height * (1 - TOP_SECTION) - MARGIN);
                }

                if (Render == SignatureRender.NameAndDescription) {
                    string signedBy = Legacy.Text.Pdf.PdfPKCS7.GetSubjectFields(this.certChain[0]).GetField("CN");
                    Rectangle sr2 = new Rectangle(signatureRect.Width - MARGIN, signatureRect.Height - MARGIN );
                    float signedSize = FitText(font, signedBy, sr2, -1, runDirection);

                    ColumnText ct2 = new ColumnText(t);
                    ct2.RunDirection = runDirection;
                    ct2.SetSimpleColumn(new Phrase(signedBy, font), signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, signedSize, Element.ALIGN_LEFT);

                    ct2.Go();
                }
                else if (Render == SignatureRender.GraphicAndDescription) {
                    ColumnText ct2 = new ColumnText(t);
                    ct2.RunDirection = runDirection;
                    ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT);

                    Image im = Image.GetInstance(SignatureGraphic);
                    im.ScaleToFit(signatureRect.Width, signatureRect.Height);

                    Paragraph p = new Paragraph();
                    // must calculate the point to draw from to make image appear in middle of column
                    float x = 0;
                    // experimentation found this magic number to counteract Adobe's signature graphic, which
                    // offsets the y co-ordinate by 15 units
                    float y = -im.ScaledHeight + 15;

                    x = x + (signatureRect.Width - im.ScaledWidth) / 2;
                    y = y - (signatureRect.Height - im.ScaledHeight) / 2;
                    p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false));
                    ct2.AddElement(p);
                    ct2.Go();
                }

                if (size <= 0) {
                    Rectangle sr = new Rectangle(dataRect.Width, dataRect.Height);
                    size = FitText(font, text, sr, 12, runDirection);
                }
                ColumnText ct = new ColumnText(t);
                ct.RunDirection = runDirection;
                ct.SetSimpleColumn(new Phrase(text, font), dataRect.Left, dataRect.Bottom, dataRect.Right, dataRect.Top, size, Element.ALIGN_LEFT);
                ct.Go();

            }
            if (app[3] == null && !acro6Layers) {
                PdfTemplate t = app[3] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(100, 100);
                writer.AddDirectTemplateSimple(t, new PdfName("n3"));
                t.SetLiteral("% DSBlank\n");
            }
            if (app[4] == null && !acro6Layers) {
                PdfTemplate t = app[4] = new PdfTemplate(writer);
                t.BoundingBox = new Rectangle(0, rect.Height * (1 - TOP_SECTION), rect.Right, rect.Top);
                writer.AddDirectTemplateSimple(t, new PdfName("n4"));
                Font font;
                if (layer2Font == null)
                    font = new Font();
                else
                    font = new Font(layer2Font);
                float size = font.Size;
                String text = "Signature Not Verified";
                if (layer4Text != null)
                    text = layer4Text;
                Rectangle sr = new Rectangle(rect.Width - 2 * MARGIN, rect.Height * TOP_SECTION - 2 * MARGIN);
                size = FitText(font, text, sr, 15, runDirection);
                ColumnText ct = new ColumnText(t);
                ct.RunDirection = runDirection;
                ct.SetSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.Width - MARGIN, rect.Height - MARGIN, size, Element.ALIGN_LEFT);
                ct.Go();
            }
            int rotation = writer.reader.GetPageRotation(page);
            Rectangle rotated = new Rectangle(rect);
            int n = rotation;
            while (n > 0) {
                rotated = rotated.Rotate();
                n -= 90;
            }
            if (frm == null) {
                frm = new PdfTemplate(writer);
                frm.BoundingBox = rotated;
                writer.AddDirectTemplateSimple(frm, new PdfName("FRM"));
                float scale = Math.Min(rect.Width, rect.Height) * 0.9f;
                float x = (rect.Width - scale) / 2;
                float y = (rect.Height - scale) / 2;
                scale /= 100;
                if (rotation == 90)
                    frm.ConcatCTM(0, 1, -1, 0, rect.Height, 0);
                else if (rotation == 180)
                    frm.ConcatCTM(-1, 0, 0, -1, rect.Width, rect.Height);
                else if (rotation == 270)
                    frm.ConcatCTM(0, -1, 1, 0, 0, rect.Width);
                frm.AddTemplate(app[0], 0, 0);
                if (!acro6Layers)
                    frm.AddTemplate(app[1], scale, 0, 0, scale, x, y);
                frm.AddTemplate(app[2], 0, 0);
                if (!acro6Layers) {
                    frm.AddTemplate(app[3], scale, 0, 0, scale, x, y);
                    frm.AddTemplate(app[4], 0, 0);
                }
            }
            PdfTemplate napp = new PdfTemplate(writer);
            napp.BoundingBox = rotated;
            writer.AddDirectTemplateSimple(napp, null);
            napp.AddTemplate(frm, 0, 0);
            return napp;
        }
 /**
 * Gets the template that aggregates all appearance layers. This corresponds to the /FRM resource.
 * <p>
 * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A>
 * for further details.
 * @return the template that aggregates all appearance layers
 */
 public PdfTemplate GetTopLayer()
 {
     if (frm == null) {
         frm = new PdfTemplate(writer);
         frm.BoundingBox = rect;
         writer.AddDirectTemplateSimple(frm, new PdfName("FRM"));
     }
     return frm;
 }
Example #40
0
 internal static PdfTemplate CreateTemplate(PdfWriter writer, float width, float height, PdfName forcedName) {
     PdfTemplate template = new PdfTemplate(writer);
     template.Width = width;
     template.Height = height;
     writer.AddDirectTemplateSimple(template, forcedName);
     return template;
 }
Example #41
0
 /** Always throws an error. This operation is not allowed.
  * @param template dummy
  * @param a dummy
  * @param b dummy
  * @param c dummy
  * @param d dummy
  * @param e dummy
  * @param f  dummy */
 public override void AddTemplate(PdfTemplate template, float a, float b, float c, float d, float e, float f)
 {
     ThrowError();
 }
Example #42
0
 /// <summary>
 /// Gets an instance of an Image in raw mode.
 /// </summary>
 /// <param name="template"></param>
 /// <returns></returns>
 public static Image GetInstance(PdfTemplate template)
 {
     return new ImgTemplate(template);
 }
Example #43
0
 public void SetAppearance(PdfName ap, PdfTemplate template)
 {
     PdfDictionary dic = (PdfDictionary)Get(PdfName.AP);
     if (dic == null)
         dic = new PdfDictionary();
     dic.Put(ap, template.IndirectReference);
     Put(PdfName.AP, dic);
     if (!form)
         return;
     if (templates == null)
         templates = new Hashtable();
     templates[template] = null;
 }
Example #44
0
        public void SetAppearance(PdfName ap, string state, PdfTemplate template)
        {
            PdfDictionary dicAp = (PdfDictionary)Get(PdfName.AP);
            if (dicAp == null)
                dicAp = new PdfDictionary();

            PdfDictionary dic;
            PdfObject obj = dicAp.Get(ap);
            if (obj != null && obj.IsDictionary())
                dic = (PdfDictionary)obj;
            else
                dic = new PdfDictionary();
            dic.Put(new PdfName(state), template.IndirectReference);
            dicAp.Put(ap, dic);
            Put(PdfName.AP, dicAp);
            if (!form)
                return;
            if (templates == null)
                templates = new Hashtable();
            templates[template] = null;
        }
Example #45
0
 /**
 * Releases the memory used by a template by writing it to the output. The template
 * can still be added to any content but changes to the template itself won't have
 * any effect.
 * @param tp the template to release
 * @throws IOException on error
 */
 public void ReleaseTemplate(PdfTemplate tp)
 {
     PdfIndirectReference refi = tp.IndirectReference;
     Object[] objs = (Object[])formXObjects[refi];
     if (objs == null || objs[1] == null)
         return;
     PdfTemplate template = (PdfTemplate)objs[1];
     if (template.IndirectReference is PRIndirectReference)
         return;
     if (template.Type == PdfTemplate.TYPE_TEMPLATE) {
         AddToBody(template.GetFormXObject(compressionLevel), template.IndirectReference);
         objs[1] = null;
     }
 }
Example #46
0
 /**
 * Adds a template to the document but not to the page resources.
 * @param template the template to add
 * @param forcedName the template name, rather than a generated one. Can be null
 * @return the <CODE>PdfName</CODE> for this template
 */
 internal PdfName AddDirectTemplateSimple(PdfTemplate template, PdfName forcedName)
 {
     PdfIndirectReference refa = template.IndirectReference;
     Object[] obj = (Object[])formXObjects[refa];
     PdfName name = null;
     if (obj == null) {
         if (forcedName == null) {
             name = new PdfName("Xf" + formXObjectsCounter);
             ++formXObjectsCounter;
         }
         else
             name = forcedName;
         if (template.Type == PdfTemplate.TYPE_IMPORTED) {
             // If we got here from PdfCopy we'll have to fill importedPages
             PdfImportedPage ip = (PdfImportedPage)template;
             PdfReader r = ip.PdfReaderInstance.Reader;
             if (!importedPages.ContainsKey(r)) {
                 importedPages[r] = ip.PdfReaderInstance;
             }
             template = null;
         }
         formXObjects[refa] = new Object[]{name, template};
     }
     else
         name = (PdfName)obj[0];
     return name;
 }