public PdfInternalFont(Font font, bool unicode)
 {
     using (Stream stream = this.GetFontStream(font))
     {
         this.internalFont = new PdfTrueTypeFont(stream, font.Size, font.Style);
     }
 }
        /// <summary>
        /// GoToE action
        /// </summary>
        /// <param name="pdf"></param>
        private static void EmbeddedGoToAction(PdfDocument pdf, PdfPageBase page)
        {
            //add a attachment
            PdfAttachment attachment = new PdfAttachment(@"..\..\..\..\..\..\Data\GoToAction.pdf");

            pdf.Attachments.Add(attachment);

            string          text   = "Test embedded go-to action! Click this will open the attached PDF in a new window.";
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 13f));
            float           width  = 490f;
            float           height = font.Height * 2.2f;
            RectangleF      rect   = new RectangleF(0, 100, width, height);

            page.Canvas.DrawString(text, font, PdfBrushes.Black, rect);

            //create a PdfDestination with specific page, location and 200% zoom factor
            PdfDestination dest = new PdfDestination(1, new PointF(0, 842), 2f);

            //create GoToE action with dest
            PdfEmbeddedGoToAction action     = new PdfEmbeddedGoToAction(attachment.FileName, dest, true);
            PdfActionAnnotation   annotation = new PdfActionAnnotation(rect, action);

            //add the annotation
            (page as PdfNewPage).Annotations.Add(annotation);
        }
Exemple #3
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");
        }
        private float AddLineAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Line Annotation: ";
            SizeF  size   = font.MeasureString(prompt);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = font.MeasureString(prompt, format).Width;

            String label = @"Line Anotation";

            size = font.MeasureString(label);
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            RectangleF bounds = new RectangleF(x, y, size.Width, size.Height);

            int[] linePoints = new int[]
            {
                (int)bounds.Left, (int)bounds.Top, (int)bounds.Right, (int)bounds.Bottom
            };
            PdfLineAnnotation annotation = new PdfLineAnnotation(linePoints, "Annotation");

            annotation.BeginLineStyle = PdfLineEndingStyle.ClosedArrow;
            annotation.EndLineStyle   = PdfLineEndingStyle.ClosedArrow;
            annotation.LineCaption    = true;
            annotation.BackColor      = Color.Black;
            annotation.CaptionType    = PdfLineCaptionType.Inline;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = bounds.Bottom;

            return(y);
        }
Exemple #5
0
 public override void CheckFont(PdfFont pdfFont)
 {
     if (!pdfFont.IsEmbedded())
     {
         throw new PdfAConformanceException(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
                                            ).SetMessageParams(pdfFont.GetFontProgram().GetFontNames().GetFontName());
     }
     if (pdfFont is PdfTrueTypeFont)
     {
         PdfTrueTypeFont trueTypeFont = (PdfTrueTypeFont)pdfFont;
         bool            symbolic     = trueTypeFont.GetFontEncoding().IsFontSpecific();
         if (symbolic)
         {
             CheckSymbolicTrueTypeFont(trueTypeFont);
         }
         else
         {
             CheckNonSymbolicTrueTypeFont(trueTypeFont);
         }
     }
     if (pdfFont is PdfType3Font)
     {
         PdfDictionary charProcs = pdfFont.GetPdfObject().GetAsDictionary(PdfName.CharProcs);
         foreach (PdfName charName in charProcs.KeySet())
         {
             CheckContentStream(charProcs.GetAsStream(charName));
         }
     }
 }
Exemple #6
0
        public void CreatPDF()
        {//
            float           x     = 50;
            float           y     = 50;
            string          hang1 = "测试文字1";
            string          hang2 = "测试文字2";
            string          hang3 = "测试文字3";
            PdfDocument     pdf   = new PdfDocument();                                                               //新建一个pdf
            PdfPageBase     page  = pdf.Pages.Add();                                                                 //新建pdf的一页
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial Unicode MS", 30f, FontStyle.Regular), true); //创建一个pdf的字体

            page.Canvas.DrawString(hang1, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
            page.Canvas.DrawString(hang2, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
            page.Canvas.DrawString(hang3, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
            // PdfStringFormat format = new PdfStringFormat();
            // format.MeasureTrailingSpaces = true;
            //// x += font1.MeasureString(str, format).Width;

            //超链接
            // PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial Unicode MS", 30f, FontStyle.Underline), true);
            // PdfTextWebLink webLink = new PdfTextWebLink();
            // webLink.Url = "https://www.baidu.com";
            // webLink.Text = "百度";
            // webLink.Font = font2;
            // webLink.Brush = PdfBrushes.Blue;
            // webLink.DrawTextWebLink(page.Canvas, new PointF(x, y));
            pdf.SaveToFile("1.pdf");////创建pdf
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the document from disk
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile(@"..\..\..\..\..\..\Data\ReplaceFont.pdf");

            //Get the fonts used in PDF
            PdfUsedFont[] fonts = doc.UsedFonts;

            //Create a new font
            PdfTrueTypeFont newfont = new PdfTrueTypeFont(new Font("Arial", 13f), true);

            foreach (PdfUsedFont font in fonts)
            {
                //Replace the font with new font
                font.Replace(newfont);
            }

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

            //View the Pdf doc
            System.Diagnostics.Process.Start("Output.pdf");
        }
Exemple #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document and add a page to it
            PdfDocument doc  = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            //Create a PDF Launch Action
            PdfLaunchAction launchAction = new PdfLaunchAction("..\\..\\..\\..\\..\\..\\Data\\text.txt");

            //Create a PDF Action Annotation with the PDF Launch Action
            string          text = "Click here to open file";
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 13f));
            RectangleF      rect = new RectangleF(50, 50, 230, 15);

            page.Canvas.DrawString(text, font, PdfBrushes.ForestGreen, rect);
            PdfActionAnnotation annotation = new PdfActionAnnotation(rect, launchAction);

            //Add the PDF Action Annotation to page
            (page as PdfNewPage).Annotations.Add(annotation);


            String result = "AddPdfLaunchAction_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Exemple #9
0
        private float DrawPageTitle(PdfPageBase page, float y)
        {
            PdfBrush        brush1 = PdfBrushes.MidnightBlue;
            PdfBrush        brush2 = PdfBrushes.Red;
            PdfTrueTypeFont font1  = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            String          title  = "Your Account Information(* = Required)";
            SizeF           size   = font1.MeasureString(title);
            float           x      = (page.Canvas.ClientSize.Width - size.Width) / 2;

            page.Canvas.DrawString("Your Account Information(", font1, brush1, x, y);
            size = font1.MeasureString("Your Account Information(");
            x    = x + size.Width;
            page.Canvas.DrawString("* = Required", font1, brush2, x, y);
            size = font1.MeasureString("* = Required");
            x    = x + size.Width;
            page.Canvas.DrawString(")", font1, brush1, x, y);
            y = y + size.Height;

            y = y + 3;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic));
            String          p     = "Your information is not public, shared in anyway, or displayed on this site.";

            page.Canvas.DrawString(p, font2, brush1, 0, y);

            return(y + font2.Height);
        }
