示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            Image img = Image.FromFile(@"..\..\..\..\..\..\Data\Background.png");
            page.BackgroundImage = img;

            //Draw table
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("ImageWaterMark.pdf");
        }
示例#2
0
        // Layout, Styling Operationen

        public void setMarginForA4Document(float valueTopBottom, float valueLeftRight)
        {
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            margin        = new PdfMargins();
            margin.Top    = unitCvtr.ConvertUnits(valueTopBottom, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(valueLeftRight, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            PdfPageTemplateElement leftSpace = new PdfPageTemplateElement(margin.Left, PdfPageSize.A4.Height);

            pdf.Template.Left = leftSpace;
            PdfPageTemplateElement topSpace = new PdfPageTemplateElement(PdfPageSize.A4.Width, margin.Top);

            topSpace.Foreground = true;
            pdf.Template.Top    = topSpace;
            PdfPageTemplateElement rightSpace = new PdfPageTemplateElement(margin.Right, PdfPageSize.A4.Height);

            pdf.Template.Right = rightSpace;
            PdfPageTemplateElement bottomSpace = new PdfPageTemplateElement(PdfPageSize.A4.Width, margin.Bottom);

            bottomSpace.Foreground = true;
            pdf.Template.Bottom    = bottomSpace;
        }
示例#3
0
        private bool CreateReportPdf(string docFile, string pdfFileExport)
        {
            try
            {
                Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();

                PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
                PdfMargins       margin   = new PdfMargins();
                margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
                margin.Bottom = margin.Top;
                margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
                margin.Right  = margin.Left;

                PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);

                String rtf = System.IO.File.ReadAllText(docFile);
                page.LoadFromRTF(rtf, page.Canvas.ClientSize.Width, true);

                pdf.SaveToFile(pdfFileExport);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            DrawCover(doc.Sections.Add(), margin);
            DrawContent(doc.Sections.Add(), margin);
            DrawPageNumber(doc.Sections[1], margin, 1, doc.Sections[1].Pages.Count);

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

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

            doc.DocumentInformation.Author = "Spire.Pdf";

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

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

            section.PageSettings.Size    = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

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

            //Draw automatic fields
            DrawAutomaticField(page);

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

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

            //Load the document from disk.
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\AddSeamSeals.pdf");

            PdfUnitConvertor convert  = new PdfUnitConvertor();
            PdfPageBase      pageBase = null;

            //Get the segmented seal image.
            Image[] images = GetImage(doc.Pages.Count);
            float   x      = 0;
            float   y      = 0;

            //Draw the picture to the designated location on the PDF page.
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                pageBase = doc.Pages[i];
                x        = pageBase.Size.Width - convert.ConvertToPixels(images[i].Width, PdfGraphicsUnit.Point) + 40;
                y        = pageBase.Size.Height / 2;
                pageBase.Canvas.DrawImage(PdfImage.FromImage(images[i]), new PointF(x, y));
            }

            String result = "AddSeamSeals_out.pdf";

            //Save the Pdf file.
            doc.SaveToFile(result);

            //Launch the Pdf file.
            PDFDocumentViewer(result);
        }
示例#7
0
        /// <summary>
        /// 生成报表文件
        /// </summary>
        /// <param name="logpath">报表路径</param>
        /// <param name="log">报表内容</param>
        public static string WriteLogs(string logpath, string log)
        {
            string _Date = DateTime.Now.ToString("yyyy-MM-dd-hh-mm");

            Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument();

            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margins  = new PdfMargins();
            PdfPageBase      page     = document.Pages.Add(PdfPageSize.A3, margins);

            PdfTrueTypeFont TitleFont = new PdfTrueTypeFont(new Font("宋体", 30f), true);

            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", 14f), true);
            PdfPen          pen  = new PdfPen(Color.Black);

            string text = log
                          + "\r\n\r\n" +
                          "检测时间:" + DateTime.Now;

            page.Canvas.DrawString("检测报告", TitleFont, pen, 350, 10);
            page.Canvas.DrawString(text, font, pen, 100, 50);

            string path = logpath + "\\" + _Date + ".pdf";

            document.SaveToFile(path);
            return(path);
        }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            Image       img  = Image.FromFile(@"..\..\..\..\..\..\Data\Background.png");

            page.BackgroundImage = img;

            //Draw table
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("ImageWaterMark.pdf");
        }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF             rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            String  formatted
                = "Beverages\nCondiments\nConfections\nDairy Products\nGrains/Cereals\nMeat/Poultry\nProduce\nSeafood";

            PdfList list = new PdfList(formatted);

            list.Font       = font;
            list.Indent     = 8;
            list.TextIndent = 5;
            list.Brush      = brush;
            PdfLayoutResult result = list.Draw(page, 0, y);

            y = result.Bounds.Bottom;

            PdfSortedList sortedList = new PdfSortedList(formatted);

            sortedList.Font       = font;
            sortedList.Indent     = 8;
            sortedList.TextIndent = 5;
            sortedList.Brush      = brush;
            sortedList.Draw(page, 0, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleList.pdf");
        }
示例#10
0
        private byte[] GetPdfFile(string header, string body, string footer, string fileName, string defaultFont, float defaultSize)
        {
            //create new PDF document
            PdfDocument doc = new PdfDocument();
            //set margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(4.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;
            //apply template in PDF document
            SetDocumentTemplate(doc, PdfPageSize.A4, margin, header, defaultFont, defaultSize);

            int         pageNum = 1;
            PdfPageBase page    = doc.Pages.Add();

            doc.Pages.Add();

            AddFooterToPage(doc, pageNum.ToString(), ref page, PdfPageSize.A4.Width, "Callibri");

            //Save pdf file.
            var root = HttpContext.Current.Server.MapPath(fileName);

            doc.SaveToFile(root);
            doc.Close();
            return(File.ReadAllBytes(root));
        }
示例#11
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.<br>
            PdfDocument doc = new PdfDocument();
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;
            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            float       y    = 10;
            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            String[] data
                =
                {
                "Name;Capital;Continent;Area;Population",
                "Argentina;Buenos Aires;South America;2777815;32300003",
                "Bolivia;La Paz;South America;1098575;7300000",
                "Brazil;Brasilia;South America;8511196;150400000",
                "Canada;Ottawa;North America;9976147;26500000",
                };
            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfTable table = new PdfTable();

            table.Style.CellPadding    = 2;
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader     = true;
            table.DataSource           = dataSource;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            y = y + result.Bounds.Height + 5;
            PdfBrush        brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 9f));

            page.Canvas.DrawString(String.Format("* {0} countries in the list.", data.Length - 1), font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("SimpleTable.pdf");
        }
示例#12
0
        internal static void Generate_receipt(List <string> SelectedImages, string ImageFileName, string taxinvoicenumber)
        {
            ///Create a pdf document
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            PdfMargins margin = new PdfMargins();

            margin.Top    = InPoints(0.5f);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;

            //Create one page
            PdfPageBase page = doc.Pages.Add(new SizeF(InPoints(float.Parse(ConfigurationManager.AppSettings["ReceiptWidth"])),
                                                       InPoints(float.Parse(ConfigurationManager.AppSettings["ReceiptHeight"]))), margin);
            //PdfFont font12 = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfFont font10 = new PdfFont(PdfFontFamily.Helvetica, 10f);
            //PdfFont font8 = new PdfFont(PdfFontFamily.Helvetica, 8f);
            PdfSolidBrush   brush1          = new PdfSolidBrush(Color.Black);
            PdfStringFormat leftAlignment   = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            PdfStringFormat rightAlignment  = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            string total = Math.Round(
                (((Convert.ToDouble(ConfigurationManager.AppSettings["CostValue" + Globals.PrintSelection.ToString()]) *
                   SelectedImages.Count) * Convert.ToDouble(ConfigurationManager.AppSettings["GSTValue"]) /
                  100) +
                 (Convert.ToDouble(ConfigurationManager.AppSettings["CostValue" + Globals.PrintSelection.ToString()]) * SelectedImages.Count)
                ), 2
                ).ToString();

            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line1"], font10, brush1, page.Canvas.ClientSize.Width, 10, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line2"] + taxinvoicenumber, font10, brush1, page.Canvas.ClientSize.Width, 25, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line3"] + SelectedImages.Count + "/-", font10, brush1, page.Canvas.ClientSize.Width, 40, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line4"] + ConfigurationManager.AppSettings["CostValue"] + "/-"
                                   , font10, brush1, page.Canvas.ClientSize.Width, 55, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line5"] +
                                   ConfigurationManager.AppSettings["GSTValue"] + "%", font10, brush1, page.Canvas.ClientSize.Width, 70, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line6"], font10, brush1, page.Canvas.ClientSize.Width, 85, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line7"] + total + "/-", font10, brush1, page.Canvas.ClientSize.Width, 100, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line8"], font10, brush1, page.Canvas.ClientSize.Width, 120, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line9"], font10, brush1, page.Canvas.ClientSize.Width, 130, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line10"], font10, brush1, page.Canvas.ClientSize.Width, 140, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line11"], font10, brush1, page.Canvas.ClientSize.Width, 155, rightAlignment);


            //Save the document
            doc.SaveToFile(Globals.receiptDir + ImageFileName);
            doc.SaveToFile(ConfigurationManager.AppSettings["ReceiptBackupDir"] + "\\" + ImageFileName);
            doc.Close();

            //Launch the Pdf file
            if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic")
            {
                logger.Log(NLog.LogLevel.Info, "Inside Generate_receipt function.");
                PDFDocumentViewer(Globals.receiptDir + ImageFileName);
            }
        }
