ScaleAbsolute() public method

Scale the image to an absolute width and an absolute height.
public ScaleAbsolute ( float newWidth, float newHeight ) : void
newWidth float the new width
newHeight float the new height
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Arma el header de los pdf en una tabla, con titulo y foto
        /// </summary>
        /// <param name="titulo">string</param>
        /// <returns>PdfTable</returns>
        public PdfPTable getHeader(string titulo)
        {
            iTextSharp.text.Font font1 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 15);
            iTextSharp.text.Font font2 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 15);

            PdfPTable tableTitulo = new PdfPTable(2);

            float[] widthsTitulo = new float[] { 10f, 3f };
            tableTitulo.SetWidths(widthsTitulo);
            tableTitulo.WidthPercentage    = 100;
            tableTitulo.DefaultCell.Border = 0;

            string rutaImagen = ConfigurationManager.AppSettings["rutaImgLogo"].ToString();

            iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(rutaImagen);
            imagen.Border = 0;
            imagen.ScaleAbsolute(159f, 60f);

            PdfPCell tilde = new PdfPCell(imagen, true);

            tilde.HorizontalAlignment = Element.ALIGN_RIGHT;
            tilde.FixedHeight         = 40f;
            tilde.Border = 0;

            tableTitulo.AddCell(new Paragraph(titulo, font2));
            tableTitulo.AddCell(tilde);
            return(tableTitulo);
        }
Ejemplo n.º 2
0
        public bool AddTextToPdf(string inputPdfPath, string outputPdfPath, string textToAdd, System.Drawing.Point point, string SEALIMG)
        {
            try
            {
                //variables
                string pathin  = inputPdfPath;
                string pathout = outputPdfPath;

                //create PdfReader object to read from the existing document
                using (PdfReader reader = new PdfReader(pathin))
                    //create PdfStamper object to write to get the pages from reader
                    using (PdfStamper stamper = new PdfStamper(reader, new FileStream(pathout, FileMode.Create)))
                    {
                        //select two pages from the original document
                        reader.SelectPages("1-2");

                        //gettins the page size in order to substract from the iTextSharp coordinates
                        var pageSize = reader.GetPageSize(1);

                        // PdfContentByte from stamper to add content to the pages over the original content
                        PdfContentByte pbover = stamper.GetOverContent(1);

                        //add content to the page using ColumnText
                        Font font = new Font();
                        font.Size = 13;

                        Font font2 = new Font();
                        font2.Size = 7;

                        //setting up the X and Y coordinates of the document
                        int x = point.X;
                        int y = point.Y;

                        x += 113;
                        y  = (int)(pageSize.Height - y);

                        ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(textToAdd, font), x, y, 0);
                        ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(reason, font2), 300, 13, 0);

                        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(SEALIMG);
                        img.SetAbsolutePosition(60, 140); // set the position in the document where you want the watermark to appear (0,0 = bottom left corner of the page)
                        img.ScaleAbsolute(140f, 153.25f);
                        PdfContentByte waterMark;
                        for (int page = 1; page <= reader.NumberOfPages; page++)
                        {
                            waterMark = stamper.GetOverContent(page);
                            waterMark.AddImage(img);
                        }


                        stamper.FormFlattening = true;
                    }
                return(true);
            }
            catch (Exception Ex)
            {
                ErrorLog.LogError(Ex);
                return(false);
            }
        }
Ejemplo n.º 3
0
        public bool AddSealSD(string DocumentPath, string SavePath, string SealIMG)
        {
            try
            {
                string WatermarkLocation = SealIMG;
                // string FileLocation = Server.MapPath(Signed);

                Document   document  = new Document();
                PdfReader  pdfReader = new PdfReader(DocumentPath);
                int        PageCount = pdfReader.NumberOfPages;
                PdfStamper stamp     = new PdfStamper(pdfReader, new FileStream(SavePath, FileMode.Create));

                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(WatermarkLocation);
                img.SetAbsolutePosition(float.Parse(Seal_AbsolutePosition_X), float.Parse(Seal_AbsolutePosition_Y)); // set the position in the document where you want the watermark to appear (0,0 = bottom left corner of the page)
                img.ScaleAbsolute(float.Parse(Seal_ScaleAbsolute_W), float.Parse(Seal_ScaleAbsolute_H));
                PdfContentByte waterMark;
                for (int page = PageCount; page <= pdfReader.NumberOfPages; page++)
                {
                    waterMark = stamp.GetOverContent(page);
                    waterMark.AddImage(img);
                }
                stamp.FormFlattening = true;

                stamp.Close();
                document.Close();
                stamp.Close();
                return(true);
            }
            catch (Exception Ex)
            {
                ErrorLog.LogError(Ex);
                return(false);
            }
        }