Exemple #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Add a new page
            PdfPageBase page = doc.Pages.Add();

            //Create a rectangle
            Rectangle rect = new Rectangle(new Point(0, 0), new Size(300, 100));

            //Create a brush with gradient
            PdfLinearGradientBrush brush = new PdfLinearGradientBrush(rect, Color.Red, Color.Blue, PdfLinearGradientMode.Horizontal);

            //Create a true type font with size 20f, underline style
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 20, FontStyle.Underline));

            //Draw text
            page.Canvas.DrawString("Welcome to E-iceblue!", font, brush, new Point(0, 100));

            String result = "DrawWithGradient-result.pdf";

            //Save to file
            doc.SaveToFile(result);

            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Exemple #11
0
        private PdfPageTemplateElement CreateFooterTemplate(PdfDocument doc, PdfMargins margins, SizeF pageSize)
        {
            //create a PdfPageTemplateElement object which works as footer space
            PdfPageTemplateElement footerSpace = new PdfPageTemplateElement(pageSize.Width, margins.Bottom);

            footerSpace.Foreground = false;

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

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

            footerSpace.Graphics.DrawLine(pen, x, y, pageSize.Width - x, y);

            //draw text in footer space
            y = y + 5;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            //draw dynamic field in footer space
            PdfPageNumberField number         = new PdfPageNumberField();
            PdfPageCountField  count          = new PdfPageCountField();
            PdfCompositeField  compositeField = new PdfCompositeField(font, PdfBrushes.Black, "Page {0} of {1}", number, count);

            compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
            SizeF size = font.MeasureString(compositeField.Text);

            compositeField.Bounds = new RectangleF(x, y, size.Width, size.Height);
            compositeField.Draw(footerSpace.Graphics);

            //return footerSpace
            return(footerSpace);
        }
        protected void GanttControlExporting_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GanttEventArgs e)
        {
            PdfExport exp = new PdfExport();
            GanttPdfExportSettings settings = new GanttPdfExportSettings();

            settings.Theme  = GanttExportTheme.FlatLime;
            settings.Locale = e.Arguments["locale"].ToString();
            //Create footer template
            RectangleF      bounds = new RectangleF(0, 0, 762, 25);
            PdfSolidBrush   brush  = new PdfSolidBrush(new PdfColor(51, 51, 51));
            PdfPen          pen    = new PdfPen(new PdfColor(200, 200, 200));
            PdfFont         font   = new PdfTrueTypeFont(new Font("Segoe UI", 10), true);
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;
            PdfPageTemplateElement footer         = new PdfPageTemplateElement(bounds);
            PdfPageNumberField     pageNumber     = new PdfPageNumberField(font, brush);
            PdfCompositeField      compositeField = new PdfCompositeField(font, brush, "Page {0}", pageNumber);

            compositeField.StringFormat = format;
            compositeField.Bounds       = footer.Bounds;
            footer.Graphics.DrawRectangle(pen, bounds);
            compositeField.Draw(footer.Graphics, new PointF(0, 0));
            PdfDocumentTemplate footerTemplate = new PdfDocumentTemplate();

            footerTemplate.Bottom        = footer;
            settings.PdfDocumentTemplate = footerTemplate;
            PdfDocument document = exp.Export(this.GanttControlExporting.Model, (IEnumerable)this.GanttControlExporting.DataSource, settings, false);

            document = exp.Export(this.GanttControlDesign.Model, (IEnumerable)this.GanttControlDesign.DataSource, settings, document, false);
            exp.Export(this.GanttControlImplementation.Model, (IEnumerable)this.GanttControlImplementation.DataSource, settings, "Gantt", document, true);
        }
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream CreatePdfDocument()
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

            //Add a page
            PdfPage page = document.Pages.Add();

            //Create font
            FileStream fontFileStream = new FileStream(ResolveApplicationPath("NotoSerif-Black.otf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfFont    font           = new PdfTrueTypeFont(fontFileStream, 14);

            //Text to draw
            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfPen     pen        = new PdfPen(new PdfColor(0, 0, 0));
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect);
            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            document.Close();
            stream.Position = 0;

            return(stream);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();
            //Add a page
            PdfPageBase page = doc.Pages.Add();

            //Set font and brush
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Arial", 20f));
            PdfSolidBrush   brush = new PdfSolidBrush(Color.Black);

            string text = "Spire.PDF for .NET";

            //Draw Superscript
            DrawSuperscript(page, text, font, brush);

            //Draw Subscript
            DrawSubscript(page, text, font, brush);

            String result = "SuperScriptAndSubScriptInPDF_out.pdf";

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

            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the Pdf from disk
            PdfDocument doc = new PdfDocument();

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

            string header1 = "Header 1";
            string header2 = "Header 2";

            //Define style
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 15f, FontStyle.Bold));
            PdfBrush        brush  = PdfBrushes.Red;
            RectangleF      rect   = new RectangleF(new PointF(0, 20), new SizeF(doc.PageSettings.Size.Width, 50f));
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment = PdfTextAlignment.Center;
            doc.Pages[0].Canvas.DrawString(header1, font, brush, rect, format);

            font             = new PdfTrueTypeFont(new Font("Aleo", 15f, FontStyle.Regular));
            brush            = PdfBrushes.Black;
            format.Alignment = PdfTextAlignment.Left;
            doc.Pages[1].Canvas.DrawString(header2, font, brush, rect, format);

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

            doc.SaveToFile(output, FileFormat.PDF);

            //Launch the Pdf
            PDFDocumentViewer(output);
        }
        private PdfLayoutResult DrawOrderItems(PdfPageBase page, DataTable orderItems, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));

            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            table.Style.BorderPen   = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.MediumTurquoise;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.PaleTurquoise;
            table.Style.AlternateStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Teal;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource       = orderItems;
            for (int i = 2; i < table.Columns.Count; i++)
            {
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();

            tableLayout.Break  = PdfLayoutBreakType.FitPage;
            tableLayout.Layout = PdfLayoutType.Paginate;

            return(table.Draw(page, new PointF(0, y), tableLayout));
        }