示例#13
0
 public MarginProvider(float topMargin, float leftMargin)
 {
     PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
     this.Margins = new PdfMargins();
     this.Margins.Top = unitCvtr.ConvertUnits(topMargin, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
     this.Margins.Bottom = this.Margins.Top;
     this.Margins.Left = unitCvtr.ConvertUnits(leftMargin, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
     this.Margins.Right = this.Margins.Left;
 }
示例#14
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Create PdfUnitConvertor to convert the unit
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            //Setting for page margin
            PdfMargins margin = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(2.0f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

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

            //Set "A4" for Pdf page
            section.PageSettings.Size = PdfPageSize.A4;

            //Set page margin
            section.PageSettings.Margins = margin;

            //Set rotating angle
            section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;

            //Add the page
            PdfPageBase page = section.Pages.Add();

            //Define a PdfBrush
            PdfBrush brush = PdfBrushes.Black;

            //Define a font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 13f, FontStyle.Bold), true);

            //Set the string format
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);

            //Set the position for drawing
            float x = 0;
            float y = 50;

            //Text string
            string specification = "The sample demonstrates how to rotate page when creating a PDF document.";

            //Draw text string on page canvas
            page.Canvas.DrawString(specification, font, brush, x, y, format);

            String result = "RotateNewPDF_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
示例#15
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            //Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            //Title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 13f, FontStyle.Bold | FontStyle.Italic), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            float           y       = 50;
            string          s       = "The sample demonstrates how to add annotations in PDF document.";

            page.Canvas.DrawString(s, font1, brush1, 0, y - 5, format1);
            y = y + font1.MeasureString(s, format1).Height;
            y = y + 15;


            y = AddDocumentLinkAnnotation(page, y);

            y = y + 6;
            y = AddFileLinkAnnotation(page, y);

            y = y + 6;
            y = AddFreeTextAnnotation(page, y);

            y = y + 6;
            y = AddLineAnnotation(page, y);

            y = y + 6;
            y = AddTextMarkupAnnotation(page, y);

            y = y + 6;
            y = AddPopupAnnotation(page, y);

            y = y + 6;
            y = AddRubberStampAnnotation(page, y);

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

            //Launch the Pdf file
            PDFDocumentViewer("Annotation.pdf");
        }
示例#16
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            
            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            String formatted
                = "Beverages\nCondiments\nConfections\nDairy Products\nGrains/Cereals\nMeat/Poultry\nProduce\nSeafood";

            PdfList list = new PdfList(formatted);
            list.Font = font;
            list.Indent = 8;
            list.TextIndent = 5;
            list.Brush = brush;
            PdfLayoutResult result = list.Draw(page, 0, y);
            y = result.Bounds.Bottom;

            PdfSortedList sortedList = new PdfSortedList(formatted);
            sortedList.Font = font;
            sortedList.Indent = 8;
            sortedList.TextIndent = 5;
            sortedList.Brush = brush;
            sortedList.Draw(page, 0, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleList.pdf");
        }
示例#17
0
        private void AddFooterToPage(PdfDocument doc, string pageNum, ref PdfPageBase page1, float pageWidth, string fontName)
        {
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            var pageSize = PdfPageSize.A4;

            PdfPageTemplateElement bottomSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Bottom - 10);

            bottomSpace.Foreground = true;
            doc.Template.Bottom    = bottomSpace;

            PdfTrueTypeFont pageNormalFont = new PdfTrueTypeFont(new Font(fontName, 6f, FontStyle.Regular));
            PdfPen          linePen1       = new PdfPen(Color.Black, 0.5f);
            //draw footer label
            float y = pageNormalFont.Height + 1;

            bottomSpace.Graphics.DrawLine(linePen1, 0, y, pageSize.Width - 1, y);
            y = y + 1;


            PdfPageNumberField pageNumber      = new PdfPageNumberField();
            PdfPageCountField  pageCount       = new PdfPageCountField();
            PdfCompositeField  pageNumberLabel = new PdfCompositeField();

            pageNumberLabel.AutomaticFields
                = new PdfAutomaticField[] { pageNumber, pageCount };
            pageNumberLabel.Brush        = PdfBrushes.Black;
            pageNumberLabel.Font         = pageNormalFont;
            pageNumberLabel.StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            pageNumberLabel.Text         = "Page {0}";
            pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - MARGIN_FROM_RIGHT, y);

            //footerY = footerY + 6;
            var    brush2  = new PdfSolidBrush(Color.Black);
            var    font2   = new PdfTrueTypeFont(new Font(fontName, 6f, FontStyle.Regular));
            var    format2 = new PdfStringFormat(PdfTextAlignment.Left);
            string text    = "Proof Of Delivery - Generated by Linfox Australia Pty Ltd.";

            bottomSpace.Graphics.DrawString(text, font2, brush2, 0, y, format2);
            text = "Page " + pageNumberLabel.Text;
            //bottomSpace.Graphics.DrawString(text, font2, brush2, pageWidth - 30, y, format2);

            string tz = "";

            text = "Generated On: " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss ") + tz;
            bottomSpace.Graphics.DrawString(text, font2, brush2, 0, y + 10, format2);
        }
示例#18
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            PdfDocument      doc      = new PdfDocument();
            PdfImage         pdfImage = PdfImage.FromImage(documentWrapper.Image);
            PdfUnitConvertor uinit    = new PdfUnitConvertor();
            SizeF            pageSize = uinit.ConvertFromPixels(documentWrapper.Image.Size, PdfGraphicsUnit.Point);
            PdfPageBase      page     = doc.Pages.Add(pageSize, new PdfMargins(0f));

            page.Canvas.DrawImage(pdfImage, new PointF(0, 0));
            doc.SaveToFile(path.Insert(path.LastIndexOf(".pdf"), "_converted"));
            isSaved = true;
        }
        public static void pdfsettings()
        {
            path = @"C:\Users\Public\Documents\RadianLabs\ReliefText\TeacherID-" + al5[relindex] + "_Date-" + date + "_Relief.pdf";
            PdfUnitConvertor uc   = new PdfUnitConvertor();;
            PdfMargins       marg = new PdfMargins();;
            PdfPageBase      page;
            PdfDocument      pdfd;
            float            y = 10;
            PdfBrush         bru;
            PdfTrueTypeFont  fon;
            PdfStringFormat  format;

            pdfd        = new PdfDocument();
            marg.Top    = uc.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            marg.Bottom = marg.Top;
            marg.Left   = uc.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            marg.Right  = marg.Left;
            page        = pdfd.Pages.Add(PdfPageSize.A4, marg);
            bru         = PdfBrushes.Black;
            fon         = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            format      = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString(textname, fon, bru, page.Canvas.ClientSize.Width / 2, y, format);
            y = y + fon.MeasureString(textname, format).Height;
            y = y + 5;
            String[]   pdfdata    = { "Period;Class", "One;" + relprinter[0] + "", "Two;" + relprinter[1] + "", "Three;" + relprinter[2] + "", "Four;" + relprinter[3] + "", "Five;" + relprinter[4] + "", "Six;" + relprinter[5] + "", "Seven;" + relprinter[6] + "", "Eight;" + relprinter[7] + "" };
            String[][] dataSource = new String[pdfdata.Length][];
            for (i = 0; i < pdfdata.Length; i++)
            {
                dataSource[i] = pdfdata[i].Split(';');
            }
            PdfTable pdftable = new PdfTable();

            pdftable.Style.CellPadding    = 2;
            pdftable.Style.HeaderSource   = PdfHeaderSource.Rows;
            pdftable.Style.HeaderRowCount = 1;
            pdftable.Style.ShowHeader     = true;
            pdftable.DataSource           = dataSource;
            PdfLayoutResult pdfresult = pdftable.Draw(page, new PointF(0, y));
            PdfBrush        bru2      = PdfBrushes.Gray;
            PdfTrueTypeFont fon2      = new PdfTrueTypeFont(new Font("Arial", 9f));

            page.Canvas.DrawString(String.Format("{0}", pdfdata.Length - 1), fon2, bru2, 5, y);
            try
            {
                pdfd.SaveToFile(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            pdfd.Close();
        }
示例#20
0
        private PdfDocument BitmapToPdf(Bitmap bitmap)
        {
            PdfDocument doc      = new PdfDocument();
            PdfImage    pdfimage = PdfImage.FromImage(bitmap);

            PdfUnitConvertor uinit    = new PdfUnitConvertor();
            SizeF            pageSize = uinit.ConvertFromPixels(bitmap.Size, PdfGraphicsUnit.Point);
            PdfPageBase      page     = doc.Pages.Add(pageSize, new PdfMargins(0f));

            page.Canvas.DrawImage(pdfimage, new PointF(0, 0));

            return(doc);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Create PdfUnitConvertor to convert the unit
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            //Setting for page margin
            PdfMargins margin = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            //Add one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            //Define a PdfBrush
            PdfBrush brush1 = PdfBrushes.Black;

            //Define a font
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 13f, FontStyle.Bold), true);

            //Set the string format
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);

            //Set the position for drawing
            float x = 0;
            float y = 50;

            //Text string
            string specification = "The sample demonstrates how to create a file link in PDF document.";

            //Draw text string on page canvas
            page.Canvas.DrawString(specification, font1, brush1, x, y, format1);

            //Use MeasureString to get the height of string
            y = y + font1.MeasureString(specification, format1).Height + 10;

            //Add file link annotation
            AddFileLinkAnnotation(page, y);

            String result = "FileLinkAnnotation_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
示例#22
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoColumnLeft;

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

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

            section.PageSettings.Size    = PdfPageSize.A4;
            section.PageSettings.Margins = new PdfMargins(0);
            SetSectionTemplate(section, PdfPageSize.A4, margin, "Section 1");

            //Create one page
            PdfNewPage page = section.Pages.Add();

            //Draw page
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

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

            //Launch the Pdf file
            PDFDocumentViewer("Template.pdf");
        }