Ejemplo n.º 4
0
    public void demoPDF()
    {
        using (Stream inputPdfStream = new FileStream(Server.MapPath("~") + "/MyFiles/demo.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
            using (Stream inputImageStream = new FileStream(Server.MapPath("~") + "/Sign/Sign.png", FileMode.Open, FileAccess.Read, FileShare.Read))
                using (Stream outputPdfStream = new FileStream(Server.MapPath("~") + "/MyFiles/Result.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    var reader = new PdfReader(inputPdfStream);

                    int pages = reader.NumberOfPages;

                    for (int i = 0; i < pages; i++)
                    {
                        var stamper        = new PdfStamper(reader, outputPdfStream);
                        var pdfContentByte = stamper.GetOverContent(1);

                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                        // image.ScalePercent(18f);
                        image.ScaleAbsolute(100, 30);

                        image.SetAbsolutePosition(300, 310);
                        pdfContentByte.AddImage(image);


                        stamper.Close();
                    }
                }
    }
        public static PdfPTable livingSkyHeading()
        {
            PdfPTable titleTable = new PdfPTable(2);

            titleTable.SpacingAfter        = 10f;
            titleTable.HorizontalAlignment = 1;
            titleTable.TotalWidth          = 300f;
            titleTable.LockedWidth         = true;


            float[] widths = new float[] { 25f, 275f };
            titleTable.SetWidths(widths);

            lskyLogo.ScaleAbsolute(22f, 22f);


            PdfPCell newCell = null;

            newCell                     = new PdfPCell(lskyLogo);
            newCell.Padding             = 2;
            newCell.Border              = 0;
            newCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            newCell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            titleTable.AddCell(newCell);

            newCell                     = new PdfPCell(new Phrase("Living Sky School Division No. 202", font_large_bold));
            newCell.Padding             = 2;
            newCell.Border              = 0;
            newCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            newCell.VerticalAlignment   = PdfPCell.ALIGN_TOP;
            titleTable.AddCell(newCell);

            return(titleTable);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add image
        /// </summary>
        private void addImage(StyleInfo styleInfo, float x, float y, float width, float height,
                              RectangleF clipRectangle, byte[] image, string url, string tooltip)
        {
            //add the image with the zoom and position
            iTextSharp.text.Image pdfImge = iTextSharp.text.Image.GetInstance(image);
            pdfImge.ScaleAbsolute(width, height);
            pdfImge.SetAbsolutePosition(x, pageHeight - y - height);
            document.Add(pdfImge);

            //add url
            if (url != null)
            {
                document.Add(new Annotation(x, pageHeight - y, height, width, url));
            }

            //add tooltip
            if (!string.IsNullOrEmpty(tooltip))
            {
                document.Add(new Annotation(x, pageHeight - y, height, width, tooltip));
            }

            //add any required border
            addBorder(styleInfo, x - styleInfo.PaddingLeft, y - styleInfo.PaddingTop, width + styleInfo.PaddingLeft + styleInfo.PaddingRight,
                      height + styleInfo.PaddingTop + styleInfo.PaddingBottom);
        }
Ejemplo n.º 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

            iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(216f, 1000f);
            Document document = new Document();

            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"HelloWorld.pdf", FileMode.Create));

            document.Open();

            /* chapter05/FoxDogImageTypes.java */
            iText.Image img1 = iText.Image.GetInstance(iText.Image.GetInstance(string.Concat(appPath, "\\", "fox.jpg")));
            img1.Alignment = iText.Image.ALIGN_MIDDLE;
            img1.ScaleAbsolute(100f, 100f);
            document.Add(img1);

            /* chapter05/Barcodes.java */
            PdfContentByte cb = writer.DirectContent;

            document.Add(new Paragraph("Barcode 3 of 9"));
            Barcode39 code39 = new Barcode39();

            code39.Code = "ITEXT IN ACTION";
            document.Add(code39.CreateImageWithBarcode(cb, null, null));

            document.Close();

            webBrowser1.Navigate(string.Concat(appPath, "\\", @"HelloWorld.pdf"));
        }
Ejemplo n.º 8
0
        public static void ConvertFirstApproach()
        {
            // creation of the document with a certain size and certain margins
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);

            // creation of the different writers
            iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Users\Mohd\Documents\visual studio 2013\Projects\TiffToPDF\TiffToPDF\tiff.tif.pdf", System.IO.FileMode.Create));

            // load the tiff image and count the total pages
            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Users\Mohd\Documents\visual studio 2013\Projects\TiffToPDF\TiffToPDF\tiff.tif");
            int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

            document.Open();
            iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
            for (int k = 0; k < total; ++k)
            {
                bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);

                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Jpeg);
                img.SetAbsolutePosition(0, 0);
                img.ScaleAbsolute(500, 500);
                //  img.ScalePercent(72f / img.DpiX * 100);
                img.ScaleAbsoluteHeight(document.PageSize.Height);
                img.ScaleAbsoluteWidth(document.PageSize.Width);
                //    img.CompressionLevel = 1;
                //    img.Deflated = true;
                cb.AddImage(img);

                document.NewPage();
            }
            document.Close();
        }