Exemple #17
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");
        }
        private static void DrawToPage(PdfPageBase page, string text, PdfTrueTypeFont font, PdfBrush brushColor, PdfStringFormat formatLeft, RectangleF area, float y, out float yout, bool ignoreOut)
        {
            page.Canvas.DrawString(text, font, brushColor, area, formatLeft);
            SizeF size = font.MeasureString(text, area.Size, formatLeft);

            yout = (ignoreOut) ? y : y + size.Height + 2;
        }
        private float AddTextMarkupAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Highlight incorrect spelling: ";
            SizeF  size   = font.MeasureString(prompt, format);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = size.Width;

            String label = "demo of anotation";

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            size = font.MeasureString("demo of ", format);
            x    = x + size.Width;
            PointF incorrectWordLocation = new PointF(x, y);
            String markupText            = "Should be 'annotation'";
            PdfTextMarkupAnnotation annotation
                = new PdfTextMarkupAnnotation(markupText, "anotation", new RectangleF(x, y, 100f, 100f), font);

            annotation.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
            annotation.TextMarkupColor          = Color.LightSkyBlue;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = y + size.Height;

            return(y);
        }
Exemple #20
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

            //Add a page
            PdfPage page = document.Pages.Add();

            //Create font
            Stream  fontStream = typeof(OpenTypeFont).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.NotoSerif-Black.otf");
            PdfFont font       = new PdfTrueTypeFont(fontStream, 14);

            //Text to draw
            string text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfPen     pen        = new PdfPen(new PdfColor(0, 0, 0));
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);


            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect);

            //Save the PDF document.
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            //Close the PDF documnet.
            document.Close(true);
            Save(stream, "OpenTypeFont.pdf");
        }
Exemple #21
0
        private void DrawPageHeaderAndFooter(PdfPageBase page, PdfMargins margin, bool isCover)
        {
            page.Canvas.SetTransparency(0.5f);
            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");

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

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

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

            page.Canvas.DrawLine(pen, x, y, x + width, y);
            y = y - 1 - font.Height;
            page.Canvas.DrawString("Demo of Spire.Pdf", font, brush, x + width, y, format);
            page.Canvas.SetTransparency(1);
        }
        private float AddFileLinkAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Launch File: ";
            SizeF  size   = font.MeasureString(prompt);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = font.MeasureString(prompt, format).Width;

            String label = @"Launch Notepad.exe";

            size = font.MeasureString(label);
            RectangleF bounds = new RectangleF(x, y, size.Width, size.Height);

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            PdfFileLinkAnnotation annotation = new PdfFileLinkAnnotation(bounds, @"C:\Windows\Notepad.exe");

            annotation.Color = Color.Blue;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = bounds.Bottom;

            return(y);
        }
Exemple #23
0
        /// <summary>
        /// Draws footer to the document.
        /// </summary>
        private PdfPageTemplateElement AddFooter(float width, string footerText)
        {
            RectangleF rect = new RectangleF(0, 0, width, 50);
            //Create a new instance of PdfPageTemplateElement class.
            PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
            PdfGraphics            g      = footer.Graphics;

            // Draw footer text.
            PdfSolidBrush brush = new PdfSolidBrush(Color.Gray);
            PdfFont       font  = new PdfTrueTypeFont(new Font("Helvetica", 6, FontStyle.Bold), true);
            float         x     = (width / 2) - (font.MeasureString(footerText).Width) / 2;

            g.DrawString(footerText, font, brush, new RectangleF(x, g.ClientSize.Height - 10, font.MeasureString(footerText).Width, font.Height));

            //Create page number field
            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field
            PdfPageCountField count = new PdfPageCountField(font, brush);

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;
            compositeField.Draw(g, new PointF(470, 40));

            return(footer);
        }