示例#23
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load an existing pdf from disk
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\Sample.pdf");

            //Get the first page of the loaded PDF file
            PdfPageBase page = doc.Pages[0];

            //Get the width of page based on "point"
            float pointWidth = page.Size.Width;

            //Get the height of page
            float pointHeight = page.Size.Height;

            //Create PdfUnitConvertor to convert the unit
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            //Convert the size with "pixel"
            float pixelWidth  = unitCvtr.ConvertUnits(pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
            float pixelHeight = unitCvtr.ConvertUnits(pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);

            //Convert the size with "inch"
            float inchWidth  = unitCvtr.ConvertUnits(pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Inch);
            float inchHeight = unitCvtr.ConvertUnits(pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Inch);

            //Convert the size with "centimeter"
            float centimeterWidth  = unitCvtr.ConvertUnits(pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);
            float centimeterHeight = unitCvtr.ConvertUnits(pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);

            //Create StringBuilder to save
            StringBuilder content = new StringBuilder();


            //Add pointSize string to StringBuilder
            content.AppendLine("The page size of the file is (width: " + pointWidth + "pt, height: " + pointHeight + "pt).");
            content.AppendLine("The page size of the file is (width: " + pixelWidth + "pixel, height: " + pixelHeight + "pixel).");
            content.AppendLine("The page size of the file is (width: " + inchWidth + "inch, height: " + inchHeight + "inch).");
            content.AppendLine("The page size of the file is (width: " + centimeterWidth + "cm, height: " + centimeterHeight + "cm.)");

            String output = "GetPageSize_out.txt";

            //Save them to a txt file
            File.WriteAllText(output, content.ToString());

            //Launch the file
            DocumentViewer(output);
        }
        public void Open(string filename)
        {
            var document = new PdfDocument();

            document.LoadFromFile(filename);
            var bmp = document.SaveAsImage(0);

            Source = GetImageStream(bmp);

            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            float            widthMM  = unitCvtr.ConvertUnits(document.Pages[0].Size.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Millimeter);
            float            heightMM = unitCvtr.ConvertUnits(document.Pages[0].Size.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Millimeter);

            DocumentSize = new SizeF(widthMM, heightMM);
        }
示例#25
0
        internal static void SetPageMarginGeneratePDF_ImageRatio4x3_A5(string ImageFileName, PdfImage img1, PdfImage img2,
                                                                       Globals.AspectRatio aspectRatioImage1 = Globals.AspectRatio.S4x3, Globals.AspectRatio aspectRatioImage2 = Globals.AspectRatio.S4x3)
        {
            float MARGINTOP_BOTTOM = 0.75f; float MARGINLEFT_RIGHT = 1.25f;
            float DISTANCE_BTW_IMAGES = 0.5F;

            ///Create a pdf document
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = PrintIO.InPoints(MARGINTOP_BOTTOM);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            //TODO: Add margins in global settings xml file.
            margin.Left  = PrintIO.InPoints(MARGINLEFT_RIGHT); //unitCvtr.ConvertUnits(MARGINLEFT_RIGHT, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float A4Height = unitCvtr.ConvertUnits(PdfPageSize.A4.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);
            float A4Width  = unitCvtr.ConvertUnits(PdfPageSize.A4.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);

            //After margin
            float A4PostMarginWidth = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins

            //Adjust width, height with 4:3 ratio in PDF points :
            float A4PostMarginWidthPts4x3  = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins
            float A4PostMarginHeightPts4x3 = A4PostMarginWidthPts4x3 * 0.75f;          // height = 3/4 * width


            //TransformText(page);
            DrawImagesInPage_A5(img1, img2, page, A4PostMarginWidthPts4x3, A4PostMarginHeightPts4x3,
                                DISTANCE_BTW_IMAGES, aspectRatioImage1, aspectRatioImage2);
            //TransformImage(page);

            //Save the document
            doc.SaveToFile(ImageFileName);
            doc.Close();

            if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic")
            {
                PrintIO.PDFDocumentViewer(ImageFileName);
            }
        }
示例#26
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoColumnLeft;

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = new PdfMargins(0);
            SetSectionTemplate(section, PdfPageSize.A4, margin, "Section 1");

            // Create one page
            PdfNewPage page = section.Pages.Add();

            //Draw page
            DrawPage(page); 

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Template.pdf");
        }
示例#27
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            y = AddDocumentLinkAnnotation(page, y);

            y = y + 2;
            y = AddFileLinkAnnotation(page, y);

            y = y + 2;
            y = AddFreeTextAnnotation(page, y);

            y = y + 2;
            y = AddLineAnnotation(page, y);

            y = y + 2;
            y = AddTextMarkupAnnotation(page, y);

            y = y + 2;
            y = AddPopupAnnotation(page, y);

            y = y + 2;
            y = AddRubberStampAnnotation(page, y);


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

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

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            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("Spire.Pdf Demo",
                                      new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 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));

            //Draw the page
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("TextWaterMark.pdf");
        }
示例#29
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            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("Spire.Pdf Demo",
                new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 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));

            //Draw the page
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("TextWaterMark.pdf");
        }
示例#30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var fileList = new List <string>();

            fileList.AddRange(Directory.GetFiles("C:\\!Files"));

            var start = DateTime.Now;


            var docs = new List <PdfDocument>();

            var merged = new PdfDocument();

            fileList.ForEach(file => docs.Add(new PdfDocument(file)));

            docs.ForEach(doc => merged.AppendPage(doc));

            var unitCvtr         = new PdfUnitConvertor();
            var verticalMargin   = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            var horizontalMargin = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            var margin           = new PdfMargins()
            {
                Top    = verticalMargin,
                Bottom = verticalMargin,
                Left   = horizontalMargin,
                Right  = horizontalMargin
            };

            DrawPageNumber(merged.Pages, margin, 1, merged.Pages.Count);

            var pageCount = merged.Pages.Count;

            merged.SaveToFile("C:\\!Files\\merged.pdf");
            var finished = DateTime.Now - start;

            //write
            Console.WriteLine($@"Merged total of {pageCount} pages from {fileList.Count} files in {finished.TotalSeconds} seconds");
        }
示例#31
0
        private void SaveAsButton_Click(object sender, EventArgs e)
        {
            PdfDocument      doc      = new PdfDocument();
            PdfImage         pdfImage = PdfImage.FromImage(documentWrapper.Image);
            PdfUnitConvertor uinit    = new PdfUnitConvertor();
            SizeF            pageSize = uinit.ConvertFromPixels(documentWrapper.Image.Size, PdfGraphicsUnit.Point);
            PdfPageBase      page     = doc.Pages.Add(pageSize, new PdfMargins(0f));

            page.Canvas.DrawImage(pdfImage, new PointF(0, 0));
            using var sfd        = new SaveFileDialog();
            sfd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
            sfd.RestoreDirectory = true;
            sfd.CheckPathExists  = true;
            sfd.AddExtension     = true;
            sfd.DefaultExt       = "pdf";
            sfd.Filter           = "PDF|*.pdf";
            var result = sfd.ShowDialog();

            if (result == DialogResult.OK)
            {
                doc.SaveToFile(sfd.FileName);
            }
            isSaved = true;
        }
示例#32
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            DrawCover(doc.Sections.Add(), margin);
            DrawContent(doc.Sections.Add(), margin);
            DrawPageNumber(doc.Sections[1], margin, 1, doc.Sections[1].Pages.Count);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Pagination.pdf");
        }
示例#33
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.DocumentInformation.Author = "Spire.Pdf";

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            for (int i = 1; i < 4; i++)
            {
                //create section
                PdfSection section = doc.Sections.Add();
                section.PageSettings.Size = PdfPageSize.A4;
                section.PageSettings.Margins = margin;

                for (int j = 0; j < i; j++)
                {
                    // Create one page
                    PdfPageBase page = section.Pages.Add();
                    DrawAutomaticField(page);
                }
            }

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

            //Launching the Pdf file.
            PDFDocumentViewer("AutomaticField.pdf");
        }
示例#34
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(0));

            float y = 0;

            //title
            y = DrawPageTitle(page, y);

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument     xpathDoc     = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                int fieldIndex = 0;
                foreach (XPathNavigator sectionNode in sectionNodes)
                {
                    //draw section label
                    String sectionLabel = sectionNode.GetAttribute("name", "");
                    y = DrawFormSection(sectionLabel, page, y);

                    XPathNodeIterator fieldNodes = sectionNode.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        y = DrawFormField(fieldNode, doc.Form, page, y, fieldIndex++);
                    }
                }
            }

            //draw button
            y = y + 10;
            float          buttonWidth  = 80;
            float          buttonX      = (page.Canvas.ClientSize.Width - buttonWidth) / 2;
            RectangleF     buttonBounds = new RectangleF(buttonX, y, buttonWidth, 16f);
            PdfButtonField button       = new PdfButtonField(page, "submit");

            button.Text   = "Submit";
            button.Bounds = buttonBounds;
            PdfSubmitAction submitAction = new PdfSubmitAction("http://www.e-iceblue.com");

            button.Actions.MouseUp = submitAction;
            doc.Form.Fields.Add(button);

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

            //Launching the Pdf file.
            PDFDocumentViewer("FormField.pdf");
        }