Ejemplo n.º 9
0
 public static bool ImageToPdf(System.Drawing.Image image, string dest)
 {
     try
     {
         using (Document document = new Document(PageSize.A4))
         {
             try
             {
                 var pagesize = document.PageSize;
                 var width    = pagesize.Width;
                 var height   = pagesize.Height;
                 //image = ResizeImage(image, width, 600, InterpolationMode.HighQualityBicubic, true);
                 var newsize = ResizeKeepAspect(image.Size, Convert.ToDecimal(width), Convert.ToDecimal(width / 2));
                 PdfWriter.GetInstance(document, new FileStream(dest, FileMode.Create));
                 document.Open();
                 iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
                 pdfImage.ScaleAbsolute(new iTextSharp.text.Rectangle(newsize.Width, newsize.Height));
                 document.Add(pdfImage);
                 document.Close();
             }
             catch
             {
                 document.Close();
                 return(false);
             }
         }
         return(true);
     }
     catch { return(false); }
 }
Ejemplo n.º 10
0
        public void ImgTransPDF(List <string> imgList, string afterPath)
        {
            List <string> imageList = imgList;
            //生成PDF路径
            string fileName = string.Empty;

            fileName = afterPath;
            //width:794px;height:1090px
            iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(0f, 0f);
            Document document = new Document(page, 1f, 1f, 1f, 1f);
            //设置纸张横向
            //document.SetPageSize(page.Rotate());
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));

            for (int i = 0; i < imageList.Count; i++)
            {
                document.Open();
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imageList[i]);
                img.ScaleAbsolute(460f, 700f);

                //图片居中
                img.Alignment = iTextSharp.text.Image.MIDDLE_ALIGN;
                //图片绝对定位
                img.SetAbsolutePosition(55, 30);

                //图片打印到PDF
                writer.DirectContent.AddImage(img);
                document.NewPage();
            }

            document.Close();
        }
Ejemplo n.º 11
0
            public override void OnEndPage(PdfWriter writer, Document doc)
            {
                string imageurl = HttpContext.Current.Server.MapPath("~/Content/logo.png");

                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(imageurl);
                logo.ScaleAbsolute(140, 15);

                //Paragraph header = new Paragraph("LOGIC UNIVERSITY", FontFactory.GetFont(FontFactory.TIMES, 25, iTextSharp.text.Font.NORMAL));
                //header.Alignment = Element.ALIGN_LEFT;
                //logo.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
                logo.Alignment = Element.ALIGN_CENTER;
                PdfPTable headerTbl = new PdfPTable(1);

                headerTbl.TotalWidth          = 300;
                headerTbl.HorizontalAlignment = Element.ALIGN_CENTER;

                PdfPCell cell = new PdfPCell(logo);

                cell.Border      = 0;
                cell.PaddingLeft = 10;

                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment   = Element.ALIGN_MIDDLE;

                headerTbl.AddCell(cell);
                headerTbl.WriteSelectedRows(0, -1, 270, 550, writer.DirectContent);
            }
