Beispiel #1
0
        async private void OpenFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            await Task.Run(() =>
            {
                // Create a pdf document with a section and page added.
                PdfDocument doc    = new PdfDocument();
                PdfSection section = doc.Sections.Add();
                PdfPageBase page   = doc.Pages.Add();
                //Load a tiff image from system
                PdfImage image =
                    PdfImage.FromFile(
                        System.Text.RegularExpressions.Regex.Escape(
                            openFileDialog1.FileName).Replace(@"\.", "."));
                //Set image display location and size in PDF
                float widthFitRate  = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
                float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
                float fitRate       = Math.Max(widthFitRate, heightFitRate);
                float fitWidth      = image.PhysicalDimension.Width / fitRate;
                float fitHeight     = image.PhysicalDimension.Height / fitRate;
                page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);
                doc.SaveToFile("imageToPdf.pdf");
                doc.Close();
            });

            pdfViewer2.LoadFromFile("imageToPdf.pdf");
        }
Beispiel #2
0
        //Exports and saves the chart in Pdf.
        #region Pdf
        private void buttonPdf_Click(object sender, EventArgs e)
        {
            try
            {
                exportFileName = fileName + ".pdf";
                string file = fileName + ".gif";

                if (!System.IO.File.Exists(file))
                {
                    this.chartControl1.SaveImage(file);
                }

                //Create a new PDF Document. The pdfDoc object represents the PDF document.
                //This document has one page by default and additional pages have to be added.
                PdfDocument pdfDoc = new PdfDocument();

                pdfDoc.Pages.Add();

                pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromFile(file), new PointF(10, 30));

                //Save the PDF Document to disk.
                pdfDoc.Save(exportFileName);
                OpenFile("Pdf", exportFileName);
            }
            catch (Exception ex)
            {
                this.toolStripStatusLabel1.Text = "Chart Export failed.";
                Console.WriteLine(ex.ToString());
            }
        }
        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);
        }