示例#35
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

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

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Attachment", format1).Height;
            y = y + 5;

            //attachment
            PdfAttachment attachment = new PdfAttachment("Header.png");
            attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Header.png");
            attachment.Description = "Page header picture of demo.";
            attachment.MimeType = "image/png";
            doc.Attachments.Add(attachment);

            attachment = new PdfAttachment("Footer.png");
            attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Footer.png");
            attachment.Description = "Page footer picture of demo.";
            attachment.MimeType = "image/png";
            doc.Attachments.Add(attachment);

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            PointF location = new PointF(0, y);
            String label = "Sales Report Chart";
            byte[] data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            SizeF size = font2.MeasureString(label);
            RectangleF bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation1
                = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data);
            annotation1.Color = Color.Teal;
            annotation1.Flags = PdfAnnotationFlags.ReadOnly;
            annotation1.Icon = PdfAttachmentIcon.Graph;
            annotation1.Text = "Sales Report Chart";
            (page as PdfNewPage).Annotations.Add(annotation1);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Science Personification Boston";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation2
                = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data);
            annotation2.Color = Color.Orange;
            annotation2.Flags = PdfAnnotationFlags.NoZoom;
            annotation2.Icon = PdfAttachmentIcon.PushPin;
            annotation2.Text = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation2);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Picture of Science";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Wikipedia_Science.png");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation3
                = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data);
            annotation3.Color = Color.SaddleBrown;
            annotation3.Flags = PdfAnnotationFlags.Locked;
            annotation3.Icon = PdfAttachmentIcon.Tag;
            annotation3.Text = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation3);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Hawaii Killer Font";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Hawaii_Killer.ttf");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation4
                = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data);
            annotation4.Color = Color.CadetBlue;
            annotation4.Flags = PdfAnnotationFlags.NoRotate;
            annotation4.Icon = PdfAttachmentIcon.Paperclip;
            annotation4.Text = "Hawaii Killer Font, from http://www.1001freefonts.com";
            (page as PdfNewPage).Annotations.Add(annotation4);
            y = y + size.Height + 2;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Attachment.pdf");
        }
示例#36
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            PdfSection section = doc.Sections.Add();
            section.PageSettings.Margins = margin;
            section.PageSettings.Size = PdfPageSize.A4;

            // Create one page
            PdfPageBase page = section.Pages.Add();
            float y = 10;

            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true);
            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);

            //draw Codabar
            PdfTextWidget text = new PdfTextWidget();
            text.Font = font1;
            text.Text = "Codabar:";
            PdfLayoutResult result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
            barcode1.BarcodeToTextGapHeight = 1f;
            barcode1.EnableCheckDigit = true;
            barcode1.ShowCheckDigit = true;
            barcode1.TextDisplayLocation = TextLocation.Bottom;
            barcode1.TextColor = Color.Blue;
            barcode1.Draw(page, new PointF(0, y));
            y = barcode1.Bounds.Bottom + 5;


            //draw Code11Barcode
            text.Text = "Code11:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
            barcode2.BarcodeToTextGapHeight = 1f;
            barcode2.TextDisplayLocation = TextLocation.Bottom;
            barcode2.TextColor = Color.Blue;
            barcode2.Draw(page, new PointF(0, y));
            y = barcode2.Bounds.Bottom + 5;


            //draw Code128-A
            text.Text = "Code128-A:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode128ABarcode barcode3 = new PdfCode128ABarcode("HELLO 00-123");
            barcode3.BarcodeToTextGapHeight = 1f;
            barcode3.TextDisplayLocation = TextLocation.Bottom;
            barcode3.TextColor = Color.Blue;
            barcode3.Draw(page, new PointF(0, y));
            y = barcode3.Bounds.Bottom + 5;


            //draw Code128-B
            text.Text = "Code128-B:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode128BBarcode barcode4 = new PdfCode128BBarcode("Hello 00-123");
            barcode4.BarcodeToTextGapHeight = 1f;
            barcode4.TextDisplayLocation = TextLocation.Bottom;
            barcode4.TextColor = Color.Blue;
            barcode4.Draw(page, new PointF(0, y));
            y = barcode4.Bounds.Bottom + 5;


            //draw Code32
            text.Text = "Code32:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode32Barcode barcode5 = new PdfCode32Barcode("16273849");
            barcode5.BarcodeToTextGapHeight = 1f;
            barcode5.TextDisplayLocation = TextLocation.Bottom;
            barcode5.TextColor = Color.Blue;
            barcode5.Draw(page, new PointF(0, y));
            y = barcode5.Bounds.Bottom + 5;

            page = section.Pages.Add();
            y = 10;


            //draw Code39
            text.Text = "Code39:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode39Barcode barcode6 = new PdfCode39Barcode("16-273849");
            barcode6.BarcodeToTextGapHeight = 1f;
            barcode6.TextDisplayLocation = TextLocation.Bottom;
            barcode6.TextColor = Color.Blue;
            barcode6.Draw(page, new PointF(0, y));
            y = barcode6.Bounds.Bottom + 5;


            //draw Code39-E
            text.Text = "Code39-E:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode39ExtendedBarcode barcode7 = new PdfCode39ExtendedBarcode("16-273849");
            barcode7.BarcodeToTextGapHeight = 1f;
            barcode7.TextDisplayLocation = TextLocation.Bottom;
            barcode7.TextColor = Color.Blue;
            barcode7.Draw(page, new PointF(0, y));
            y = barcode7.Bounds.Bottom + 5;


            //draw Code93
            text.Text = "Code93:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode93Barcode barcode8 = new PdfCode93Barcode("16-273849");
            barcode8.BarcodeToTextGapHeight = 1f;
            barcode8.TextDisplayLocation = TextLocation.Bottom;
            barcode8.TextColor = Color.Blue;
            barcode8.QuietZone.Bottom = 5;
            barcode8.Draw(page, new PointF(0, y));
            y = barcode8.Bounds.Bottom + 5;


            //draw Code93-E
            text.Text = "Code93-E:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode93ExtendedBarcode barcode9 = new PdfCode93ExtendedBarcode("16-273849");
            barcode9.BarcodeToTextGapHeight = 1f;
            barcode9.TextDisplayLocation = TextLocation.Bottom;
            barcode9.TextColor = Color.Blue;
            barcode9.Draw(page, new PointF(0, y));
            y = barcode9.Bounds.Bottom + 5;


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

            //Launching the Pdf file.
            PDFDocumentViewer("Barcode.pdf");
        }
示例#37
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 1;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.Style.RepeatHeader = true;
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select * from parts ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    dataTable.Columns.RemoveAt(1);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for(int i = 0; i < table.Columns.Count; i++)
            {
                if (i == 1)
                {
                    table.Columns[i].Width = width * 0.4f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    table.Columns[i].Width = width * 0.12f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
            y = result.Bounds.Bottom + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* All {0} parts in the list", table.Rows.Count), 
                font2, brush2, 5, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("TableLayout.pdf");
        }
示例#38
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Fly;
            section.PageSettings.Transition.PageDuration = 1;

            PdfNewPage page = section.Pages.Add();
            page.BackgroundColor = Color.Red;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Green;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Blue;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Box;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Split;
            section.PageSettings.Transition.Dimension = PdfTransitionDimension.Vertical;
            section.PageSettings.Transition.Motion = PdfTransitionMotion.Inward;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Transition.pdf");
        }