Ejemplo n.º 12
0
        private PdfPTable GetHeader()
        {
            PdfPTable headerTable = new PdfPTable(2);

            headerTable.TotalWidth          = 530f;
            headerTable.HorizontalAlignment = 0;
            headerTable.SpacingAfter        = 20;
            //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

            float[] headerTableColWidth = new float[2];
            headerTableColWidth[0] = 220f;
            headerTableColWidth[1] = 310f;

            headerTable.SetWidths(headerTableColWidth);
            headerTable.LockedWidth = true;

            iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("Images/thai_gov.png"));
            png.ScaleAbsolute(40, 40);

            PdfPCell headerTableCell_0 = new PdfPCell(png);

            headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
            headerTableCell_0.Border = Rectangle.NO_BORDER;
            headerTable.AddCell(headerTableCell_0);

            PdfPCell headerTableCell_1 = new PdfPCell(new Phrase("บันทึกข้อความ", h1));

            headerTableCell_1.HorizontalAlignment = Element.ALIGN_LEFT;
            headerTableCell_1.VerticalAlignment   = Element.ALIGN_BOTTOM;
            headerTableCell_1.Border = Rectangle.NO_BORDER;
            headerTable.AddCell(headerTableCell_1);

            return(headerTable);
        }
Ejemplo n.º 13
0
        private void etractToPdfToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);

            // this.DrawToBitmap(bmp, new Rectangle(tableLayoutPanel1.Location.X, tableLayoutPanel1.Location.Y, tableLayoutPanel1.Width, tableLayoutPanel1.Height));
            panel1.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));


            Document doc = new Document();

            try
            {
                PdfWriter.GetInstance(doc, new FileStream(@"../rcpt/receipt" + label9.Text + ".pdf", FileMode.Create));
                doc.Open();

                //doc.Add(new Paragraph("GIF"));
                // Image gif = Image.GetInstance(imagepath + "/mikesdotnetting.gif");
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bmp, System.Drawing.Imaging.ImageFormat.Bmp);
                img.ScaleAbsolute(159f, 159f);
                PdfPTable table = new PdfPTable(1);
                table.AddCell(img);
                doc.Add(table);
                //doc.Add(a);
                MessageBox.Show("Pdf created Suuccesfully");
            }
            catch (Exception ex)
            {
                //Log error;
                MessageBox.Show("error" + ex);
            }
            finally
            {
                doc.Close();
            }
        }
Ejemplo n.º 14
0
    private static void AddBroHeader(iTextSharp.text.Image Logo, int pageNo, PdfPTable tblPro)
    {
        tblPro.HorizontalAlignment = 0;
        tblPro.TotalWidth          = 838f;
        //tblPro.WidthPercentage = 100;
        tblPro.LockedWidth = true;
        float[] widths = new float[] { 410f, 10f, 418f };
        tblPro.SetWidths(widths);

        //Logo for header
        Logo.ScaleAbsolute(100f, 75f);
        PdfPCell headerCell = new PdfPCell(Logo);

        headerCell.FixedHeight     = 53f;
        headerCell.Colspan         = 2;
        headerCell.Border          = iTextSharp.text.Rectangle.NO_BORDER;
        headerCell.BackgroundColor = BaseColor.BLACK;
        tblPro.AddCell(headerCell);


        var FontColour = new BaseColor(31, 73, 125);
        var MyFont     = FontFactory.GetFont("Times New Roman", 11, FontColour);

        var pageHeaderCell = new PdfPCell(new Phrase("Page " + pageNo, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 9f, iTextSharp.text.Font.NORMAL, BaseColor.WHITE)));

        pageHeaderCell.VerticalAlignment   = Element.ALIGN_BOTTOM;
        pageHeaderCell.HorizontalAlignment = Element.ALIGN_RIGHT;
        pageHeaderCell.BackgroundColor     = BaseColor.BLACK;
        pageHeaderCell.PaddingBottom       = 10f;
        pageHeaderCell.PaddingRight        = 10f;
        pageHeaderCell.Border = iTextSharp.text.Rectangle.NO_BORDER;

        tblPro.AddCell(pageHeaderCell);
        //End Header
    }