Beispiel #4
0
        /// <summary>
        /// 生产pdf的重载方法
        /// </summary>
        /// <param name="ImageFileName"></param>
        /// <param name="pdfFileName"></param>
        private static void GenaratePDF(String ImageFileName, String pdfFileName)
        {
            PdfDocument doc  = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            //添加文本
            //page.Canvas.DrawString("Demo of extract text and imgae from PDF!",
            //new PdfFont(PdfFontFamily.Helvetica, 20f),
            //new PdfSolidBrush(Color.Black), 10, 10);
            // page.Canvas.TranslateTransform(0,-150);
            //添加图片

            PdfImage image2 = PdfImage.FromFile(ImageFileName);
            float    width  = image2.Width * 0.75f;
            float    height = image2.Height * 0.75f;
            float    x      = (page.Canvas.ClientSize.Width - width) / 2;

            Console.WriteLine("page.Canvas.ClientSize.Width  =" + page.Canvas.ClientSize.Width);
            Console.WriteLine("width=" + width);
            page.Canvas.DrawImage(image2, x, 0); //page.Canvas.DrawImage(image2, 0, 0);/与page.Canvas.DrawImage(image2, 0, 0,width,height);等价
            //page.Canvas.DrawImage(image2, x - 100, 0, width, height);
            page.Canvas.DrawString("Demo of extract text and imgae from PDF!",
                                   new PdfFont(PdfFontFamily.Helvetica, 20f),
                                   new PdfSolidBrush(Color.Blue), 0, 0);//drawString x,y 表示坐标原点的位置。
            doc.SaveToFile(pdfFileName);


            PDFDocumentViewer(pdfFileName);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load document from disk
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"../../../../../../Data/PDFTemplate_N.pdf");

            //Load an image
            PdfImage image = PdfImage.FromFile("../../../../../../Data/E-iceblueLogo.png");

            foreach (PdfPageBase page in pdf.Pages)
            {
                //Create PdfTilingBrush
                PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.Size.Width / 3, page.Canvas.Size.Height / 5));

                //Set the transparency
                brush.Graphics.SetTransparency(0.3f);

                //Draw image on brush graphics
                brush.Graphics.DrawImage(image, new PointF((brush.Size.Width - image.Width) / 2, (brush.Size.Height - image.Height) / 2));

                //use the brush to draw rectangle
                page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.Size));
            }

            //Save the Pdf document
            string output = "AddTilingBackgroundImage_out.pdf";

            pdf.SaveToFile(output, FileFormat.PDF);

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //Draw the text
            page.Canvas.DrawString("Hello, World!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);
            //Draw the image
            PdfImage image  = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            float    width  = image.Width * 0.75f;
            float    height = image.Height * 0.75f;
            float    x      = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 60, width, height);

            //Save pdf file.
            doc.SaveToFile("Image.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Image.pdf");
        }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string path = "..\\..\\..\\..\\..\\..\\Data\\";
            //pdf file
            string input = path + "Sample4.pdf";

            //open pdf document
            PdfDocument doc = new PdfDocument(input);

            //create a pdf image
            PdfImage headerImage = PdfImage.FromFile(path + "E-iceblue logo.png");

            //draw header image into pages
            foreach (PdfPageBase page in doc.Pages)
            {
                page.Canvas.DrawImage(headerImage, new PointF(10, 2));
            }

            string output = "AddImageInHeader.pdf";

            //Save pdf file.
            doc.SaveToFile(output);
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer(output);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            string      input    = "..\\..\\..\\..\\..\\..\\Data\\AddImageStamp.pdf";
            PdfDocument document = new PdfDocument();

            document.LoadFromFile(input);
            //Get the first page
            PdfPageBase page = document.Pages[0];

            //Create a rubber stamp annotation
            PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(0, 0), new SizeF(60, 60)));

            //Create an instance of PdfAppearance
            PdfAppearance loApprearance = new PdfAppearance(loStamp);
            PdfImage      image         = PdfImage.FromFile("..\\..\\..\\..\\..\\..\\..\\Data\\image stamp.jpg");
            PdfTemplate   template      = new PdfTemplate(210, 210);

            //Draw a pdf image into pdf template
            template.Graphics.DrawImage(image, 60, 60);
            loApprearance.Normal = template;
            loStamp.Appearance   = loApprearance;

            //Add the rubber stamp annotation into pdf
            page.AnnotationsWidget.Add(loStamp);

            string output = "AddImageStamp.pdf";

            //Save pdf document
            document.SaveToFile(output);

            //Launch the file
            PDFDocumentViewer(output);
        }
