Ejemplo n.º 1
0
 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)
     {
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 // we override the onOpenDocument method
 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 de)
     {
     }
     catch (System.IO.IOException ioe)
     {
     }
 }
Ejemplo n.º 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)
        //{

        //}
    }
Ejemplo n.º 6
0
 // we override the onOpenDocument method
 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 (IOException)
     {
     }
 }
Ejemplo n.º 7
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)
     {
     }
 }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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);
     }
 }
Ejemplo n.º 11
0
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         bf             = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb             = writer.DirectContent;
         footerTemplate = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
         //handle exception here
     }
     catch (System.IO.IOException ioe)
     {
         //handle exception here
     }
 }
Ejemplo n.º 12
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;
    }    
Ejemplo n.º 13
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);
     }
 }
Ejemplo n.º 14
0
 // we override the onOpenDocument method
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         PrintTime = DateTime.Now;
         bf        = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb        = writer.DirectContent;
         template  = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
         string erro = de.Message;
     }
     catch (System.IO.IOException ioe)
     {
         string erro = ioe.Message;
     }
 }
Ejemplo n.º 15
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);
     }
 }
Ejemplo n.º 16
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);
        }
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            printTime  = DateTime.Now;
            baseFont   = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            pdfContent = writer.DirectContent;

            Rectangle pageSize = document.PageSize;

            if (Title != string.Empty)
            {
                pdfContent.BeginText();
                pdfContent.SetFontAndSize(baseFont, 18);
                pdfContent.SetRGBColorFill(0, 0, 0);
                pdfContent.SetTextMatrix(pageSize.GetLeft(10), pageSize.GetTop(20));
                pdfContent.ShowText(Title);
                pdfContent.EndText();
            }
            pageNumberTemplate = pdfContent.CreateTemplate(50, 50);
        }
Ejemplo n.º 18
0
        // I am following a tutorial & they said that if I want to create headers/footers when each page is created
        // that I should override the OnEndPage() not the OnStartPage() is that correct?
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            // Post: When each new page is created, add a header & footer image to the page. And set the top margin to 370px
            //       and the bottom margin to 664px.
            // Result: The function executes but the pdf's header image isn't visible & the footer looks resized(scaled up in size).

            string path      = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var    directory = System.IO.Path.GetDirectoryName(path);
            //Footer Image
            Image imgfoot = Image.GetInstance(directory + "/images/pdf/StadaFooter.jpg");
            //Header Image
            Image imghead = Image.GetInstance(directory + "/images/pdf/StadaLogo.jpg");

            imgfoot.SetAbsolutePosition(0, 0);
            imgfoot.ScaleAbsolute(new Rectangle(document.PageSize.Width, 60));

            imghead.SetAbsolutePosition(0, 0);
            imghead.ScaleAbsolute(new Rectangle(document.PageSize.Width, 15));

            PdfContentByte cbhead = writer.DirectContent;
            PdfTemplate    tp     = cbhead.CreateTemplate(document.PageSize.Width, document.PageSize.Height); // units are in pixels but I'm not sure if thats the correct units

            tp.AddImage(imghead);

            PdfContentByte cbfoot = writer.DirectContent;
            PdfTemplate    tpl    = cbfoot.CreateTemplate(document.PageSize.Width, document.PageSize.Height);

            tpl.AddImage(imgfoot);

            cbhead.AddTemplate(tp, 0, document.PageSize.Height);
            cbfoot.AddTemplate(tpl, 0, 0);
            //cbhead.AddTemplate(tp, 0, 715);

            helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

            /*PdfContentByte cb = writer.DirectContent;
             * cbfoot.SaveState();
             * document.SetMargins(35, 35, 100, 82);
             * cb.RestoreState();*/

            //document.NewPage();
            base.OnStartPage(writer, document);
        }
        private static void DrawBeerName(Rectangle rectangle, Cursor topCursor, PdfContentByte canvas, Beer beer,
                                         BaseFont baseFont)
        {
            var textRectangle         = new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Right, topCursor.GetCurrent());
            var templateTextRectangle = new Rectangle(textRectangle.Height, textRectangle.Width);
            var template = canvas.CreateTemplate(templateTextRectangle.Width, templateTextRectangle.Height);
            var fontSize = TextSharpHelpers.GetMultiLineFontSize(canvas, beer.FullName, templateTextRectangle, baseFont, 12,
                                                                 Element.ALIGN_LEFT, Font.NORMAL) - .5f;
            var textFont = new Font(baseFont, fontSize, Font.NORMAL, BaseColor.BLACK);

            TextSharpHelpers.WriteWrappingTextInRectangle(template, beer.FullName, textFont, templateTextRectangle,
                                                          Element.ALIGN_LEFT);
            var angle = Math.PI / 2;

            canvas.AddTemplate(template,
                               (float)Math.Cos(angle), -(float)Math.Sin(angle),
                               (float)Math.Sin(angle), (float)Math.Cos(angle),
                               textRectangle.Left, textRectangle.Top);
        }