Exemple #24
0
        private void SetSectionTemplate(PdfSection section, SizeF pageSize, PdfMargins margin, String label)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);

            leftSpace.Foreground     = true;
            section.Template.OddLeft = leftSpace;

            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            float           y      = (pageSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f);
            RectangleF      bounds
                = new RectangleF(10, y, margin.Left - 20, font.Height + 6);

            leftSpace.Graphics.DrawRectangle(PdfBrushes.OrangeRed, bounds);
            leftSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);

            rightSpace.Foreground      = true;
            section.Template.EvenRight = rightSpace;
            bounds
                = new RectangleF(10, y, margin.Right - 20, font.Height + 6);
            rightSpace.Graphics.DrawRectangle(PdfBrushes.SaddleBrown, bounds);
            rightSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);
        }
Exemple #25
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);
        }
Exemple #26
0
        private byte[] CreateTextString(string text)
        {
            if (pdfFont.PdfFontType == PdfFont.FontType.TrueType)
            {
                PdfTrueTypeFont ttf = pdfFont as PdfTrueTypeFont;

                int    i     = 0;
                char[] glyph = new char[text.Length];

                for (int k = 0; k < text.Length; ++k)
                {
                    int[] metrics = ttf.GetMetricsTT(text[k]);

                    if (metrics != null)
                    {
                        glyph[i] = (char)metrics[0];
                        i++;
                    }
                }

                return(System.Text.Encoding.BigEndianUnicode.GetBytes(glyph));
            }
            else
            {
                string alter = Utility.TextEncode(text);
                return(System.Text.Encoding.ASCII.GetBytes(alter));
            }
        }
        private float AddDocumentLinkAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Document Link: ";
            SizeF  size   = font.MeasureString(prompt);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = font.MeasureString(prompt, format).Width;

            PdfDestination dest = new PdfDestination(page);

            dest.Mode     = PdfDestinationMode.Location;
            dest.Location = new PointF(0, y);
            dest.Zoom     = 2f;

            String label = "Click me, Zoom 200%";

            size = font.MeasureString(label);
            RectangleF bounds = new RectangleF(x, y, size.Width, size.Height);

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(bounds, dest);

            annotation.Color = Color.Blue;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = bounds.Bottom;

            return(y);
        }
        private PdfPageTemplateElement CreateHeaderTemplate(PdfDocument doc, PdfMargins margins)
        {
            //get page size
            SizeF pageSize = doc.PageSettings.Size;

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

            headerSpace.Foreground = false;

            //declare two float variables
            float x = margins.Left;
            float y = 0;
            //draw line in header space
            PdfPen pen = new PdfPen(PdfBrushes.Gray, 2);

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

            //draw text in header space
            PdfTrueTypeFont font       = new PdfTrueTypeFont(new Font("Helvetica", 25f, FontStyle.Bold));
            PdfStringFormat format     = new PdfStringFormat(PdfTextAlignment.Center);
            String          headerText = "SACRAMENT MEETING AGENDA";
            SizeF           size       = font.MeasureString(headerText, format);

            headerSpace.Graphics.DrawString(headerText, font, PdfBrushes.Gray, pageSize.Width - x - size.Width + 165, margins.Top - (size.Height + 5), format);

            //return headerSpace
            return(headerSpace);
        }
        private float AddRubberStampAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Markup incorrect spelling: ";
            SizeF  size   = font.MeasureString(prompt, format);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = size.Width;

            String label = "demo of annotation";

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            x = x + font.MeasureString(label, format).Width;
            String markupText = "Just a draft, not checked.";

            size = font.MeasureString(markupText);
            PdfRubberStampAnnotation annotation
                = new PdfRubberStampAnnotation(new RectangleF(x, y, font.Height, font.Height), markupText);

            annotation.Icon  = PdfRubberStampAnnotationIcon.Draft;
            annotation.Color = Color.Plum;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = y + size.Height;

            return(y);
        }
 public PdfInternalFont(Font font, bool unicode)
 {
     using (Stream stream = this.GetFontStream(font))
     {
         this.internalFont = new PdfTrueTypeFont(stream, font.Size, font.Style);
     }
 }
        private float AddPopupAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Markup incorrect spelling: ";
            SizeF  size   = font.MeasureString(prompt, format);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = size.Width;

            String label = "demo of annotation";

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            x = x + font.MeasureString(label, format).Width;
            String markupText = "All words were spelled correctly";

            size = font.MeasureString(markupText);
            PdfPopupAnnotation annotation
                = new PdfPopupAnnotation(new RectangleF(new PointF(x, y), SizeF.Empty), markupText);

            annotation.Icon  = PdfPopupIcon.Paragraph;
            annotation.Open  = true;
            annotation.Color = Color.Yellow;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = y + size.Height;

            return(y);
        }
Exemple #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;

            // 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");
        }
Exemple #33
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

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

            //Load image
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            float imageWidth = image.PhysicalDimension.Width / 2;
            float imageHeight = image.PhysicalDimension.Height / 2;
            foreach (PdfBlendMode mode in Enum.GetValues(typeof(PdfBlendMode)))
            {
                PdfPageBase page = section.Pages.Add();
                float pageWidth = page.Canvas.ClientSize.Width;
                float y = 0;

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

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

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

            //Launching the Pdf file.
            PDFDocumentViewer("Transparency.pdf");
        }