示例#39
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Name,Capital,Continent,Area,Population from country ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            table.Columns[0].Width = width * 0.24f * width;
            table.Columns[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[1].Width = width * 0.21f * width;
            table.Columns[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[2].Width = width * 0.24f * width;
            table.Columns[2].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[3].Width = width * 0.13f * width;
            table.Columns[3].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            table.Columns[4].Width = width * 0.18f * width;
            table.Columns[4].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString(String.Format("* {0} countries in the list.", table.Rows.Count),
                font2, brush2, 5, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("DataSource.pdf");
        }
示例#40
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create a new documenFt class object.
            pdfDoc = new PdfDocument();
            pdfDoc.ViewerPreferences.HideMenubar  = true;
            pdfDoc.ViewerPreferences.HideWindowUI = true;
            pdfDoc.ViewerPreferences.HideToolbar  = true;
            pdfDoc.ViewerPreferences.FitWindow    = true;

            pdfDoc.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage;
            pdfDoc.PageSettings.Orientation     = PdfPageOrientation.Portrait;
            pdfDoc.PageSettings.Margins.All     = 0;

            //To set coordinates to draw form fields
            RectangleF       bounds = new RectangleF(180, 65, 156, 15);
            PdfUnitConvertor con    = new PdfUnitConvertor();

            PdfImage img = new PdfBitmap(@"..\..\..\..\..\..\..\Common\Images\PDF\Careers.png");

            //Set the page size
            SizeF pageSize = new SizeF(500, 310);

            pdfDoc.PageSettings.Height = pageSize.Height;
            pdfDoc.PageSettings.Width  = pageSize.Width;

            Font    f       = new Font("Calibri", 12f, System.Drawing.FontStyle.Bold);
            PdfFont pdfFont = new PdfTrueTypeFont(f);

            #region First Page
            pdfDoc.Pages.Add();

            PdfPage firstPage = pdfDoc.Pages[0];
            pdfDoc.Pages[0].Graphics.DrawImage(img, 0, 0, pageSize.Width, pageSize.Height);
            pdfDoc.Pages[0].Graphics.DrawString("General Information", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 25, 40);
            pdfDoc.Pages[0].Graphics.DrawString("Education Grade", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 25, 190);

            f       = new Font("Calibri", 10f);
            pdfFont = new PdfTrueTypeFont(f);
            //Create fields in first page.
            pdfDoc.Pages[0].Graphics.DrawString("First Name:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 65);

            //Create text box for firstname.
            CreateTextBox(pdfDoc.Pages[0], "FirstName", "First Name", f, bounds);

            pdfFont = new PdfTrueTypeFont(f);
            pdfDoc.Pages[0].Graphics.DrawString("Last Name:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 83);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;
            //Create text box for lastname.
            CreateTextBox(pdfDoc.Pages[0], "LastName", "Last Name", f, bounds);

            pdfFont = new PdfTrueTypeFont(f);
            pdfDoc.Pages[0].Graphics.DrawString("Email:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 103);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;

            //Create text box for Email.
            CreateTextBox(pdfDoc.Pages[0], "Email", "Email id", f, bounds);

            pdfFont = new PdfTrueTypeFont(f);
            pdfDoc.Pages[0].Graphics.DrawString("Business Phone:", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 123);

            //Set position to draw form fields
            bounds.Y = bounds.Y + 18;

            //Create text box for Business phone.
            CreateTextBox(pdfDoc.Pages[0], "Business", "Business phone", f, bounds);

            pdfFont = new PdfTrueTypeFont(f);
            pdfDoc.Pages[0].Graphics.DrawString("Which position are\nyou applying for?", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 143);

            //Create combo box for Position.
            #region Create ComboBox
            //Set position to draw Combo Box
            bounds.Y = bounds.Y + 24;

            PdfComboBoxField comboBox = new PdfComboBoxField(pdfDoc.Pages[0], "JobTitle");
            comboBox.Bounds      = bounds;
            comboBox.BorderWidth = 1;
            comboBox.BorderColor = new PdfColor(System.Drawing.Color.Gray);

            pdfFont          = new PdfTrueTypeFont(f);
            comboBox.Font    = pdfFont;
            comboBox.ToolTip = "Job Title";


            comboBox.Items.Add(new PdfListFieldItem("Development", "accounts"));
            comboBox.Items.Add(new PdfListFieldItem("Support", "advertise"));
            comboBox.Items.Add(new PdfListFieldItem("Documentation", "agri"));

            pdfDoc.Form.Fields.Add(comboBox);
            #endregion

            pdfDoc.Pages[0].Graphics.DrawString("Highest qualification", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), 25, 217);

            //Create Checkbox box.
            #region Create CheckBox

            f       = new Font("Calibri", 8f);
            pdfFont = new PdfTrueTypeFont(f);;
            //Set position to draw Checkbox
            bounds.Y     = 239;
            bounds.X     = 25;
            bounds.Width = 10;

            bounds.Height = 10;

            // Create a Check Box
            PdfCheckBoxField chb = new PdfCheckBoxField(pdfDoc.Pages[0], "Adegree");

            chb.Font        = pdfFont;
            chb.ToolTip     = "degree";
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(System.Drawing.Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Associate degree", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);
            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb             = new PdfCheckBoxField(pdfDoc.Pages[0], "Bdegree");
            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(System.Drawing.Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Bachelor degree", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "college");

            chb.Font        = pdfFont;
            chb.ToolTip     = "college";
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(System.Drawing.Color.Gray);

            bounds.X += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("College", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.Y += 20;
            bounds.X  = 25;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "pg");

            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(System.Drawing.Color.Gray);
            bounds.X       += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("Post Graduate", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            bounds.X += 90;
            pdfDoc.Form.Fields.Add(chb);
            //Create a Checkbox
            chb = new PdfCheckBoxField(pdfDoc.Pages[0], "mba");

            chb.Font        = pdfFont;
            chb.Bounds      = bounds;
            chb.BorderColor = new PdfColor(System.Drawing.Color.Gray);

            bounds.X += chb.Bounds.Height + 10;

            pdfDoc.Pages[0].Graphics.DrawString("MBA", pdfFont, new PdfSolidBrush(new PdfColor(124, 143, 166)), bounds.X, bounds.Y);

            pdfDoc.Form.Fields.Add(chb);
            #endregion

            # region Create Button
示例#41
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfLinearGradientBrush brush3
                = new PdfLinearGradientBrush(rctg, Color.OrangeRed, Color.Navy, PdfLinearGradientMode.Vertical);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 8f), true);

            PdfOrderedMarker marker1
                = new PdfOrderedMarker(PdfNumberStyle.LowerRoman, new PdfFont(PdfFontFamily.Helvetica, 10f));
            PdfOrderedMarker marker2
                = new PdfOrderedMarker(PdfNumberStyle.Numeric, new PdfFont(PdfFontFamily.Helvetica, 8f));

            PdfSortedList vendorList = new PdfSortedList(font2);
            vendorList.Indent = 0;
            vendorList.TextIndent = 5;
            vendorList.Brush = brush2;
            vendorList.Marker = marker1;
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select VendorNo, VendorName from vendors ";
                command.Connection = conn;

                OleDbCommand command2 = new OleDbCommand();
                command2.CommandText
                    = " select Description from parts where VendorNo = @VendorNo";
                command2.Connection = conn;
                OleDbParameter param = new OleDbParameter("@VendorNo", OleDbType.Double);
                command2.Parameters.Add(param);

                conn.Open();

                OleDbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    double id = reader.GetDouble(0);
                    PdfListItem item = vendorList.Items.Add(reader.GetString(1));
                    PdfSortedList subList = new PdfSortedList(font3);
                    subList.Marker = marker2;
                    subList.Brush = brush3;
                    item.SubList = subList;
                    subList.TextIndent = 20;
                    command2.Parameters[0].Value = id;
                    using (OleDbDataReader reader2 = command2.ExecuteReader())
                    {
                        while (reader2.Read())
                        {
                            subList.Items.Add(reader2.GetString(0));
                        }
                    }
                    String maxNumberLabel = Convert.ToString(subList.Items.Count);
                    subList.Indent = 30 - font3.MeasureString(maxNumberLabel).Width;
                }
            }

            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            vendorList.Draw(page, new PointF(0, y), textLayout);

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

            //Launching the Pdf file.
            PDFDocumentViewer("List.pdf");
        }
示例#42
0
        private PdfPageBase DrawPages(PdfDocument doc)
        {
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Description, OnHand, OnOrder, Cost, ListPrice from parts ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for (int i = 0; i < table.Columns.Count; i++)
            {
                if (i == 0)
                {
                    table.Columns[i].Width = width * 0.40f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    table.Columns[i].Width = width * 0.15f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
            y = result.Bounds.Bottom + 3;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* {0} parts in the list.", table.Rows.Count),
                font2, brush2, 5, y);

            return result.Page;
        }
        private void buttonRun_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFiledialog = new SaveFileDialog();
            saveFiledialog.Filter = "PDF Document (*.pdf)|*.pdf";
            bool? result = saveFiledialog.ShowDialog();
            if (!result.HasValue || !result.Value)
            {
                return;
            }

            //create a pdf document
            PdfDocument document = new PdfDocument();
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            

            //create one page
            PdfPageBase page
                = document.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0,
                PdfPageOrientation.Landscape);
            float y = 0;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1
                = new PdfTrueTypeFont(new Font("Arial", 16f, System.Drawing.FontStyle.Bold), true);
            PdfStringFormat format1
                = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Vendor List", format1).Height;
            y = y + 5;

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            grid.Columns.Add(this.dataGridVendorList.Columns.Count);

            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;

            //header of grid
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font
                = new PdfTrueTypeFont(new Font("Arial", 11f, System.Drawing.FontStyle.Bold), true);
            String[] header = { "Vendor Name", "Address", "City", "State", "Country" };
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            }
            headerRow.Style.BackgroundBrush = PdfBrushes.SeaGreen;

            //datarow of grid
            int rowIndex = 1;
            foreach (Vendor vendor in this.dataSource)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                row.Cells[0].Value = vendor.VendorName;
                row.Cells[1].Value = vendor.Address;
                row.Cells[2].Value = vendor.City;
                row.Cells[3].Value = vendor.State;
                row.Cells[4].Value = vendor.Country;

                row.Cells[0].Style.BackgroundBrush = PdfBrushes.LightGray;
                row.Cells[0].StringFormat = row.Cells[1].StringFormat = row.Cells[2].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                row.Cells[3].StringFormat = row.Cells[4].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (rowIndex % 2 == 0)
                {
                    row.Style.BackgroundBrush = PdfBrushes.YellowGreen;
                }
                else
                {
                    row.Style.BackgroundBrush = PdfBrushes.Bisque;
                }
                rowIndex++;
            }

            StringBuilder totalAmount = new StringBuilder();

            var groupByCountry
                = this.dataSource.GroupBy(v => v.Country)
                    .Select(g => new { Name = g.Key, Count = g.Count() });

            foreach (var item in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", item.Name, item.Count);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f,System.Drawing.FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), true);
               // = new Font("Arial", 10f, System.Drawing.FontStyle.Bold);
            totalAmountRow.Cells[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfLayoutResult resultl = grid.Draw(page, new PointF(0, y));
            y = y + resultl.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            resultl.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                font2, brush2, 5, y);

            //Save pdf file.
            using (Stream stream = saveFiledialog.OpenFile())
            {
                document.SaveToStream(stream);
            }
            document.Close();
        }