Ejemplo n.º 20
0
        private PdfTemplate PdfFooter(PdfContentByte cb, DataRow drFoot)
        {
            // Create the template and assign height
            PdfTemplate tmpFooter = cb.CreateTemplate(580, 70);

            // Move to the bottom left corner of the template
            tmpFooter.MoveTo(1, 1);
            // Place the footer content
            tmpFooter.Stroke();
            // Begin writing the footer
            tmpFooter.BeginText();
            // Set the font and size
            tmpFooter.SetFontAndSize(f_cn, 8);
            // Write out details from the payee table
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["supplier"].ToString(), 0, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address1"].ToString(), 0, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address2"].ToString(), 0, 37, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["address3"].ToString(), 0, 29, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["zip"].ToString() + " " + drFoot["city"].ToString() + " " + drFoot["country"].ToString(), 0, 21, 0);
            // Bold text for ther headers
            tmpFooter.SetFontAndSize(f_cb, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Phone", 215, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 215, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Web", 215, 37, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Legal info", 400, 53, 0);
            // Regular text for infomation fields
            tmpFooter.SetFontAndSize(f_cn, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["phone"].ToString(), 265, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["mail"].ToString(), 265, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["web"].ToString(), 265, 37, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, drFoot["xtrainfo"].ToString(), 400, 45, 0);
            // End text
            tmpFooter.EndText();
            // Stamp a line above the page footer
            cb.SetLineWidth(0f);
            cb.MoveTo(30, 60);
            cb.LineTo(570, 60);
            cb.Stroke();
            // Return the footer template
            return(tmpFooter);
        }
        public void Test_Draw_Text()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var fileStream  = new FileStream(pdfFilePath, FileMode.Create);
            var pdfDoc      = new Document(PageSize.A4);
            var pdfWriter   = PdfWriter.GetInstance(pdfDoc, fileStream);

            pdfDoc.AddAuthor(TestUtils.Author);
            pdfDoc.Open();

            pdfDoc.Add(new Paragraph("Test"));

            PdfContentByte cb = pdfWriter.DirectContent;
            BaseFont       bf = BaseFont.CreateFont();

            cb.BeginText();
            cb.SetFontAndSize(bf, 12);
            cb.MoveText(88.66f, 367);
            cb.ShowText("ld");
            cb.MoveText(-22f, 0);
            cb.ShowText("Wor");
            cb.MoveText(-15.33f, 0);
            cb.ShowText("llo");
            cb.MoveText(-15.33f, 0);
            cb.ShowText("He");
            cb.EndText();

            PdfTemplate tmp = cb.CreateTemplate(250, 25);

            tmp.BeginText();
            tmp.SetFontAndSize(bf, 12);
            tmp.MoveText(0, 7);
            tmp.ShowText("Hello People");
            tmp.EndText();
            cb.AddTemplate(tmp, 36, 343);

            pdfDoc.Close();
            fileStream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Ejemplo n.º 22
0
        private PdfTemplate PdfFooter(PdfContentByte cb)
        {
            // Create the template and assign height
            PdfTemplate tmpFooter = cb.CreateTemplate(580, 70);

            // Move to the bottom left corner of the template
            tmpFooter.MoveTo(1, 1);
            // Place the footer content
            tmpFooter.Stroke();
            // Begin writing the footer
            tmpFooter.BeginText();
            // Set the font and size
            tmpFooter.SetFontAndSize(f_cn, 8);
            // Write out details from the payee table
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Politexniki Ltd", 0, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Thessaloniki", 0, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Menemeni", 0, 37, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "20", 0, 29, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "56123" + " " + "Thessaloniki" + " " + "Greece", 0, 21, 0);
            // Bold text for ther headers
            tmpFooter.SetFontAndSize(f_cb, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Phone", 215, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 215, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Web", 215, 37, 0);
            //tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Legal info", 400, 53, 0);
            // Regular text for infomation fields
            tmpFooter.SetFontAndSize(f_cn, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "456155616", 265, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "*****@*****.**", 265, 45, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "www.politexniki.gr", 265, 37, 0);
            // End text
            tmpFooter.EndText();
            // Stamp a line above the page footer
            cb.SetLineWidth(0f);
            cb.MoveTo(30, 60);
            cb.LineTo(560, 60);
            cb.Stroke();
            // Return the footer template
            return(tmpFooter);
        }