Ejemplo n.º 15
0
 public void Logo(string ruta, Document doc)
 {
     iTextSharp.text.Image img = Imagen(ruta);
     img.SetAbsolutePosition(100, 650);
     doc.Add(img);
     img.ScaleAbsolute(25f, 25F);
 }
Ejemplo n.º 16
0
        public void ProgrammaToPdf()
        {
            FileStream fs     = new FileStream("Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
            Document   doc    = new Document(new Rectangle(PageSize.A4.Rotate()));
            PdfWriter  writer = PdfWriter.GetInstance(doc, fs);

            doc.Open();

            doc.Add(new Paragraph("Buikspierenkwartier"));
            iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance("ZVH.jpg");
            myImage.ScaleAbsolute(120f, 120f);
            PdfPTable table = new PdfPTable(5);
            PdfPCell  cell  = new PdfPCell(myImage);

            cell.Colspan             = 5;
            cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            table.AddCell(cell);
            foreach (var oefening in this.Oefeningen)
            {
                table.AddCell(oefening.Oefening.Naam);
                table.AddCell(oefening.Oefening.Houding);
                table.AddCell(oefening.Oefening.oefening);
                table.AddCell(oefening.Oefening.GetReps(oefening.Niveau));
                table.AddCell(oefening.Oefening.Link);
            }
            doc.Add(table);

            doc.Close();
        }
Ejemplo n.º 17
0
        //private static IDictionary<string, string> Meta2Parameters(Texxtoor.BaseLibrary.Pdf2Epub.MetaData data) {
        //  IDictionary<string, string> dictionary = new Dictionary<string, string>();
        //  dictionary.Add("##Author##", data.Author);
        //  dictionary.Add("##Title##", data.Title);
        //  dictionary.Add("##Date##", data.Date);
        //  dictionary.Add("##UUID##", Guid.NewGuid().ToString());
        //  return dictionary;
        //}

        private static void ParseHtml(Document doc, StringReader html, StyleSheet css, List <Bitmap> images)
        {
            iTextSharp.text.Rectangle mySize = null;
            var htmlWorker = new HTMLWorker(doc);

            htmlWorker.SetStyleSheet(css);
            //htmlWorker.Parse(html);
            var objects = HTMLWorker.ParseToList(html, css);

            foreach (var element in objects)
            {
                doc.Add(element);
            }
            mySize = doc.PageSize;
            if (images.Count > 0)
            {
                for (int i = 0; i <= images.Count - 1; i++)
                {
                    System.Drawing.Image  mySource = (Bitmap)images[i];
                    iTextSharp.text.Image myImage  = iTextSharp.text.Image.GetInstance(mySource, System.Drawing.Imaging.ImageFormat.Png);
                    myImage.ScaleAbsolute(400, 300);
                    doc.Add(myImage);
                }
            }
        }
Ejemplo n.º 18
0
        override public void writePdf(bool bBlackAndWhite = false)
        {
            initFile();
            PdfPTable table      = new PdfPTable(m_iCount + 1);
            int       cellHeight = ((int)m_doc.PageSize.Height - 200) / m_iCount;

            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance("");
            image.ScaleAbsolute(cellHeight / 2, cellHeight / 2);
            for (int j = 0; j < m_iCount; j++)
            {
                int cnt = s_random.Next(1, m_iMax);

                for (int i = 0; i < m_iMax; i++)
                {
                    if (i < cnt)
                    {
                        table.AddCell(image);
                    }
                    else
                    {
                        table.AddCell(new Phrase(" "));
                    }
                }

                table.AddCell(rectangle);
            }
            m_doc.Add(table);

            printSiteName();
            m_doc.Close();
        }
Ejemplo n.º 19
0
    public void AddImageFromUrl(PdfPTable t, string url, int colSpan = 1, int HorizontalAlignment = PdfPCell.ALIGN_CENTER, int rowSpan = 1)
    {
        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(url);
        float size = 40;

        // img.ScaleToFit(size, size);
        img.ScaleAbsolute(size, size);

        //img.ScaleAbsoluteWidth(size);
        //img.ScaleAbsoluteHeight(size);
        //img.ScaleAbsolute(200, 50);
        img.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
        PdfPCell c = new PdfPCell();

        c.AddElement(img);
        c.Colspan = colSpan;
        c.Rowspan = rowSpan;

        //        image1.SetAbsolutePosition((PageSize.A4.Width - image1.ScaledWidth) / 2, (PageSize.A4.Height - image1.ScaledHeight) / 2);

        c.FixedHeight = 50;
        //  c.Border = 1;
        c.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
        c.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

        t.AddCell(c);
    }
Ejemplo n.º 20
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            //-------------------------------------------------Foo-------------------------------------------
            PdfPTable tbHeader = new PdfPTable(3);

            tbHeader.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            tbHeader.DefaultCell.Border = 0;
            tbHeader.AddCell(new Paragraph());

            PdfPCell _cell = new PdfPCell(new Paragraph("Comprobante de Pago Salarial"));

            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
            _cell.Border = 0;

            tbHeader.AddCell(_cell);

            _cell = new PdfPCell(new Paragraph("N°" + NumeroComprobante));
            _cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            _cell.Border = 0;

            tbHeader.AddCell(_cell);
            tbHeader.AddCell(new Paragraph());
            tbHeader.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetTop(document.TopMargin) + 30, writer.DirectContent);



            //-------------------------------------------------Footer-------------------------------------------
            PdfPTable tbFooder = new PdfPTable(3);

            tbFooder.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;
            tbFooder.DefaultCell.Border = 0;
            tbFooder.AddCell(new Paragraph());


            _cell = new PdfPCell(new Paragraph("Coorporación Los negritos S.A"));
            _cell.HorizontalAlignment = Element.ALIGN_CENTER;
            _cell.Border = 0;

            tbFooder.AddCell(_cell);


            _cell = new PdfPCell(new Paragraph("Pagina" + writer.PageNumber));
            _cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            _cell.Border = 0;

            tbFooder.AddCell(_cell);
            tbFooder.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin) - 5, writer.DirectContent);

            //Inicio imagen

            Image logo = Image.GetInstance(PathImage);

            logo.SetAbsolutePosition(document.LeftMargin, writer.PageSize.GetTop(document.TopMargin + 40));
            logo.ScaleAbsolute(135f, 135f);
            document.Add(logo);


            //final de imagen
        }