Exemple #34
0
        private void DrawPage(PdfPageBase page)
        {
            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("Category Sales by Year", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Category Sales by Year", format1).Height;
            y = y + 5;

            String[][] data
                = {
                    new String[]{"Category Name", "1994 Sale Amount", "1995 Sale Amount", "1996 Sale Amount"},
                    new String[]{"Beverages", "38,487.20", "102,479.46", "126,901.53"},
                    new String[]{"Condiments", "16,402.95", "51,041.83", "38,602.31"},
                    new String[]{"Confections", "23,812.90", "79,752.25", "63,792.07"},
                    new String[]{"Dairy Products", "30,027.79", "116,495.45", "87,984.05"},
                    new String[]{"Grains/Cereals", "7,313.92", "53,823.48", "34,607.19"},
                    new String[]{"Meat/Poultry", "19,856.86", "77,164.75", "66,000.75"},
                    new String[]{"Produce", "10,694.96", "45,973.69", "43,315.93"},
                    new String[]{"Seafood", "16,247.77", "64,195.51", "50,818.46"}
                };

            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.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            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;
            table.DataSource = data;

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

            PdfBrush brush2 = PdfBrushes.LightGray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString("* All data from NorthWind", font2, brush2, 5, y);
        }
        protected bool GenerateTransferPDF(BankTransfer transfer)
        {
            lock (this)
            {
                PdfDocument transferDetails = new PdfDocument();
                //transferDetails.
                Font pdfFont = new Font("Arial", 18f);
                PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(pdfFont, true);

                PdfPageBase TransferPage = transferDetails.Pages.Add();
                PdfBitmap logo = new PdfBitmap(SieradzBankFilesPathHolder.TransferFilesPath + @"..\mBank\logo.jpg");
                TransferPage.Canvas.DrawImage(logo, new RectangleF(new PointF(25.0f, 25.0f), new SizeF(140f, 85f)));
                TransferPage.Canvas.DrawString("\tPotwierdzenie przelewu:", new PdfFont(PdfFontFamily.Helvetica, 20f), new PdfSolidBrush(new PdfRGBColor(0, 0, 0)), 10, 150f);
                TransferPage.Canvas.DrawString(TransferDetailsString(transfer), trueTypeFont, new PdfSolidBrush(new PdfRGBColor(0, 0, 0)), 50, 180f);
                SavePDF(transferDetails);
            }

            return true;
        }
Exemple #36
0
        private void DrawAutomaticField(PdfPageBase page)
        {
            float y = 0;

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

            String[] fieldList = new String[]
            {
                "DateTimeField",
                "CreationDateField",
                "DocumentAuthorField",
                "SectionNumberField",
                "SectionPageNumberField",
                "SectionPageCountField",
                "PageNumberField",
                "PageCountField",
                "DestinationPageNumberField",
                "CompositeField"
            };
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat fieldNameFormat = new PdfStringFormat();
            fieldNameFormat.MeasureTrailingSpaces = true;
            foreach (String fieldName in fieldList)
            {
                //draw field name
                String text = String.Format("{0}: ", fieldName);
                page.Canvas.DrawString(text, font, PdfBrushes.DodgerBlue, 0, y);
                float x = font.MeasureString(text, fieldNameFormat).Width;
                RectangleF bounds = new RectangleF(x, y, 200, font.Height);
                DrawAutomaticField(fieldName, page, bounds);
                y = y + font.Height + 3;
            }
        }
Exemple #37
0
        private void SetSectionTemplate(PdfSection section, SizeF pageSize, PdfMargins margin, String label)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);
            leftSpace.Foreground = true;
            section.Template.OddLeft = leftSpace;

            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            float y = (pageSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f);
            RectangleF bounds
                = new RectangleF(10, y, margin.Left - 20, font.Height + 6);
            leftSpace.Graphics.DrawRectangle(PdfBrushes.OrangeRed, bounds);
            leftSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);
            rightSpace.Foreground = true;
            section.Template.EvenRight = rightSpace;
            bounds
                = new RectangleF(10, y, margin.Right - 20, font.Height + 6);
            rightSpace.Graphics.DrawRectangle(PdfBrushes.SaddleBrown, bounds);
            rightSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);
        }
Exemple #38
0
        private float DrawPageTitle(PdfPageBase page, float y)
        {
            PdfBrush brush1 = PdfBrushes.MidnightBlue;
            PdfBrush brush2 = PdfBrushes.Red;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            String title = "Your Account Information(* = Required)";
            SizeF size = font1.MeasureString(title);
            float x = (page.Canvas.ClientSize.Width - size.Width) / 2;
            page.Canvas.DrawString("Your Account Information(", font1, brush1, x, y);
            size = font1.MeasureString("Your Account Information(");
            x = x + size.Width;
            page.Canvas.DrawString("* = Required", font1, brush2, x, y);
            size = font1.MeasureString("* = Required");
            x = x + size.Width;
            page.Canvas.DrawString(")", font1, brush1, x, y);
            y = y + size.Height;

            y = y + 3;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic));
            String p = "Your information is not public, shared in anyway, or displayed on this site.";
            page.Canvas.DrawString(p, font2, brush1, 0, y);

            return y + font2.Height;
        }
Exemple #39
0
 private float DrawFormSection(String label, PdfPageBase page, float y)
 {
     PdfBrush brush1 = PdfBrushes.LightYellow;
     PdfBrush brush2 = PdfBrushes.DarkSlateGray;
     PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
     PdfStringFormat format = new PdfStringFormat();
     float height = font.MeasureString(label).Height;
     page.Canvas.DrawRectangle(brush2, 0, y, page.Canvas.ClientSize.Width, height + 2);
     page.Canvas.DrawString(label, font, brush1, 2, y + 1);
     y = y + height + 2;
     PdfPen pen = new PdfPen(PdfBrushes.LightSkyBlue, 0.75f);
     page.Canvas.DrawLine(pen, 0, y, page.Canvas.ClientSize.Width, y);
     return y + 0.75f;
 }
Exemple #40
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");
        }