Ejemplo n.º 23
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4.Rotate()))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte over  = writer.DirectContent;
         PdfContentByte under = writer.DirectContentUnder;
         locations = PojoFactory.GetLocations();
         PdfTemplate t_under = under.CreateTemplate(
             PageSize.A4.Height, PageSize.A4.Width
             );
         DrawTimeTable(t_under);
         PdfTemplate t_over = over.CreateTemplate(
             PageSize.A4.Height, PageSize.A4.Width
             );
         DrawTimeSlots(t_over);
         DrawInfo(t_over);
         List <string>    days = PojoFactory.GetDays();
         List <Screening> screenings;
         int d = 1;
         foreach (string day in days)
         {
             over.AddTemplate(t_over, 0, 0);
             under.AddTemplate(t_under, 0, 0);
             DrawDateInfo(day, d++, over);
             screenings = PojoFactory.GetScreenings(day);
             foreach (Screening screening in screenings)
             {
                 DrawBlock(screening, under, over);
                 DrawMovieInfo(screening, over);
             }
             document.NewPage();
         }
     }
 }
Ejemplo n.º 24
0
 // write on top of document
 public override void OnOpenDocument(PdfWriter writer, Document document)
 {
     base.OnOpenDocument(writer, document);
     try
     {
         if (PrintTime == null)
         {
             PrintTime = DateTime.Now;
         }
         bf       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb       = writer.DirectContent;
         template = cb.CreateTemplate(50, 50);
     }
     catch (DocumentException de)
     {
         Console.WriteLine(de.Message);
     }
     catch (System.IO.IOException ioe)
     {
         Console.WriteLine(ioe.Message);
     }
 }
        //footer
        private PdfTemplate PdfFooter(PdfContentByte cb, int num1)
        {
            // kreiranje template
            PdfTemplate tmpFooter = cb.CreateTemplate(580, 70);

            // doljnji lijevi čošak stranice
            tmpFooter.MoveTo(1, 1);
            // dodavanje footera
            tmpFooter.Stroke();
            // upisivanje u footer
            tmpFooter.BeginText();
            // postavljanje formatea i veličine
            tmpFooter.SetFontAndSize(f_cb, 8);
            // Info
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Dobavljac", 0, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Adresa", 0, 45, 0);

            tmpFooter.SetFontAndSize(f_cn, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetTrgovina[0], 50, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetUlicaTrg[0] + ", " + crud.GetMjesto[0], 50, 45, 0);

            //naslovi
            tmpFooter.SetFontAndSize(f_cb, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Tel/Mob", 215, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Mail", 400, 53, 0);
            // info
            tmpFooter.SetFontAndSize(f_cn, 8);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetMob[0], 265, 53, 0);
            tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, crud.GetEmail[0], 450, 53, 0);
            // kraj
            tmpFooter.EndText();
            // dodavanje linije iznad samog footera
            cb.SetLineWidth(0f);
            cb.MoveTo(30, 65);
            cb.LineTo(570, 65);
            cb.Stroke();
            return(tmpFooter);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Page footer for 2nd and remaining pages.  Only prints page number.
        /// </summary>
        /// <param name="PageNumber"></param>
        /// <returns></returns>
        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);
        }
Ejemplo n.º 27
0
        private static PdfTemplate createTemplate(PdfContentByte content, Rectangle rect, int factor)
        {
            var template = content.CreateTemplate(rect.Width, rect.Height);

            template.ConcatCtm(factor, 0, 0, factor, 0, 0);

            var hero = TestUtils.GetTxtPath("hero.txt");

            if (!File.Exists(hero))
            {
                throw new FileNotFoundException($"{hero} NOT FOUND!");
            }
            var fi = new FileInfo(hero);

            using (var sr = fi.OpenText())
            {
                while (sr.Peek() >= 0)
                {
                    template.SetLiteral((char)sr.Read());
                }
            }
            return(template);
        }