Ejemplo n.º 21
0
        public iTextSharp.text.Image HeaderLogo(string path)
        {
            Bitmap bitmap = new Bitmap(path);

            iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance((System.Drawing.Image)bitmap, BaseColor.WHITE);
            gif.ScaleAbsolute(125.0f, 50.0f);
            return(gif);
        }
Ejemplo n.º 22
0
    private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        AppState appState = new AppState();

        appState.Application = _appState.Application;
        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker     mapMaker     = new MapMaker(appState, pixelWidth, pixelHeight, 2);
        MapImageData mapImageData = mapMaker.GetImage();

        System.Drawing.Bitmap bitmap      = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image));
        Transformation        trans       = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent);
        MapGraphics           mapGraphics = MapGraphics.FromImage(bitmap, trans);

        double   minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12;
        Envelope extent  = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY));

        if (extent.Width < minSize)
        {
            extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY));
        }

        if (extent.Height < minSize)
        {
            extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5));
        }

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red));
        System.Drawing.Pen   pen   = new System.Drawing.Pen(System.Drawing.Color.Red, 4);

        mapGraphics.FillEnvelope(brush, extent);
        mapGraphics.DrawEnvelope(pen, extent);

        MemoryStream stream = new MemoryStream();

        bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] mapImage = stream.ToArray();

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
 public void IMGPrint(Document doc)
 {
     //System.Drawing.Image img = Properties.Resources.Castle_logo;
     System.Drawing.Image  img        = Properties.Resources.tituln;
     iTextSharp.text.Image fonpicture = iTextSharp.text.Image.GetInstance(img, BaseColor.WHITE);
     //fonpicture.ScalePercent(22);
     fonpicture.SetAbsolutePosition(0, 0);
     fonpicture.ScaleAbsolute(600, 800);
     doc.Add(fonpicture);
 }