Exemple #41
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();            

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

            //Draw the text
            float l = page.Canvas.ClientSize.Width / 2;
            PointF center = new PointF(l, l);
            float r = (float)Math.Sqrt(2 * l * l);
            PdfRadialGradientBrush brush
                = new PdfRadialGradientBrush(center, 0f, center, r, Color.Blue, Color.Red);
            PdfFontFamily[] fontFamilies
                = (PdfFontFamily[])Enum.GetValues(typeof(PdfFontFamily));
            float y = 10;
            for(int i = 0; i < fontFamilies.Length; i++)
            {
                String text = String.Format("Font Family: {0}", fontFamilies[i]);
                float x1 = 0;
                y = 10 + i * 16;
                PdfFont font1 = new PdfFont(PdfFontFamily.Courier, 14f);
                PdfFont font2 = new PdfFont(fontFamilies[i], 14f);
                float x2 = x1 + 10 + font1.MeasureString(text).Width;
                page.Canvas.DrawString(text, font1, brush, x1, y);
                page.Canvas.DrawString(text, font2, brush, x2, y);
            }
            
            //true type font - embedded.
            System.Drawing.Font font = new System.Drawing.Font("Arial", 14f, FontStyle.Bold);
            PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(font);
            page.Canvas.DrawString("Font Family: Arial - Embedded", trueTypeFont, brush, 0, (y = y + 16f));

            //right to left
            String arabicText
                = "\u0627\u0644\u0630\u0647\u0627\u0628\u0021\u0020"
                + "\u0628\u062F\u0648\u0631\u0647\u0020\u062D\u0648\u0644\u0647\u0627\u0021\u0020"
                + "\u0627\u0644\u0630\u0647\u0627\u0628\u0021\u0020"
                + "\u0627\u0644\u0630\u0647\u0627\u0628\u0021\u0020"
                + "\u0627\u0644\u0630\u0647\u0627\u0628\u0021";
            trueTypeFont = new PdfTrueTypeFont(font, true);
            RectangleF rctg = new RectangleF(new PointF(0, (y = y + 16f)), page.Canvas.ClientSize);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
            format.RightToLeft = true;
            page.Canvas.DrawString(arabicText, trueTypeFont, brush, rctg, format);

            //true type font - not embedded
            font = new System.Drawing.Font("Batang", 14f, FontStyle.Italic);
            trueTypeFont = new PdfTrueTypeFont(font);
            page.Canvas.DrawString("Font Family: Batang - Not Embedded", trueTypeFont, brush, 0, (y = y + 16f));

            //font file
            String fontFileName = @"..\..\..\..\..\..\Data\Hawaii_Killer.ttf";
            trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);
            page.Canvas.DrawString("Hawaii Killer Font", trueTypeFont, brush, 0, (y = y + 16f));
            page.Canvas.DrawString("Hawaii Killer Font, from http://www.1001freefonts.com", new PdfFont(PdfFontFamily.Helvetica, 8f), brush, 10, (y = y + 20f));

            //cjk font
            PdfCjkStandardFont cjkFont = new PdfCjkStandardFont(PdfCjkFontFamily.MonotypeHeiMedium, 14f);
            page.Canvas.DrawString("How to say 'Font' in Chinese? \u5B57\u4F53", cjkFont, brush, 0, (y = y + 16f));

            cjkFont = new PdfCjkStandardFont(PdfCjkFontFamily.HanyangSystemsGothicMedium, 14f);
            page.Canvas.DrawString("How to say 'Font' in Japanese? \u30D5\u30A9\u30F3\u30C8", cjkFont, brush, 0, (y = y + 16f));

            cjkFont = new PdfCjkStandardFont(PdfCjkFontFamily.HanyangSystemsShinMyeongJoMedium, 14f);
            page.Canvas.DrawString("How to say 'Font' in Korean? \uAE00\uAF34", cjkFont, brush, 0, (y = y + 16f));

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

            //Launching the Pdf file.
            PDFDocumentViewer("Font.pdf");

        }
Exemple #42
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");
        }
Exemple #43
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");
        }
Exemple #44
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");
        }
        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();
        }
Exemple #46
0
        private PdfLayoutResult DrawVendor(PdfPageBase page, DataTable vendors, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            DataRow row = vendors.Rows[index];
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[vendors.Columns.Count][];
            for (int i = 0; i < vendors.Columns.Count; i++)
            {
                data[i] = new Object[2];
                data[i][0] = vendors.Columns[i].ColumnName;
                data[i][1] = vendors.Rows[index].ItemArray[i];
            }

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(2, 2, 1, 1);
            grid.DataSource = data;

            float width
                = page.Canvas.ClientSize.Width
                    - (grid.Columns.Count + 1) * 0.75f;
            grid.Columns[0].Width = width * 0.20f;
            grid.Columns[1].Width = width * 0.80f;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f));
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Style.Font = font2;
                grid.Rows[i].Cells[0].Style.BackgroundBrush = PdfBrushes.CadetBlue;
                grid.Rows[i].Cells[1].Style.BackgroundBrush = PdfBrushes.SkyBlue;
            }

            PdfGridLayoutFormat layout = new PdfGridLayoutFormat();
            layout.Break = PdfLayoutBreakType.FitPage;
            layout.Layout = PdfLayoutType.Paginate;

            return grid.Draw(page, new PointF(0, y), layout);
        }
Exemple #47
0
        private PdfLayoutResult DrawPart(PdfPageBase page, DataTable parts, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            DataRow row = parts.Rows[index];
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[2][];
            data[0] = new String[parts.Columns.Count];
            for (int i = 0; i < parts.Columns.Count; i++)
            {
                data[0][i] = parts.Columns[i].ColumnName;
            }
            data[1] = row.ItemArray;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.GreenYellow;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f));
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.ForestGreen;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource = data;

            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for (int i = 0; i < table.Columns.Count; i++)
            {
                table.Columns[i].Width = i == 1 ? width * 0.35f : width * 0.13f;
            }

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

            return table.Draw(page, new PointF(0, y), tableLayout);
        }