示例#44
0
        public FileResult Download(int year, int id)
        {
            //Create a pdf document.<br>
            PdfDocument doc = new PdfDocument();
            Participant data = TheRace.Historical(year).Participants.Where(p => p.Startnumber == id).First();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;

            PdfFont font32b = new PdfFont(PdfFontFamily.Helvetica, 40f, PdfFontStyle.Bold); ;
            PdfFont font32 = new PdfFont(PdfFontFamily.TimesRoman, 32f, PdfFontStyle.Regular);
            PdfFont font20b = new PdfFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfFont font20 = new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Regular);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            format1.WordWrap = PdfWordWrapType.Word;

            //Draw the image
            PdfImage image = PdfImage.FromFile(Server.MapPath("~/Content/Images/price.jpg"));
            float width = image.Width;
            float height = image.Height;
            float x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, x, y, width, height);

            page.Canvas.DrawString(data.Splits(data.Classes[0].Id).Last().Position.ToString() + ".", font32b, brush1, x + 60, y + 50, format1);

            y = image.Height;

            page.Canvas.DrawString(data.Name, font32b, brush1, 0, y, format1);

            y = y + font32b.MeasureString(data.Name, format1).Height + 15;

            foreach (ParticipantClass c in data.Classes.Where(c => c.Official))
            {
                StringBuilder sb = new StringBuilder(c.Name);
                sb.Append(" - ");
                var res = data.Leg(c.Id, 248);
                if (res != null)
                    sb.Append(data.Leg(c.Id, 248).Position);
                sb.Append(".plass");

                page.Canvas.DrawString(sb.ToString(), font20, brush1, 0, y, format1);
                y += font20.MeasureString(sb.ToString(), format1).Height + 15;
            }

            List<String[]> splits = data.Splits(data.Classes[0].Id).Select(p => new String[] { p.Leg, p.IsSuper ? "" : p.Name, p.Time }).ToList<String[]>();
            if (splits.Count() > 0)
            {
                splits.Add(new String[] { "Totaltid", "", data.TotalTime });

                y = y + 30;

                page.Canvas.DrawString("Etappetider", font20b, brush1, 0, y, format1);
                y += font20b.MeasureString("Etappetider", format1).Height + 5;

                PdfTable table = new PdfTable();
                table.Style.BorderPen = new PdfPen(Color.Transparent);
                table.Style.DefaultStyle.TextBrush = brush1;
                table.Style.DefaultStyle.Font = font20;
                table.Style.DefaultStyle.BorderPen = new PdfPen(Color.Transparent);
                table.Style.CellPadding = 2;
                table.Style.HeaderSource = PdfHeaderSource.Rows;
                table.Style.HeaderRowCount = 0;
                table.Style.ShowHeader = false;
                table.Style.AlternateStyle = new PdfCellStyle();

                table.Style.AlternateStyle.TextBrush = brush1;
                table.Style.AlternateStyle.Font = font20;
                table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightGray;
                table.Style.AlternateStyle.BorderPen = new PdfPen(Color.Transparent);

                table.DataSource = splits.ToArray<String[]>();

                PdfLayoutResult result = table.Draw(page, new PointF(0, y));

                y = y + result.Bounds.Height + 5;

            }

            StringBuilder s = new StringBuilder("Start # ");
            s.Append(data.Startnumber.ToString());
            s.Append("    Emit # ");
            s.Append(data.EmitID.ToString());

            y += 50;

            page.Canvas.DrawString(s.ToString(), font20, brush1, page.Canvas.ClientSize.Width / 2, y, format1);

            y = page.Canvas.ClientSize.Height - 60;

            image = PdfImage.FromFile(Server.MapPath("~/Content/Images/kjeringi2016_logo-2.png"));
            width = image.Width;
            height = image.Height;
            x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, 0, y, width, height);

            image = PdfImage.FromFile(Server.MapPath("~/Content/Images/difi-logo.png"));
            width = image.Width;
            height = image.Height;
            x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, x, y, width, height);

            doc.SaveToFile(@"c:\temp\KjeringiOpen-" + year.ToString() + "_" + id.ToString() + ".pdf");

            return File(@"c:\temp\KjeringiOpen-" + year.ToString() + "_" + id.ToString() + ".pdf", "application/pdf");
        }
示例#45
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;
            float x = 0;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12));
            String label = "Simple Link: ";
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12, FontStyle.Underline));
            String url1 = "http://www.e-iceblue.com";
            page.Canvas.DrawString(url1, font1, PdfBrushes.Blue, x, y);
            y = y + font1.MeasureString(url1).Height;

            label = "Web Link: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            String text = "e-iceblue";
            PdfTextWebLink link2 = new PdfTextWebLink();
            link2.Text = text;
            link2.Url = url1;
            link2.Font = font1;
            link2.Brush = PdfBrushes.Blue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height;

            label = "URI Annonationa: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "Google";
            PointF location = new PointF(x, y);
            SizeF size = font1.MeasureString(text);
            RectangleF linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link3 = new PdfUriAnnotation(linkBounds);
            link3.Border = new PdfAnnotationBorder(0);
            link3.Uri = "http://www.google.com";
            (page as PdfNewPage).Annotations.Add(link3);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

            label = "URI Annonationa Action: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "JavaScript Action (Click Me)";
            location = new PointF(x, y);
            size = font1.MeasureString(text);
            linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds);
            link4.Border = new PdfAnnotationBorder(0.75f);
            link4.Color = Color.LightGray;
            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Hello.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script);
            link4.Action = action;
            (page as PdfNewPage).Annotations.Add(link4);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Link.pdf");
        }
示例#46
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            page.BackgroundColor = Color.Chocolate;

            //Draw page
            DrawPage(page);

            page = doc.Pages.Add(PdfPageSize.A4, margin);
            page.BackgroundColor = Color.Coral;

            //Draw page
            DrawPage(page);

            page = doc.Pages.Add(PdfPageSize.A3, margin, PdfPageRotateAngle.RotateAngle180, PdfPageOrientation.Landscape);
            page.BackgroundColor = Color.LightPink;

            //Draw page
            DrawPage(page);

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            page = section.Pages.Add();

            //Draw page
            DrawPage(page);

            //set background color
            page = section.Pages.Add();
            page.BackgroundColor = Color.LightSkyBlue;
            DrawPage(page);

            //Landscape
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Orientation = PdfPageOrientation.Landscape;
            page = section.Pages.Add();
            DrawPage(page);

            //Rotate 90
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;
            page = section.Pages.Add();
            DrawPage(page);

            //Rotate 180
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180;
            page = section.Pages.Add();
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("PageSetup.pdf");
        }