Beispiel #9
0
        private void btnExportarPDF_Click(object sender, EventArgs e)
        {
            if (dgvMaterias.Rows.Count == 0)
            {
                MessageBox.Show("Sin datos por EXPORTAR", "Aviso", MessageBoxButtons.OK);
            }
            else
            {
                PdfDocument pdf   = new PdfDocument();
                PdfPageBase page  = pdf.Pages.Add();
                PdfTable    table = new PdfTable();
                table.DataSource       = dgvMaterias.DataSource;
                table.Style.ShowHeader = true;

                PdfImage image  = PdfImage.FromFile(Path.Combine(System.IO.Path.GetFullPath(@"..\..\"), "Resources\\reporte.jpeg"));
                float    width  = image.Width * 0.75f;
                float    height = image.Height * 0.75f;
                float    x      = (page.Canvas.ClientSize.Width - width) / 2;
                page.Canvas.DrawImage(image, x, 60, width, height);

                table.Style.CellPadding = 2;
                PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
                tableLayout.Break     = PdfLayoutBreakType.FitElement;
                tableLayout.Layout    = PdfLayoutType.Paginate;
                table.BeginRowLayout += new BeginRowLayoutEventHandler(BeginRowLayout);
                table.Draw(page, new RectangleF(10, 30, 500, 700), tableLayout);


                pdf.SaveToFile("C:\\Users\\AbelFH\\Desktop\\Horarios-Asignados.pdf");
                MessageBox.Show("PDF generado exitosamente", "Aviso", MessageBoxButtons.OK);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load file from disk.
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\ReplaceImage.pdf");

            //Get the first page.
            PdfPageBase page = doc.Pages[0];

            //Load a image
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\E-iceblueLogo.png");

            //Replace the first image on the page.
            page.ReplaceImage(0, image);

            String result = "Output.pdf";

            //Save the document
            doc.SaveToFile(result);

            //Launch the Pdf file
            PDFDocumentViewer("Output.pdf");
        }
Beispiel #11
0
        private void DrawPageHeaderAndFooter(PdfPageBase page, PdfMargins margin, bool isCover)
        {
            page.Canvas.SetTransparency(0.5f);
            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");

            page.Canvas.DrawImage(headerImage, new PointF(0, 0));
            page.Canvas.DrawImage(footerImage, new PointF(0, page.Canvas.ClientSize.Height - footerImage.PhysicalDimension.Height));
            if (isCover)
            {
                page.Canvas.SetTransparency(1);
                return;
            }

            PdfBrush        brush  = PdfBrushes.Black;
            PdfPen          pen    = new PdfPen(brush, 0.75f);
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic), true);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);

            format.MeasureTrailingSpaces = true;
            float space = font.Height * 0.75f;
            float x     = margin.Left;
            float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
            float y     = margin.Top - space;

            page.Canvas.DrawLine(pen, x, y, x + width, y);
            y = y - 1 - font.Height;
            page.Canvas.DrawString("Demo of Spire.Pdf", font, brush, x + width, y, format);
            page.Canvas.SetTransparency(1);
        }
Beispiel #12
0
        static void PdfHeaderFooterEventHandler(object sender, PdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;

            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 38);
            string filePath = "";

            if (AppDomain.CurrentDomain.BaseDirectory.Contains("Binaries"))
            {
                filePath = System.IO.Path.GetFullPath(@"..\..\datagrid\Assets\datagrid\Header.jpg");
            }
            else
            {
                filePath = System.IO.Path.GetFullPath(@"..\..\..\datagrid\Assets\datagrid\Header.jpg");
            }
            header.Graphics.DrawImage(PdfImage.FromFile(filePath), 155, 5, width / 3f, 34);
            e.PdfDocumentTemplate.Top = header;

            PdfPageTemplateElement footer = new PdfPageTemplateElement(width, 30);

            if (AppDomain.CurrentDomain.BaseDirectory.Contains("Binaries"))
            {
                filePath = System.IO.Path.GetFullPath(@"..\..\datagrid\Assets\datagrid\Footer.jpg");
            }
            else
            {
                filePath = System.IO.Path.GetFullPath(@"..\..\..\datagrid\Assets\datagrid\Footer.jpg");
            }
            footer.Graphics.DrawImage(PdfImage.FromFile(filePath), 0, 0);
            e.PdfDocumentTemplate.Bottom = footer;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // Create a pdf document with a section and page added.
            PdfDocument pdf     = new PdfDocument();
            PdfSection  section = pdf.Sections.Add();
            PdfPageBase page    = pdf.Pages.Add();

            //Load a tiff image from system
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Water.jpg");
            //Set image display location and size in PDF
            //Calculate rate
            float widthFitRate  = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
            float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
            float fitRate       = Math.Max(widthFitRate, heightFitRate);
            //Calculate the size of image
            float fitWidth  = image.PhysicalDimension.Width / fitRate;
            float fitHeight = image.PhysicalDimension.Height / fitRate;

            //Draw image
            page.Canvas.DrawImage(image, 0, 30, fitWidth, fitHeight);

            string output = "ConvertImageToPDF-result.pdf";

            pdf.SaveToFile(output);
            pdf.Close();

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
Beispiel #14
0
        private PdfPageTemplateElement CreateHeaderTemplate(PdfDocument doc, PdfMargins margins, SizeF pageSize)
        {
            //create a PdfPageTemplateElement object as header space
            PdfPageTemplateElement headerSpace = new PdfPageTemplateElement(pageSize.Width, margins.Top);

            headerSpace.Foreground = false;

            //declare two float variables
            float x = margins.Left;
            float y = 0;

            //draw image in header space
            PdfImage headerImage = PdfImage.FromFile("../../../../../../../Data/E-iceblueLogo.png");
            float    width       = headerImage.Width / 2;
            float    height      = headerImage.Height / 2;

            headerSpace.Graphics.DrawImage(headerImage, x, margins.Top - height - 5, width, height);

            //draw line in header space
            PdfPen pen = new PdfPen(PdfBrushes.LightGray, 1);

            headerSpace.Graphics.DrawLine(pen, x, y + margins.Top - 2, pageSize.Width - x, y + margins.Top - 2);

            //return headerSpace
            return(headerSpace);
        }
Beispiel #15
0
        private void BackgroundPDF()
        {
            string      pat  = string.Format(@"{0}\{1}.pdf", AppDomain.CurrentDomain.BaseDirectory, "Han");
            string      pat1 = string.Format(@"{0}\{1}.ico", AppDomain.CurrentDomain.BaseDirectory, "LogoBaoBao");
            PdfDocument pdf  = new PdfDocument();

            pdf.LoadFromFile(pat);
            PdfImage image = PdfImage.FromFile(pat1);

            foreach (PdfPageBase page in pdf.Pages)
            {
                //PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.Size.Width / 3, page.Canvas.Size.Height / 5));
                //brush.Graphics.SetTransparency(0.2f);
                //brush.Graphics.DrawImage(image, new PointF((brush.Size.Width - image.Width) / 2, (brush.Size.Height - image.Height) / 2));
                //page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.Size));
                PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
                brush.Graphics.SetTransparency(0.3f);
                brush.Graphics.Save();
                brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
                brush.Graphics.RotateTransform(-45);
                brush.Graphics.DrawString(Login.Username, new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Blue, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
                brush.Graphics.Restore();
                brush.Graphics.SetTransparency(1);
                page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
            }
            pdf.SaveToFile(txtMaSanPham.Text + ".pdf");
        }
Beispiel #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            string path = "..\\..\\..\\..\\..\\..\\Data\\";
            //pdf file
            string input = path + "Sample4.pdf";

            //open pdf document
            PdfDocument doc = new PdfDocument(input);

            //create a pdf image
            PdfImage footerImage = PdfImage.FromFile(path + "logo2.png");

            float x = 0;
            float y = 0;

            //draw footer image into pages
            foreach (PdfPageBase page in doc.Pages)
            {
                x = page.Canvas.ClientSize.Width - footerImage.PhysicalDimension.Width - 10;
                y = page.Canvas.ClientSize.Height - footerImage.PhysicalDimension.Height - 10;
                page.Canvas.DrawImage(footerImage, new PointF(x, y));
            }

            string output = "AddImageInFooter.pdf";

            //Save pdf file.
            doc.SaveToFile(output);
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer(output);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //Create one page
            PdfPageBase page = doc.Pages.Add();

            //Load an image
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\ChartImage.png");

            //Set the width and height of image
            float width  = image.Width * 0.75f;
            float height = image.Height * 0.75f;

            //Define a position to draw image
            float x = (page.Canvas.ClientSize.Width - width) / 2;
            float y = 60f;

            //Draw image on page canvas
            page.Canvas.DrawImage(image, x, y, width, height);

            String result = "SetImageSize_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
 void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
 {
     if (args.RowIndex == 1)
     {
         PdfImage image = PdfImage.FromFile("../../../../../../Data/E-iceblueLogo.png");
         args.MinimalHeight = image.PhysicalDimension.Height + 4;
     }
 }
        /// <summary>
        /// Uploads a file to the webserver.
        /// </summary>
        /// <param name="title">The title for the file, to be used in the Database.</param>
        /// <param name="type">What type of file is uploaded. Example: 'FirstAid' or 'DoctorsNote'.</param>
        /// <param name="fileLocation">The local filepath to the document.</param>
        /// <param name="url">The url of the server, where the file will be uploaded.</param>
        /// <returns>Returns a bool wether the operation was completed or not.</returns>
        private bool UploadFile(string title, string type, string fileLocation, string url)
        {
            Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument();
            FileInfo file = new FileInfo(fileLocation);

            if (!file.Exists)
            {
                return(false);
            }

            if (file.Extension != ".pdf")
            {
                Spire.Pdf.PdfPageBase page = document.Pages.Add();

                PdfImage image = PdfImage.FromFile(fileLocation);
                fileLocation = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.pdf");

                float widthFitRate  = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
                float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
                float fitRate       = Math.Max(widthFitRate, heightFitRate);
                float fitWidth      = image.PhysicalDimension.Width / fitRate;
                float fitHeight     = image.PhysicalDimension.Height / fitRate;
                page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);

                document.DocumentInformation.Title        = $"{Session.LoggedInUser.Fullname} - {type}";
                document.DocumentInformation.Author       = Session.LoggedInUser.Fullname;
                document.DocumentInformation.CreationDate = DateTime.Now;

                document.SaveToFile(fileLocation);
                document.Close();
            }
            else
            {
                document.LoadFromFile(fileLocation);
                document.DocumentInformation.Title        = $"{Session.LoggedInUser.Fullname} - {type}";
                document.DocumentInformation.Author       = Session.LoggedInUser.Fullname;
                document.DocumentInformation.CreationDate = DateTime.Now;

                document.SaveToFile(fileLocation);
                document.Close();
            }

            document.Dispose();

            string fileUrl = SendToServer(fileLocation, url);

            if (fileUrl == "null")
            {
                return(false);
            }

            if (!MySql.UploadDocument(title, type, DateTime.Today, Session.LoggedInUser.Id, fileUrl))
            {
                return(false);
            }

            return(true);
        }
        private void DrawImage(PdfPageBase page)
        {
            PdfImage image  = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            float    width  = image.Width * 0.75f;
            float    height = image.Height * 0.75f;
            float    x      = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 60, width, height);
        }