Exemple #48
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");
        }
Exemple #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;

            //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");
        }
Exemple #50
0
        private PdfLayoutResult DrawOrderItems(PdfPageBase page, DataTable orderItems, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.MediumTurquoise;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.PaleTurquoise;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Teal;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource = orderItems;
            for (int i = 2; i < table.Columns.Count; i++)
            {
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            }

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

            return table.Draw(page, new PointF(0, y), tableLayout);
        }
        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);
        }
Exemple #52
0
        private void DrawPage(PdfPageBase page)
        {
            float pageWidth = page.Canvas.ClientSize.Width;
            float y = 0;

            //page header
            PdfPen pen1 = new PdfPen(Color.LightGray, 1f);
            PdfBrush brush1 = new PdfSolidBrush(Color.LightGray);
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right);
            String text = "Demo of Spire.Pdf";
            page.Canvas.DrawString(text, font1, brush1, pageWidth, y, format1);
            SizeF size = font1.MeasureString(text, format1);
            y = y + size.Height + 1;
            page.Canvas.DrawLine(pen1, 0, y, pageWidth, y);

            //title
            y = y + 5;
            PdfBrush brush2 = new PdfSolidBrush(Color.Black);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center);
            format2.CharacterSpacing = 1f;
            text = "Summary of Science";
            page.Canvas.DrawString(text, font2, brush2, pageWidth / 2, y, format2);
            size = font2.MeasureString(text, format2);
            y = y + size.Height + 6;

            //icon
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Wikipedia_Science.png");
            page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y));
            float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2;
            float imageBottom = image.PhysicalDimension.Height + y;

            //refenrence content
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat format3 = new PdfStringFormat();
            format3.ParagraphIndent = font3.Size * 2;
            format3.MeasureTrailingSpaces = true;
            format3.LineSpacing = font3.Size * 1.5f;
            String text1 = "(All text and picture from ";
            String text2 = "Wikipedia";
            String text3 = ", the free encyclopedia)";
            page.Canvas.DrawString(text1, font3, brush2, 0, y, format3);

            size = font3.MeasureString(text1, format3);
            float x1 = size.Width;
            format3.ParagraphIndent = 0;
            PdfTrueTypeFont font4 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Underline));
            PdfBrush brush3 = PdfBrushes.Blue;
            page.Canvas.DrawString(text2, font4, brush3, x1, y, format3);
            size = font4.MeasureString(text2, format3);
            x1 = x1 + size.Width;

            page.Canvas.DrawString(text3, font3, brush2, x1, y, format3);
            y = y + size.Height;

            //content
            PdfStringFormat format4 = new PdfStringFormat();
            text = System.IO.File.ReadAllText(@"..\..\..\..\..\..\Data\Summary_of_Science.txt");
            PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f));
            format4.LineSpacing = font5.Size * 1.5f;
            PdfStringLayouter textLayouter = new PdfStringLayouter();
            float imageLeftBlockHeight = imageBottom - y;
            PdfStringLayoutResult result
                = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            if (result.ActualSize.Height < imageBottom - y)
            {
                imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight;
                result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            }
            foreach (LineInfo line in result.Lines)
            {
                page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4);
                y = y + result.LineHeight;
            }
            PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2);
            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
            textWidget.StringFormat = format4;
            textWidget.Draw(page, bounds, textLayout);
        }
Exemple #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), 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");
        }
Exemple #54
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;
        }
Exemple #55
0
        private PdfLayoutResult DrawTable(PdfPageBase page, float y)
        {
            PdfBrush brush1 = PdfBrushes.Black;

            //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;
        }
Exemple #56
0
        private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);
            doc.Template.Left = leftSpace;

            PdfPageTemplateElement topSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Top);
            topSpace.Foreground = true;
            doc.Template.Top = topSpace;

            //draw header label
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
            String label = "Demo of Spire.Pdf";
            SizeF size = font.MeasureString(label, format);
            float y = topSpace.Height - font.Height - 1;
            PdfPen pen = new PdfPen(Color.Black, 0.75f);
            topSpace.Graphics.SetTransparency(0.5f);
            topSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y);
            y = y - 1 - size.Height;
            topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);
            doc.Template.Right = rightSpace;

            PdfPageTemplateElement bottomSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Bottom);
            bottomSpace.Foreground = true;
            doc.Template.Bottom = bottomSpace;

            //draw footer label
            y = font.Height + 1;
            bottomSpace.Graphics.SetTransparency(0.5f);
            bottomSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, 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 = font;
            pageNumberLabel.StringFormat = format;
            pageNumberLabel.Text = "page {0} of {1}";
            pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - margin.Right, y);

            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PointF pageLeftTop = new PointF(-margin.Left, -margin.Top);
            PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension);
            header.Foreground = false;
            header.Graphics.SetTransparency(0.5f);
            header.Graphics.DrawImage(headerImage, 0, 0);
            doc.Template.Stamps.Add(header);

            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");
            y = pageSize.Height - footerImage.PhysicalDimension.Height;
            PointF footerLocation = new PointF(-margin.Left, y);
            PdfPageTemplateElement footer = new PdfPageTemplateElement(footerLocation, footerImage.PhysicalDimension);
            footer.Foreground = false;
            footer.Graphics.SetTransparency(0.5f);
            footer.Graphics.DrawImage(footerImage, 0, 0);
            doc.Template.Stamps.Add(footer);
        }
Exemple #57
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");
        }