Ejemplo n.º 28
0
        // ---------------------------------------------------------------------------

        /**
         * Generates a PDF file with the text 'Hello World'
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (Document document = new Document())
                {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    // we add the text to the direct content, but not in the right order
                    PdfContentByte cb = writer.DirectContent;
                    BaseFont       bf = BaseFont.CreateFont();
                    cb.BeginText();
                    cb.SetFontAndSize(bf, 12);
                    cb.MoveText(88.66f, 367);
                    cb.ShowText("ld");
                    cb.MoveText(-22f, 0);
                    cb.ShowText("Wor");
                    cb.MoveText(-15.33f, 0);
                    cb.ShowText("llo");
                    cb.MoveText(-15.33f, 0);
                    cb.ShowText("He");
                    cb.EndText();
                    // we also add text in a form XObject
                    PdfTemplate tmp = cb.CreateTemplate(250, 25);
                    tmp.BeginText();
                    tmp.SetFontAndSize(bf, 12);
                    tmp.MoveText(0, 7);
                    tmp.ShowText("Hello People");
                    tmp.EndText();
                    cb.AddTemplate(tmp, 36, 343);
                }
                return(ms.ToArray());
            }
        }
Ejemplo n.º 29
0
 public override void OnEndPage(PdfWriter writer, Document document)
 {
     base.OnEndPage(writer, document);
     if (Reporte == 1)
     {
         PdfTemplate templateM = cb.CreateTemplate(50, 50);
         templates.Add(templateM);
         int      pageN      = writer.CurrentPageNumber;
         string   pageText   = "Página " + pageN.ToString("00") + " de ";
         string   pageSicorp = "Academia GOLL " + DateTime.Now.ToString("dd-MM-yyyy");
         BaseFont bf         = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         float    len        = bf.GetWidthPoint(pageText, 10);
         cb.BeginText();
         cb.SetFontAndSize(bf, 10);
         cb.SetTextMatrix((document.PageSize.Width - 120f), document.PageSize.GetBottom(document.BottomMargin - 5));
         cb.ShowText(pageText);
         cb.EndText();
         cb.AddTemplate(templateM, (document.PageSize.Width - 120f) + len, document.PageSize.GetBottom(document.BottomMargin - 5));
         cbsimarn.BeginText();
         cbsimarn.SetFontAndSize(bf, 10);
         cbsimarn.SetTextMatrix(document.LeftMargin, document.PageSize.GetBottom(document.BottomMargin - 5));
         cbsimarn.ShowText(pageSicorp);
         cbsimarn.EndText();
     }
     else if (Reporte == 3)
     {
         //PdfTemplate templateM = cb.CreateTemplate(50, 50);
         //string pageSicorp = "SICORP " + DateTime.Now.ToString("dd-MM-yyyy");
         //BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         //cbsimarn.BeginText();
         //cbsimarn.SetFontAndSize(bf, 10);
         //cbsimarn.SetTextMatrix(document.LeftMargin, document.PageSize.GetBottom(document.BottomMargin));
         //cbsimarn.ShowText(pageSicorp);
         //cbsimarn.EndText();
     }
 }
        public static void ManipulatePdf(String src, String dest)
        {
            string fullPdfPath = dest + "\\Output.pdf";

            if (File.Exists(fullPdfPath))
            {
                File.Delete(fullPdfPath);
            }

            PdfReader reader = new PdfReader(src);

            using (var fileStream = new FileStream(fullPdfPath, FileMode.Create, FileAccess.Write))
            {
                PdfStamper stamper = new PdfStamper(reader, fileStream);
                // Get canvas for page 1
                PdfContentByte cb = stamper.GetOverContent(1);
                // Create template (aka XOBject)
                PdfTemplate xobject = cb.CreateTemplate(80, 120);
                // Add content using ColumnText
                ColumnText column = new ColumnText(xobject);
                column.SetSimpleColumn(new Rectangle(80, 120));
                column.AddElement(new Paragraph("Some long text that needs to be distributed over several lines."));
                column.Go();
                // Add the template to the canvas
                cb.AddTemplate(xobject, 36, 600);
                double angle = Math.PI / 4;
                cb.AddTemplate(xobject,
                               (float)Math.Cos(angle), -(float)Math.Sin(angle),
                               (float)Math.Cos(angle), (float)Math.Sin(angle),
                               150, 600);
                stamper.Close();
            }
            reader.Close();

            Process.Start(fullPdfPath);
        }
Ejemplo n.º 31
0
 /** Creates a template with the barcode.
  * @param cb the <CODE>PdfContentByte</CODE> to create the template. It
  * serves no other use
  * @param barColor the color of the bars. It can be <CODE>null</CODE>
  * @param textColor the color of the text. It can be <CODE>null</CODE>
  * @return the template
  * @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
  */
 public PdfTemplate CreateTemplateWithBarcode(PdfContentByte cb, Color barColor, Color textColor)
 {
     PdfTemplate tp = cb.CreateTemplate(0, 0);
     Rectangle rect = PlaceBarcode(tp, barColor, textColor);
     tp.BoundingBox = rect;
     return tp;
 }