Ejemplo n.º 24
0
        // save pdf button
        private void button2_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog()
            {
                Filter = "PDF file|*.pdf", ValidateNames = true
            }) {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    Document doc = new Document(PageSize.A4);

                    try {
                        PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                        doc.Open();

                        // logo
                        iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(@"img\company_logo.png");
                        logo.ScaleAbsolute(200, 90);
                        doc.Add(logo);

                        // fonts
                        var titleFont     = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD);
                        var boldTableFont = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD);
                        var bodyFont      = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.NORMAL);

                        Paragraph para = new Paragraph(report_tag.Text, titleFont);
                        para.SpacingBefore = 10;
                        doc.Add(para);
                        doc.Add(new Paragraph("Mozumdar Drug Store, Mirpur, Dhaka.", bodyFont));
                        doc.Add(new Paragraph("Issue Date: " + DateTime.Now.ToLongDateString(), bodyFont));

                        doc.Add(headerTable);

                        doc.Add(new Paragraph("Product wise: ", boldTableFont));
                        doc.Add(productTable);

                        doc.Add(new Paragraph("Company wise: ", boldTableFont));
                        doc.Add(companyTable);

                        doc.Add(new Paragraph("Employee wise: ", boldTableFont));
                        doc.Add(employeeTable);

                        if (Type == 0)
                        {
                            doc.Add(new Paragraph("Representative wise: ", boldTableFont));
                            doc.Add(representativeTable);
                        }
                    } catch (Exception exep) {
                    } finally {
                        doc.Close();
                        MessageBox.Show("Pdf file saved!");
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public void exportBalance(string cardNo, string status)
        {
            string atmID     = "ATM001";
            string accountID = accountBUL.getAccountID(cardNo);
            string date      = DateTime.Now.ToString("yyyy-MM-dd");
            string time      = DateTime.Now.ToString("h:mm tt");
            string balance   = accountBUL.getBalance(cardNo);

            // Tạo 1 document
            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(400, 600);
            rect.BackgroundColor = new BaseColor(System.Drawing.Color.WhiteSmoke);
            Document doc = new Document(rect, 50, 50, 50, 50);

            string imgURL = "", path = "";

            iTextSharp.text.Image img = null;

            // đường đẫn đọc ảnh mẫu
            imgURL = @"E:\NAM 4 KY 1\WIN_FORM\BAI TAP LON\BTL_WIN\YÊUCẦU + BIÊNLAI\BIÊN LAI\mẫu\bien lai.jpg";
            img    = iTextSharp.text.Image.GetInstance(imgURL);

            // đường dẫn ghi file pdf
            indexName++;
            path = @"E:\NAM 4 KY 1\WIN_FORM\BAI TAP LON\BTL_WIN\YÊUCẦU + BIÊNLAI\BIÊN LAI\bien lai" + indexName + ".pdf";
            PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));

            doc.Open();

            img.ScaleAbsolute(300f, 500f);
            img.Border      = iTextSharp.text.Rectangle.BOX;
            img.BorderColor = BaseColor.BLUE;
            img.BorderWidth = 3f;
            Paragraph paragraph = new Paragraph();
            Phrase    phrase    = new Phrase("\n\n\n\n\n\n\n\n\n\n");
            Phrase    phrase1   = new Phrase("   NGAY                          GIO                        MAY ATM\n\n");
            Phrase    phrase2   = new Phrase("   " + date + "                 " + time + "                 " + atmID + "\n\n");
            Phrase    phrase3   = new Phrase("   SO THE  :  " + cardNo + "\n\n");
            Phrase    phrase4   = new Phrase("   SO GD   : 9918 \n\n");
            Phrase    phrase5   = new Phrase("   SO TAI KHOAN  :   " + accountID + "\n\n");
            Phrase    phrase6   = new Phrase("   SO DU   :   " + balance + " VND\n");

            paragraph.Add(phrase);
            paragraph.Add(phrase1);
            paragraph.Add(phrase2);
            paragraph.Add(phrase3);
            paragraph.Add(phrase4);
            paragraph.Add(phrase5);
            paragraph.Add(phrase6);

            paragraph.Add(new Chunk(img, 0, -125));

            doc.Add(paragraph);
            doc.Close();
        }
Ejemplo n.º 26
0
        //adding image to PDF
        public void SetImage(string imagePath)
        {
            doc.Open();
            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagePath);
            image.ScaleAbsolute(400, 400);
            image.SetAbsolutePosition(50, 350);
            Paragraph imageParagragh = new Paragraph();

            imageParagragh.Add(image);
            doc.Add(imageParagragh);
        }