Exemple #58
0
        private float DrawFormField(XPathNavigator fieldNode, PdfForm form, PdfPageBase page, float y, int fieldIndex)
        {
            float width = page.Canvas.ClientSize.Width;
            float padding = 2;

            //measure field label
            String label = fieldNode.GetAttribute("label", "");
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            float labelMaxWidth = width * 0.4f - 2 * padding;
            SizeF labelSize = font1.MeasureString(label, labelMaxWidth, format);

            //measure field height
            float fieldHeight = MeasureFieldHeight(fieldNode);

            float height = labelSize.Height > fieldHeight ? labelSize.Height : fieldHeight;
            height = height + 2;

            //draw background
            PdfBrush brush = PdfBrushes.SteelBlue;
            if (fieldIndex % 2 == 1)
            {
                brush = PdfBrushes.LightGreen;
            }
            page.Canvas.DrawRectangle(brush, 0, y, width, height);

            //draw field label
            PdfBrush brush1 = PdfBrushes.LightYellow;
            RectangleF labelBounds = new RectangleF(padding, y, labelMaxWidth, height);
            page.Canvas.DrawString(label, font1, brush1, labelBounds, format);

            //daw field
            float fieldMaxWidth = width * 0.57f - 2 * padding;
            float fieldX = labelBounds.Right + 2 * padding;
            float fieldY = y + (height - fieldHeight) / 2;
            String fieldType = fieldNode.GetAttribute("type", "");
            String fieldId = fieldNode.GetAttribute("id", "");
            bool required = "true" == fieldNode.GetAttribute("required", "");
            switch (fieldType)
            {
                case "text":
                case "password":
                    PdfTextBoxField textField = new PdfTextBoxField(page, fieldId);
                    textField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                    textField.BorderWidth = 0.75f;
                    textField.BorderStyle = PdfBorderStyle.Solid;
                    textField.Required = required;
                    if ("password" == fieldType)
                    {
                        textField.Password = true;
                    }
                    if ("true" == fieldNode.GetAttribute("multiple", ""))
                    {
                        textField.Multiline = true;
                        textField.Scrollable = true;
                    }
                    form.Fields.Add(textField);
                    break;
                case "checkbox":
                    PdfCheckBoxField checkboxField = new PdfCheckBoxField(page, fieldId);
                    float checkboxWidth = fieldHeight - 2 * padding;
                    float checkboxHeight = checkboxWidth;
                    checkboxField.Bounds = new RectangleF(fieldX, fieldY + padding, checkboxWidth, checkboxHeight);
                    checkboxField.BorderWidth = 0.75f;
                    checkboxField.Style = PdfCheckBoxStyle.Cross;
                    checkboxField.Required = required;
                    form.Fields.Add(checkboxField);
                    break;

                case "list":
                    XPathNodeIterator itemNodes = fieldNode.Select("item");
                    if ("true" == fieldNode.GetAttribute("multiple", ""))
                    {
                        PdfListBoxField listBoxField = new PdfListBoxField(page, fieldId);
                        listBoxField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                        listBoxField.BorderWidth = 0.75f;
                        listBoxField.MultiSelect = true;
                        listBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
                        listBoxField.Required = required;
                        //add items into list box.
                        foreach (XPathNavigator itemNode in itemNodes)
                        {
                            String text = itemNode.SelectSingleNode("text()").Value;
                            listBoxField.Items.Add(new PdfListFieldItem(text, text));
                        }
                        listBoxField.SelectedIndex = 0;
                        form.Fields.Add(listBoxField);

                        break;
                    }
                    if (itemNodes != null && itemNodes.Count <= 3)
                    {
                        PdfRadioButtonListField radioButtonListFile
                            = new PdfRadioButtonListField(page, fieldId);
                        radioButtonListFile.Required = required;
                        //add items into radio button list.
                        float fieldItemHeight = fieldHeight / itemNodes.Count;
                        float radioButtonWidth = fieldItemHeight - 2 * padding;
                        float radioButtonHeight = radioButtonWidth;
                        foreach (XPathNavigator itemNode in itemNodes)
                        {
                            String text = itemNode.SelectSingleNode("text()").Value;
                            PdfRadioButtonListItem fieldItem = new PdfRadioButtonListItem(text);
                            fieldItem.BorderWidth = 0.75f;
                            fieldItem.Bounds = new RectangleF(fieldX, fieldY + padding, radioButtonWidth, radioButtonHeight);
                            radioButtonListFile.Items.Add(fieldItem);

                            float fieldItemLabelX = fieldX + radioButtonWidth + padding;
                            SizeF fieldItemLabelSize = font1.MeasureString(text);
                            float fieldItemLabelY = fieldY + (fieldItemHeight - fieldItemLabelSize.Height) / 2;
                            page.Canvas.DrawString(text, font1, brush1, fieldItemLabelX, fieldItemLabelY);

                            fieldY = fieldY + fieldItemHeight;
                        }
                        form.Fields.Add(radioButtonListFile);

                        break;
                    }

                    //combo box
                    PdfComboBoxField comboBoxField = new PdfComboBoxField(page, fieldId);
                    comboBoxField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                    comboBoxField.BorderWidth = 0.75f;
                    comboBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
                    comboBoxField.Required = required;
                    //add items into combo box.
                    foreach (XPathNavigator itemNode in itemNodes)
                    {
                        String text = itemNode.SelectSingleNode("text()").Value;
                        comboBoxField.Items.Add(new PdfListFieldItem(text, text));
                    }
                    form.Fields.Add(comboBoxField);
                    break;

            }

            if (required)
            {
                //draw *
                float flagX = width * 0.97f + padding;
                PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
                SizeF size = font3.MeasureString("*");
                float flagY = y + (height - size.Height) / 2;
                page.Canvas.DrawString("*", font3, PdfBrushes.Red, flagX, flagY);
            }

            return y + height;
        }
        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);
        }
Exemple #60
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");
        }