Beispiel #21
0
        static PdfPageTemplateElement CreateHeaderTemplate(PdfDocument doc, PdfMargins margins)
        {
            //get page size
            SizeF pageSize = doc.PageSettings.Size;

            //create a PdfPageTemplateElement object as header space
            PdfPageTemplateElement headerSpace = new PdfPageTemplateElement(pageSize.Width, 170);

            headerSpace.Foreground = false;

            //declare two float variables
            float x = margins.Left;
            float y = 0;

            //draw image in header space
            PdfImage headerImage = PdfImage.FromFile("1.png");
            float    width       = headerImage.Width / 2;
            float    height      = headerImage.Height / 2;

            headerSpace.Graphics.DrawImage(headerImage, x, margins.Top - height + 130, width, height);

            /*  //draw line in header space
             * PdfPen pen = new PdfPen(PdfBrushes.Gray, 1);
             * headerSpace.Graphics.DrawLine(pen, x, y + margins.Top - 2, pageSize.Width - x, y + margins.Top - 2);
             *
             * //draw text in header space
             * PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Impact", 25f, FontStyle.Bold));
             * PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
             * String headerText = "HEADER TEXT";
             * SizeF size = font.MeasureString(headerText, format);
             * headerSpace.Graphics.DrawString(headerText, font, PdfBrushes.Gray, pageSize.Width - x - size.Width - 2, margins.Top - (size.Height + 5), format);
             */

            PdfImage headerImage2 = PdfImage.FromFile("2.png");
            float    width2       = headerImage.Width / 2;
            float    height2      = headerImage.Height / 5;

            headerSpace.Graphics.DrawImage(headerImage2, x + 230, margins.Top - height2 + 50, width2, height2);


            PdfImage headerImage3 = PdfImage.FromFile("3.png");
            float    width3       = headerImage.Width / 4;
            float    height3      = headerImage.Height / 5;

            headerSpace.Graphics.DrawImage(headerImage3, x + 510, margins.Top - height3 + 50, width3, height3);

            PdfTrueTypeFont font       = new PdfTrueTypeFont(new Font("Arial", 28.5f, FontStyle.Bold));
            PdfStringFormat format     = new PdfStringFormat(PdfTextAlignment.Left);
            String          headerText = "Invoice";
            SizeF           size       = font.MeasureString(headerText, format);

            headerSpace.Graphics.DrawString(headerText, font, PdfBrushes.Black, pageSize.Width - x - size.Width - 40, margins.Top - (size.Height - 130), format);


            //return headerSpace
            return(headerSpace);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load Pdf from disk
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile("../../../../../../../Data/PDFTemplate_HF.pdf");

            //Get the first page
            PdfPageBase page = doc.Pages[0];

            string   text1 = "Spire.Pdf is a robust component by";
            string   text2 = "Technology Co., Ltd.";
            PdfImage image = PdfImage.FromFile("../../../../../../../Data/Top-logo.png");

            //Define font and bursh
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Impact", 10f));
            PdfBrush        bursh = PdfBrushes.DarkGray;

            //Get the size of text
            SizeF s1 = font.MeasureString(text1);
            SizeF s2 = font.MeasureString(text2);

            float x = 10;
            float y = 10;

            //Define image size
            SizeF imgSize = new SizeF(image.Width / 2, image.Height / 2);

            //Define rectangle and string format
            SizeF           size   = new SizeF(s1.Width, imgSize.Width);
            RectangleF      rect1  = new RectangleF(new PointF(x, y), size);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);

            //Draw the text1
            page.Canvas.DrawString(text1, font, bursh, rect1, format);

            //Draw the image
            x += s1.Width;
            page.Canvas.DrawImage(image, new PointF(x, y), imgSize);


            //Draw the text2
            x    += imgSize.Width;
            size  = new SizeF(s2.Width, imgSize.Height);
            rect1 = new RectangleF(new PointF(x, y), size);
            page.Canvas.DrawString(text2, font, bursh, rect1, format);

            //Save the document
            string output = "ImageandPageNumberinHeaderFootersectionInline_out.pdf";

            doc.SaveToFile(output);
            doc.Close();

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
Beispiel #23
0
        //[HttpPost]
        //[ValidateInput(false)]
        //public FileResult Export(string GridHtml)
        //{
        //    using (MemoryStream stream = new System.IO.MemoryStream())
        //    {
        //        StringReader sr = new StringReader(GridHtml);
        //        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
        //        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
        //        pdfDoc.Open();
        //        XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
        //        pdfDoc.Close();
        //        return File(stream.ToArray(), "application/pdf", "Grid.pdf");
        //    }
        //}

        public FileResult CreateDocument()
        {
            using (PdfDocument document = new PdfDocument())
            {
                //Create a new PDF document.
                PdfDocument doc = new PdfDocument();
                //Adds page settings
                document.PageSettings.Orientation = PdfPageOrientation.Landscape;
                document.PageSettings.Margins.All = 50;

                //Add a page.
                PdfPage     page     = doc.Pages.Add();
                PdfGraphics graphics = page.Graphics;
                //Create a PdfGrid.
                PdfGrid    pdfGrid = new PdfGrid();
                PdfImage   image   = PdfImage.FromFile(Server.MapPath("../Content/img/índice.png"));
                RectangleF bounds  = new RectangleF(0, 0, 150, 150);
                //Draws the image to the PDF page
                page.Graphics.DrawImage(image, bounds);
                //Create a DataTable.
                DataTable dataTable = new DataTable();

                //Add columns to the DataTable
                dataTable.Columns.Add("IdVenta");
                dataTable.Columns.Add("Nombre Producto");
                dataTable.Columns.Add("Descripcion");
                dataTable.Columns.Add("Precio");
                dataTable.Columns.Add("Fecha");
                dataTable.Columns.Add("Cantidad");
                dataTable.Columns.Add("Total");
                //Add rows to the DataTable.
                ML.DetalleVenta detalleVenta = new ML.DetalleVenta();
                detalleVenta.Venta    = new ML.Venta();
                detalleVenta.Producto = new ML.Producto();
                ML.Result result = BL.DetalleVenta.GetAll();
                detalleVenta.DetalleVentas = result.Objects;

                foreach (ML.DetalleVenta detalle in detalleVenta.DetalleVentas)
                {
                    dataTable.Rows.Add(new object[] { detalle.Venta.IdVenta, detalle.Producto.Nombre, detalle.Producto.Descripcion,
                                                      detalle.Producto.Precio, detalle.Venta.Fecha, detalle.Cantidad, detalle.Venta.Total });
                }



                //Assign data source.
                pdfGrid.DataSource = dataTable;
                //Draw grid to the page of PDF document.
                pdfGrid.Draw(page, new PointF(10, 10));
                // Open the document in browser after saving it
                doc.Save("Output.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                //close the document
                doc.Close(true);
            }
            return(null);
        }
Beispiel #24
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            String      input = @"..\..\..\..\..\..\Data\DigitalSignature.pdf";
            PdfDocument doc   = new PdfDocument();

            doc.LoadFromFile(input);
            //Load the certificate
            String         pfxPath = @"..\..\..\..\..\..\Data\gary.pfx";
            PdfCertificate cert    = new PdfCertificate(pfxPath, "e-iceblue");

            PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "signature0");

            signature.Bounds = new RectangleF(new PointF(90, 550), new SizeF(270, 90));

            //Load sign image source.
            signature.SignImageSource = PdfImage.FromFile(@"..\..\..\..\..\..\Data\E-iceblueLogo.png");

            //Set the dispay mode of graphics, if not set any, the default one will be applied
            signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
            signature.NameLabel    = "Signer:";

            signature.Name = "Gary";

            signature.ContactInfoLabel = "ContactInfo:";
            signature.ContactInfo      = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);

            signature.DateLabel = "Date:";
            signature.Date      = DateTime.Now;

            signature.LocationInfoLabel = "Location:";
            signature.LocationInfo      = "Chengdu";

            signature.ReasonLabel = "Reason: ";
            signature.Reason      = "The certificate of this document";

            signature.DistinguishedNameLabel = "DN: ";
            signature.DistinguishedName      = signature.Certificate.IssuerName.Name;

            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            signature.Certificated        = true;

            //Set fonts. if not set, default ones will be applied.
            signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
            signature.SignNameFont    = new PdfFont(PdfFontFamily.Courier, 15);

            //Set the sign image layout mode
            signature.SignImageLayout = SignImageLayout.None;

            //Save pdf file.
            doc.SaveToFile("DigitalSignature.pdf");
            doc.Close();

            //Launch the file.
            PDFDocumentViewer("DigitalSignature.pdf");
        }
        public bool IntroPdf(PdfSection sec, string name, string surname, string email, string note, string pathOfImage, int numberOfNewLine, bool argument)
        {
            float intro = 10;

            try
            {
                page = sec.Pages.Add();

                float width  = 0;
                float height = 0;
                if (argument)
                {
                    PdfImage image = PdfImage.FromFile(pathOfImage);
                    if (image.Width < 150 || image.Height < 150)
                    {
                        return(false);
                    }
                    else
                    {
                        width = 150; height = 150;
                        float x = (page.Canvas.ClientSize.Width - width) / 2;
                        page.Canvas.DrawImage(image, x, intro, width, height);
                    }
                }
                intro += height;
                page.Canvas.DrawString("Browser Report", font1, brush1, page.Canvas.ClientSize.Width / 2, intro, format1);
                intro += fontInfo.MeasureString("Country List", format1).Height;
                intro += 20;
                page.Canvas.DrawString("Name    : " + name, fontInfo, brush1, 0, intro, leftAlignment);
                intro += 20;
                page.Canvas.DrawString("Surname : " + surname, fontInfo, brush1, 0, intro, leftAlignment);
                intro += 20;
                page.Canvas.DrawString("E-Mail  : " + email, fontInfo, brush1, 0, intro, leftAlignment);
                if (numberOfNewLine <= 1)
                {
                    intro += (20 * numberOfNewLine);
                }
                else
                {
                    intro += (20 * numberOfNewLine) - fontInfo.MeasureString("Country List", format1).Height;
                }

                if (note.Length != 0)
                {
                    page.Canvas.DrawString("Notes   : " + note, fontInfo, brush1, 0, intro, leftAlignment);
                }
                intro += 20;
                page.Canvas.DrawString("Date  : " + DateTime.Now, fontInfo, brush1, 0, intro, leftAlignment);
                return(true);
            }
            catch
            {
                Exception.ThrowExc.Instance.ErrorMessage(Const.Constants.ERROR_WHILE_CREATING);
                return(false);
            }
        }
 void table_EndCellLayout(object sender, EndCellLayoutEventArgs args)
 {
     if (args.RowIndex == 1 && args.CellIndex == 1)
     {
         PdfImage image = PdfImage.FromFile("../../../../../../Data/E-iceblueLogo.png");
         float    x     = (args.Bounds.Width - image.PhysicalDimension.Width) / 2 + args.Bounds.X;
         float    y     = (args.Bounds.Height - image.PhysicalDimension.Height) / 2 + args.Bounds.Y;
         args.Graphics.DrawImage(image, x, y);
     }
 }
        private void DrawImage(PdfPageBase page)
        {
            //Load an image
            PdfImage image  = PdfImage.FromFile(@"..\..\..\..\..\..\Data\ChartImage.png");
            float    width  = image.Width * 0.75f;
            float    height = image.Height * 0.75f;
            float    x      = (page.Canvas.ClientSize.Width - width) / 2;

            //Draw the image
            page.Canvas.DrawImage(image, x, 60, width, height);
        }