Ejemplo n.º 27
0
        private void To_pdf()
        {
            Document       doc  = new Document(PageSize.LETTER.Rotate(), 10, 10, 10, 10);
            SaveFileDialog save = new SaveFileDialog();

            save.Title       = "[LFP]PROYECTO REPORTE NO.1";
            save.DefaultExt  = "pdf";
            save.Filter      = "pdf Files (*.pdf)|*.pdf| All Files(*.*)|*.*";
            save.FilterIndex = 2;
            string filename = " ";

            if (save.ShowDialog() == DialogResult.OK)
            {
                filename = save.FileName;
            }

            if (filename.Trim() != "")
            {
                FileStream file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                PdfWriter.GetInstance(doc, file);
                doc.Open();

                string remito = "Autorizo: Uzzi Libni Aarón Pineda Solórzano.";
                string envio  = "Fecha:" + DateTime.Now.ToString();
                string url    = @"C:\\Users\\libni\\OneDrive\\Imágenes\\logo_institucional.png";

                System.Drawing.Image  image    = System.Drawing.Image.FromFile(url);
                iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Png);
                pdfImage.ScaleAbsolute(189f, 130f);

                Chunk chunk = new Chunk("Reporte De competitividad", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD));
                doc.Add(pdfImage);
                doc.Add(new Paragraph(chunk));
                doc.Add(new Paragraph("                       "));
                doc.Add(new Paragraph("------------------------------------------------------------------------------------------"));
                doc.Add(new Paragraph("Proyecto Lenguajes Formales y de Programación"));
                doc.Add(new Paragraph(remito));
                doc.Add(new Paragraph(envio));
                doc.Add(new Paragraph("------------------------------------------------------------------------------------------"));
                doc.Add(new Paragraph("                       "));
                GenerarDocumento(doc);
                doc.AddCreationDate();
                doc.Add(new Paragraph("Continente al cual pertenece el pais: "));
                doc.Add(new Paragraph("Nombre del pais: "));
                doc.Add(new Paragraph("Poblacion: "));
                doc.Add(new Paragraph("bandera: "));
                doc.Add(new Paragraph("______________________________________________", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD)));
                doc.Add(new Paragraph("Firma", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD)));
                doc.Close();
                Process.Start(filename);
            }
        }
Ejemplo n.º 28
0
        public override void DrawItem(iTextSharp.text.pdf.PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            base.DrawItem(pdfWriter, converter);
            iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance(image, null, false);

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            im.ScaleAbsolute(r.Width, r.Height);
            im.SetAbsolutePosition(r.Left, r.Top - r.Height);
            PdfContentByte cb = base.PdfWriter.DirectContent;

            cb.AddImage(im);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Add Image to Pdf from Image path with Scale size.
        /// </summary>
        /// <param name="ImagePath"></param>
        /// <param name="ImageSize"></param>
        /// <exception cref="System.ArgumentNullException">ImagePath is null.</exception>
        /// <exception cref="System.UriFormatException">ImagePath is empty.-or- The scheme specified in ImagePath is not correctly formed.</exception>
        private static void AddImageWithSize(String ImagePath, float ImageSize = 100f)
        {
            System.Drawing.Image Image = System.Drawing.Bitmap.FromFile(ImagePath);

            iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(Image, System.Drawing.Imaging.ImageFormat.Jpeg);

            pic.ScaleAbsolute(ImageSize, ImageSize);
            PdfPTable table = new PdfPTable(1);

            table.AddCell(new PdfPCell(pic));
            table.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
            ElementList.Add(table);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Metodo para agregar una celda al archivo con una foto de una persona
        /// </summary>
        /// <returns></returns>
        public static PdfPTable AddCeldaFotos(PdfPTable tabla, Model_Celda _celda)
        {
            iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(_celda.Texto));
            logo.ScaleAbsolute(100f, 100f);
            PdfPCell celda = new PdfPCell(logo);

            celda                     = SetBorde(celda, _celda.Borde);
            celda.Colspan             = _celda.Colspan;
            celda.Rowspan             = _celda.Rowspan;
            celda.HorizontalAlignment = GetAlineacion(_celda.Alinear);
            tabla.AddCell(celda);
            return(tabla);
        }