示例#47
0
        private void crearFacturaPDF(String title)
        {
            //create a new pdf document
            PdfDocument pdfDoc = new PdfDocument();

            //add one blank page
            PdfPageBase page = pdfDoc.Pages.Add();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            float y = 40;
            float infoMargin = 120;

            Cliente c = findCliente(fac_cliente.Text);
            //Encabezado
            PdfBrush brush1 = PdfBrushes.BlueViolet;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Calibri", 11f)); ;
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            page.Canvas.DrawString(c.cl_nombre, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(c.cl_ruc, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(c.cl_direccion, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(fac_fecha.Text, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 30;

            //Productos
            PdfBrush brush2 = PdfBrushes.Green;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            float x = 30;
            float totalX = page.Canvas.ClientSize.Width - 2 * x;
            foreach (FacturaItem fi in _FacturaItemsCollection)
            {

                page.Canvas.DrawString(fi.fi_codigo, font2, brush2, x, y, format1);
                x = x + 0.15f * totalX;
                page.Canvas.DrawString(fi.fi_nombre, font2, brush2, x, y, format1);
                x = x + 0.55f * totalX;
                page.Canvas.DrawString(fi.fi_cantidad.ToString("n2"), font2, brush2, x, y, format1);
                x = x + 0.15f * totalX;
                page.Canvas.DrawString(fi.fi_importe.ToString("n2"), font2, brush2, x, y, format1);
                y = y + font2.MeasureString(fi.fi_nombre, format1).Height + 5;
                x = 30;
            }

            //Tail
            y = page.Canvas.ClientSize.Height - 60;
            infoMargin = x + 0.85f * totalX;
            page.Canvas.DrawString(fact_total.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_total.ToString(), format1).Height - 5;
            page.Canvas.DrawString(fact_iva.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_total.ToString(), format1).Height - 5;
            page.Canvas.DrawString(fact_subtotal.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_subtotal.ToString(), format1).Height - 5;

            //page.Canvas.DrawString(String.Format("* {0} productos en la base de datos.", dataSource.Length - 1), font2, brush2, 5, y);

            //save the pdf document
            String filename = title + ".pdf";
            pdfDoc.SaveToFile(@filename);

            //launch the pdf document
            System.Diagnostics.Process.Start(@filename);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            PdfSection section = doc.Sections.Add();

            section.PageSettings.Margins = margin;
            section.PageSettings.Size    = PdfPageSize.A4;

            // Create one page
            PdfPageBase page = section.Pages.Add();
            float       y    = 10;

            PdfBrush               brush1 = PdfBrushes.Black;
            PdfTrueTypeFont        font1  = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true);
            RectangleF             rctg   = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);

            //draw Codabar
            PdfTextWidget text = new PdfTextWidget();

            text.Font = font1;
            text.Text = "Codabar:";
            PdfLayoutResult result = text.Draw(page, 0, y);

            page = result.Page;
            y    = result.Bounds.Bottom + 2;

            PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");

            barcode1.BarcodeToTextGapHeight = 1f;
            barcode1.EnableCheckDigit       = true;
            barcode1.ShowCheckDigit         = true;
            barcode1.TextDisplayLocation    = TextLocation.Bottom;
            barcode1.TextColor = Color.Blue;
            barcode1.Draw(page, new PointF(0, y));
            y = barcode1.Bounds.Bottom + 5;


            //draw Code11Barcode
            text.Text = "Code11:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");

            barcode2.BarcodeToTextGapHeight = 1f;
            barcode2.TextDisplayLocation    = TextLocation.Bottom;
            barcode2.TextColor = Color.Blue;
            barcode2.Draw(page, new PointF(0, y));
            y = barcode2.Bounds.Bottom + 5;


            //draw Code128-A
            text.Text = "Code128-A:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode128ABarcode barcode3 = new PdfCode128ABarcode("HELLO 00-123");

            barcode3.BarcodeToTextGapHeight = 1f;
            barcode3.TextDisplayLocation    = TextLocation.Bottom;
            barcode3.TextColor = Color.Blue;
            barcode3.Draw(page, new PointF(0, y));
            y = barcode3.Bounds.Bottom + 5;


            //draw Code128-B
            text.Text = "Code128-B:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode128BBarcode barcode4 = new PdfCode128BBarcode("Hello 00-123");

            barcode4.BarcodeToTextGapHeight = 1f;
            barcode4.TextDisplayLocation    = TextLocation.Bottom;
            barcode4.TextColor = Color.Blue;
            barcode4.Draw(page, new PointF(0, y));
            y = barcode4.Bounds.Bottom + 5;


            //draw Code32
            text.Text = "Code32:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode32Barcode barcode5 = new PdfCode32Barcode("16273849");

            barcode5.BarcodeToTextGapHeight = 1f;
            barcode5.TextDisplayLocation    = TextLocation.Bottom;
            barcode5.TextColor = Color.Blue;
            barcode5.Draw(page, new PointF(0, y));
            y = barcode5.Bounds.Bottom + 5;

            page = section.Pages.Add();
            y    = 10;


            //draw Code39
            text.Text = "Code39:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode39Barcode barcode6 = new PdfCode39Barcode("16-273849");

            barcode6.BarcodeToTextGapHeight = 1f;
            barcode6.TextDisplayLocation    = TextLocation.Bottom;
            barcode6.TextColor = Color.Blue;
            barcode6.Draw(page, new PointF(0, y));
            y = barcode6.Bounds.Bottom + 5;


            //draw Code39-E
            text.Text = "Code39-E:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode39ExtendedBarcode barcode7 = new PdfCode39ExtendedBarcode("16-273849");

            barcode7.BarcodeToTextGapHeight = 1f;
            barcode7.TextDisplayLocation    = TextLocation.Bottom;
            barcode7.TextColor = Color.Blue;
            barcode7.Draw(page, new PointF(0, y));
            y = barcode7.Bounds.Bottom + 5;


            //draw Code93
            text.Text = "Code93:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode93Barcode barcode8 = new PdfCode93Barcode("16-273849");

            barcode8.BarcodeToTextGapHeight = 1f;
            barcode8.TextDisplayLocation    = TextLocation.Bottom;
            barcode8.TextColor        = Color.Blue;
            barcode8.QuietZone.Bottom = 5;
            barcode8.Draw(page, new PointF(0, y));
            y = barcode8.Bounds.Bottom + 5;


            //draw Code93-E
            text.Text = "Code93-E:";
            result    = text.Draw(page, 0, y);
            page      = result.Page;
            y         = result.Bounds.Bottom + 2;

            PdfCode93ExtendedBarcode barcode9 = new PdfCode93ExtendedBarcode("16-273849");

            barcode9.BarcodeToTextGapHeight = 1f;
            barcode9.TextDisplayLocation    = TextLocation.Bottom;
            barcode9.TextColor = Color.Blue;
            barcode9.Draw(page, new PointF(0, y));
            y = barcode9.Bounds.Bottom + 5;


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

            //Launching the Pdf file.
            PDFDocumentViewer("Barcode.pdf");
        }
示例#49
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(0));

            float y = 0;

            //title
            y = DrawPageTitle(page, y);

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument xpathDoc = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                int fieldIndex = 0;
                foreach (XPathNavigator sectionNode in sectionNodes)
                {
                    //draw section label
                    String sectionLabel = sectionNode.GetAttribute("name", "");
                    y = DrawFormSection(sectionLabel, page, y);

                    XPathNodeIterator fieldNodes = sectionNode.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        y= DrawFormField(fieldNode, doc.Form, page, y, fieldIndex++);
                    }
                }
            }

            //draw button
            y = y + 10;
            float buttonWidth = 80;
            float buttonX = (page.Canvas.ClientSize.Width - buttonWidth) / 2;
            RectangleF buttonBounds = new RectangleF(buttonX, y, buttonWidth, 16f);
            PdfButtonField button = new PdfButtonField(page, "submit");
            button.Text = "Submit";
            button.Bounds = buttonBounds;
            PdfSubmitAction submitAction = new PdfSubmitAction("http://www.e-iceblue.com");
            button.Actions.MouseUp = submitAction;
            doc.Form.Fields.Add(button);

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

            //Launching the Pdf file.
            PDFDocumentViewer("FormField.pdf");
        }
示例#50
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Set margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            //Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //Title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 2;

            //Table top
            PdfDestination tableTopDest = new PdfDestination(page);

            tableTopDest.Location = new PointF(0, y);
            tableTopDest.Mode     = PdfDestinationMode.Location;
            tableTopDest.Zoom     = 1f;

            //Draw table
            PdfTrueTypeFont buttonFont        = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            float           buttonWidth       = 70;
            float           buttonHeight      = buttonFont.Height * 1.5f;
            float           tableTop          = y;
            PdfLayoutResult tableLayoutResult = DrawTable(page, y + buttonHeight + 5);

            //Table bottom
            PdfDestination tableBottomDest = new PdfDestination(tableLayoutResult.Page);

            tableBottomDest.Location = new PointF(0, tableLayoutResult.Bounds.Bottom);
            tableBottomDest.Mode     = PdfDestinationMode.Location;
            tableBottomDest.Zoom     = 1f;

            //Go to table bottom
            float           x            = page.Canvas.ClientSize.Width - buttonWidth;
            PdfStringFormat format2      = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            RectangleF      buttonBounds = new RectangleF(x, tableTop, buttonWidth, buttonHeight);

            page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            page.Canvas.DrawString("To Bottom", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction       action1 = new PdfGoToAction(tableBottomDest);
            PdfActionAnnotation annotation1
                = new PdfActionAnnotation(buttonBounds, action1);

            annotation1.Border = new PdfAnnotationBorder(0.75f);
            annotation1.Color  = Color.LightGray;
            (page as PdfNewPage).Annotations.Add(annotation1);

            //Go to table top
            float tableBottom = tableLayoutResult.Bounds.Bottom + 5;

            buttonBounds = new RectangleF(x, tableBottom, buttonWidth, buttonHeight);
            tableLayoutResult.Page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            tableLayoutResult.Page.Canvas.DrawString("To Top", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction       action2 = new PdfGoToAction(tableTopDest);
            PdfActionAnnotation annotation2
                = new PdfActionAnnotation(buttonBounds, action2);

            annotation2.Border = new PdfAnnotationBorder(0.75f);
            annotation2.Color  = Color.LightGray;
            (tableLayoutResult.Page as PdfNewPage).Annotations.Add(annotation2);

            //Go to last page
            PdfNamedAction action3 = new PdfNamedAction(PdfActionDestination.LastPage);

            doc.AfterOpenAction = action3;

            //Script
            String script
                = "app.alert({"
                  + "    cMsg: \"Oh no, you want to leave me.\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);

            doc.BeforeCloseAction = action4;

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

            //Launch the Pdf file
            PDFDocumentViewer("Action.pdf");
        }
示例#51
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 2;

            //table top
            PdfDestination tableTopDest = new PdfDestination(page);
            tableTopDest.Location = new PointF(0, y);
            tableTopDest.Mode = PdfDestinationMode.Location;
            tableTopDest.Zoom = 1f;

            //Draw table            
            PdfTrueTypeFont buttonFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            float buttonWidth = 70;
            float buttonHeight = buttonFont.Height * 1.5f;
            float tableTop = y;
            PdfLayoutResult tableLayoutResult = DrawTable(page, y + buttonHeight + 5);

            //table bottom
            PdfDestination tableBottomDest = new PdfDestination(tableLayoutResult.Page);
            tableBottomDest.Location = new PointF(0, tableLayoutResult.Bounds.Bottom);
            tableBottomDest.Mode = PdfDestinationMode.Location;
            tableBottomDest.Zoom = 1f;

            //go to table bottom
            float x = page.Canvas.ClientSize.Width - buttonWidth;
            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            RectangleF buttonBounds = new RectangleF(x, tableTop, buttonWidth, buttonHeight);
            page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            page.Canvas.DrawString("To Bottom", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action1 = new PdfGoToAction(tableBottomDest);
            PdfActionAnnotation annotation1
                = new PdfActionAnnotation(buttonBounds, action1);
            annotation1.Border = new PdfAnnotationBorder(0.75f);
            annotation1.Color = Color.LightGray;
            (page as PdfNewPage).Annotations.Add(annotation1);

            //go to table top
            float tableBottom = tableLayoutResult.Bounds.Bottom + 5;
            buttonBounds = new RectangleF(x, tableBottom, buttonWidth, buttonHeight);
            tableLayoutResult.Page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            tableLayoutResult.Page.Canvas.DrawString("To Top", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action2 = new PdfGoToAction(tableTopDest);
            PdfActionAnnotation annotation2
                = new PdfActionAnnotation(buttonBounds, action2);
            annotation2.Border = new PdfAnnotationBorder(0.75f);
            annotation2.Color = Color.LightGray;
            (tableLayoutResult.Page as PdfNewPage).Annotations.Add(annotation2);

            //goto last page
            PdfNamedAction action3 = new PdfNamedAction(PdfActionDestination.LastPage);
            doc.AfterOpenAction = action3;

            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Oh no, you want to leave me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            doc.BeforeCloseAction = action4;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Action.pdf");
        }
示例#52
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);

            float y = 10;
            float x1 = page.Canvas.ClientSize.Width;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Vendor List", format1).Height;
            y = y + 5;

            String[] data
                = {
                    "VendorName;Address1;City;State;Country",
                    "Cacor Corporation;161 Southfield Rd;Southfield;OH;U.S.A.",
                    "Underwater;50 N 3rd Street;Indianapolis;IN;U.S.A.",
                    "J.W.  Luscher Mfg.;65 Addams Street;Berkely;MA;U.S.A.",
                    "Scuba Professionals;3105 East Brace;Rancho Dominguez;CA;U.S.A.",
                    "Divers'  Supply Shop;5208 University Dr;Macon;GA;U.S.A.",
                    "Techniques;52 Dolphin Drive;Redwood City;CA;U.S.A.",
                    "Perry Scuba;3443 James Ave;Hapeville;GA;U.S.A.",
                    "Beauchat, Inc.;45900 SW 2nd Ave;Ft Lauderdale;FL;U.S.A.",
                    "Amor Aqua;42 West 29th Street;New York;NY;U.S.A.",
                    "Aqua Research Corp.;P.O. Box 998;Cornish;NH;U.S.A.",
                    "B&K Undersea Photo;116 W 7th Street;New York;NY;U.S.A.",
                    "Diving International Unlimited;1148 David Drive;San Diego;DA;U.S.A.",
                    "Nautical Compressors;65 NW 167 Street;Miami;FL;U.S.A.",
                    "Glen Specialties, Inc.;17663 Campbell Lane;Huntington Beach;CA;U.S.A.",
                    "Dive Time;20 Miramar Ave;Long Beach;CA;U.S.A.",
                    "Undersea Systems, Inc.;18112 Gotham Street;Huntington Beach;CA;U.S.A.",
                    "Felix Diving;310 S Michigan Ave;Chicago;IL;U.S.A.",
                    "Central Valley Skin Divers;160 Jameston Ave;Jamaica;NY;U.S.A.",
                    "Parkway Dive Shop;241 Kelly Street;South Amboy;NJ;U.S.A.",
                    "Marine Camera & Dive;117 South Valley Rd;San Diego;CA;U.S.A.",
                    "Dive Canada;275 W Ninth Ave;Vancouver;British Columbia;Canada",
                    "Dive & Surf;P.O. Box 20210;Indianapolis;IN;U.S.A.",
                    "Fish Research Labs;29 Wilkins Rd Dept. SD;Los Banos;CA;U.S.A."
                };
            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

            String[] header = data[0].Split(';');
            grid.Columns.Add(header.Length);
            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            headerRow.Style.BackgroundBrush
                = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), Color.Red, Color.Blue);
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (i == 0)
                {
                    headerRow.Cells[i].Style.BackgroundBrush = PdfBrushes.Gray;
                }
            }

            Random random = new Random();
            Dictionary<String, int> groupByCountry = new Dictionary<String, int>();
            for (int r = 1; r < data.Length; r++)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                byte[] buffer = new byte[6];
                random.NextBytes(buffer);
                PdfRGBColor color1 = new PdfRGBColor(buffer[0], buffer[1], buffer[2]);
                PdfRGBColor color2 = new PdfRGBColor(buffer[3], buffer[4], buffer[5]);
                row.Style.BackgroundBrush
                    = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), color1, color2);
                String[] rowData = data[r].Split(';');
                for (int c = 0; c < rowData.Length; c++)
                {
                    row.Cells[c].Value = rowData[c];
                    if (c == 0)
                    {
                        row.Cells[c].Style.BackgroundBrush = PdfBrushes.Gray;
                    }
                    if(c < 3)
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    if (c == 4)
                    {
                        if (groupByCountry.ContainsKey(rowData[c]))
                        {
                            groupByCountry[rowData[c]] = groupByCountry[rowData[c]] + 1;
                        }
                        else
                        {
                            groupByCountry[rowData[c]] = 1;
                        }
                    }
                }
            }
            StringBuilder totalAmount = new StringBuilder();
            foreach (KeyValuePair<String, int> country in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", country.Key, country.Value);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            //append product list
            PdfGrid productList = new PdfGrid();
            productList.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f), true);
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select p.Description "
                    + " from vendors v "
                    + "     inner join parts p "
                    + "     on v.VendorNo = p.VendorNo "
                    + " where v.VendorName = 'Cacor Corporation'";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    productList.DataSource = dataTable;
                }
            }
            productList.Headers[0].Cells[0].Value = "Cacor Corporation";
            productList.Headers[0].Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
            productList.Headers[0].Cells[0].Style.Borders.All = new PdfPen(new PdfTilingBrush(new SizeF(1, 1)), 0);
            grid.Rows[0].Cells[0].Value = productList;
            grid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Left;

            PdfLayoutResult result = grid.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                font2, brush2, 5, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Grid.pdf");
        }