Beispiel #28
0
        private void ExportOptions_HeaderFooterExporting(object sender, PdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;
            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 38);

            header.Graphics.DrawImage(PdfImage.FromFile(@"..\..\Resources\Header.jpg"), 155, 5, width / 3f, 34);
            e.PdfDocumentTemplate.Top = header;
            PdfPageTemplateElement footer = new PdfPageTemplateElement(width, 30);

            footer.Graphics.DrawImage(PdfImage.FromFile(@"..\..\Resources\Footer.jpg"), 0, 0);
            e.PdfDocumentTemplate.Bottom = footer;
        }
Beispiel #29
0
        private static void PdfHeaderFooterEventHandler(object sender, TreeGridPdfHeaderFooterEventArgs e)
        {
            var width = e.PdfPage.GetClientSize().Width;
            PdfPageTemplateElement header = new PdfPageTemplateElement(width, 38);

            header.Graphics.DrawImage(PdfImage.FromFile(@"Assets/treegrid/Header.png"), 155, 5, width / 3f, 34);
            e.PdfDocumentTemplate.Top = header;
            PdfPageTemplateElement footer = new PdfPageTemplateElement(width, 30);

            footer.Graphics.DrawImage(PdfImage.FromFile(@"Assets/treegrid/Footer.png"), 0, 0);
            e.PdfDocumentTemplate.Bottom = footer;
        }
Beispiel #30
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Create one section
            PdfSection section = doc.Sections.Add();

            //Load an image
            PdfImage image       = PdfImage.FromFile(@"..\..\..\..\..\..\Data\ChartImage.png");
            float    imageWidth  = image.PhysicalDimension.Width / 2;
            float    imageHeight = image.PhysicalDimension.Height / 2;

            foreach (PdfBlendMode mode in Enum.GetValues(typeof(PdfBlendMode)))
            {
                PdfPageBase page      = section.Pages.Add();
                float       pageWidth = page.Canvas.ClientSize.Width;
                float       y         = 0;

                //Title
                y = y + 15;
                PdfBrush        brush  = new PdfSolidBrush(Color.OrangeRed);
                PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
                PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);
                String          text   = String.Format("Transparency Blend Mode: {0}", mode);
                page.Canvas.DrawString(text, font, brush, pageWidth / 2, y, format);
                SizeF size = font.MeasureString(text, format);
                y = y + size.Height + 25;

                page.Canvas.DrawImage(image, 0, y, imageWidth, imageHeight);
                page.Canvas.Save();
                float d = (page.Canvas.ClientSize.Width - imageWidth) / 5;
                float x = d;
                y = y + d / 2 + 40;
                for (int i = 0; i < 5; i++)
                {
                    float alpha = 1.0f / 6 * (5 - i);
                    page.Canvas.SetTransparency(alpha, alpha, mode);
                    page.Canvas.DrawImage(image, x, y, imageWidth, imageHeight);
                    x = x + d;
                    y = y + d / 2 + 40;
                }
                page.Canvas.Restore();
            }

            //Save the document
            doc.SaveToFile("Transparency.pdf");
            doc.Close();

            //Launch the Pdf file
            PDFDocumentViewer("Transparency.pdf");
        }