示例#53
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            String[] data
                = {
                    "Name;Capital;Continent;Area;Population",
                    "Argentina;Buenos Aires;South America;2777815;32300003",
                    "Bolivia;La Paz;South America;1098575;7300000",
                    "Brazil;Brasilia;South America;8511196;150400000",
                    "Canada;Ottawa;North America;9976147;26500000",
                    "Chile;Santiago;South America;756943;13200000",
                    "Colombia;Bagota;South America;1138907;33000000",
                    "Cuba;Havana;North America;114524;10600000",
                    "Ecuador;Quito;South America;455502;10600000",
                    "El Salvador;San Salvador;North America;20865;5300000",
                    "Guyana;Georgetown;South America;214969;800000",
                    "Jamaica;Kingston;North America;11424;2500000",
                    "Mexico;Mexico City;North America;1967180;88600000",
                    "Nicaragua;Managua;North America;139000;3900000",
                    "Paraguay;Asuncion;South America;406576;4660000",
                    "Peru;Lima;South America;1285215;21600000",
                    "United States of America;Washington;North America;9363130;249200000",
                    "Uruguay;Montevideo;South America;176140;3002000",
                    "Venezuela;Caracas;South America;912047;19700000"
                };

            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString(String.Format("* {0} countries in the list.", data.Length - 1),
                font2, brush2, 5, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleTable.pdf");
        }
示例#54
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

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

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Sales Report", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Sales Report", format1).Height;
            y = y + 5;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                conn.Open();

                OleDbCommand partQueryCommand = PreparePartQueryCommand(conn);
                OleDbCommand orderItemQueryCommand = PrepareOrderItemQueryCommand(conn);

                DataTable vendors = GetVendors(conn);
                for (int i = 0;  i < vendors.Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        //next page
                        page = section.Pages.Add();
                        y = 0;
                    }
                    //draw vendor
                    String vendorTitle = String.Format("{0}. {1}", i + 1, vendors.Rows[i].ItemArray[1]);
                    PdfLayoutResult drawVendorLayoutResult = DrawVendor(page, vendors, i, vendorTitle, y);

                    //add vendor bookmark
                    PdfDestination vendorBookmarkDest = new PdfDestination(page, new PointF(0, y));
                    PdfBookmark vendorBookmark = doc.Bookmarks.Add(vendorTitle);
                    vendorBookmark.Color = Color.SaddleBrown;
                    vendorBookmark.DisplayStyle = PdfTextStyle.Bold;
                    vendorBookmark.Action = new PdfGoToAction(vendorBookmarkDest);

                    y = drawVendorLayoutResult.Bounds.Bottom + 5;
                    page = drawVendorLayoutResult.Page;

                    //get parts of vendor
                    DataTable parts = GetParts(partQueryCommand, (double)vendors.Rows[i].ItemArray[0]);
                    for (int j = 0; j < parts.Rows.Count; j++)
                    {
                        if (j > 0)
                        {
                            //next page
                            page = section.Pages.Add();
                            y = 0;
                        }
                        //draw part
                        String partTitle = String.Format("{0}.{1}. {2}", i + 1, j + 1, parts.Rows[j].ItemArray[1]);
                        PdfLayoutResult drawPartLayoutResult = DrawPart(page, parts, j, partTitle, y);

                        //add part bookmark
                        PdfDestination partBookmarkDest = new PdfDestination(page, new PointF(0, y));
                        PdfBookmark partBookmark = vendorBookmark.Add(partTitle);
                        partBookmark.Color = Color.Coral;
                        partBookmark.DisplayStyle = PdfTextStyle.Italic;
                        partBookmark.Action = new PdfGoToAction(partBookmarkDest);

                        y = drawPartLayoutResult.Bounds.Bottom + 5;
                        page = drawPartLayoutResult.Page;

                        //get order items
                        String orderItemsTitle = String.Format("{0} - Order Items", parts.Rows[j].ItemArray[1]);
                        DataTable orderItems = GetOrderItems(orderItemQueryCommand, (double)parts.Rows[j].ItemArray[0]);
                        DrawOrderItems(page, orderItems, orderItemsTitle, y);
                    }
                }
            }

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

            //Launching the Pdf file.
            PDFDocumentViewer("Bookmark.pdf");
        }
示例#55
0
        private String crearPDFoculto(String title, String[][] dataSource, String[] extraInfo)
        {
            //create a new pdf document
            PdfDocument pdfDoc = new PdfDocument();

            //add one blank page
            PdfPageBase page = pdfDoc.Pages.Add();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.BlueViolet;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Calibri", 13f)); ;
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString(title, font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString(title, format1).Height;
            y = y + 5;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            if (extraInfo != null)
            {
                PdfBrush brush2 = PdfBrushes.Green;
                PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
                foreach (String item in extraInfo)
                {
                    page.Canvas.DrawString(item, font2, brush2, 5, y);
                    y = y + font2.MeasureString(item, format1).Height;
                    y = y + 5;
                }
            }

            //page.Canvas.DrawString(String.Format("* {0} productos en la base de datos.", dataSource.Length - 1), font2, brush2, 5, y);
            //save the pdf document
            String filename = "data/" + title + ".pdf";
            pdfDoc.SaveToFile(@filename);
            return filename;

            //launch the pdf document
            //System.Diagnostics.Process.Start(@filename);
        }