Exemplo n.º 1
1
        void Pdf_Clicked(object sender, EventArgs args)
        {
            PdfDocument document = new PdfDocument();
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 50;
            PdfPage page = document.Pages.Add();
            PdfGraphics g = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");
            element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg");
            PdfImage img = PdfImage.FromStream(imgStream);
            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            g.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 20));


            PdfGrid grid = new PdfGrid();
            grid.DataSource = GetDataSource();
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();
            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();
            headerStyle.Borders.All = new PdfPen(new PdfColor(126, 151, 173));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
            headerStyle.TextBrush = PdfBrushes.White;
            headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                else
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            }

            header.ApplyStyle(headerStyle);
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f);
            cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    else
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

                    if (i > 1)
                    {
                        float val = float.MinValue;
                        float.TryParse(cell.Value.ToString(), out val);
                        cell.Value = "$" + val.ToString();
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + 40), new Syncfusion.Drawing.SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;
            for (int i = 0; i < grid.Columns.Count - 1; i++)
                pos += grid.Columns[i].Width;

            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);

            gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new Syncfusion.Drawing.PointF(pos - 55, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$13600", font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));


            MemoryStream data = new MemoryStream();

            document.Save(data);

            document.Close();

            DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data);
          

        }
Exemplo n.º 2
0
        public PdfLayoutResult HeaderPoints(string text, float yPosition, PdfPage page)
        {
            float          headerBulletsXposition = 35;
            PdfTextElement txtElement             = new PdfTextElement("")
            {
                Font         = new PdfStandardFont(PdfFontFamily.TimesRoman, 13),
                Brush        = new PdfSolidBrush(aliceBlue),
                StringFormat = new PdfStringFormat()
            };

            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 300, 100));


            txtElement = new PdfTextElement(text)
            {
                Font         = new PdfStandardFont(PdfFontFamily.TimesRoman, 11),
                StringFormat = new PdfStringFormat()
            };

            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 20, yPosition, 320, 100));

            return(result);
        }
Exemplo n.º 3
0
        public MemoryStream PdfBuktiBank(TranshView trans)
        {
            var buktibank = _context.CbTransHs.Include(p => p.CbTransDs).Where(x => x.DocNo == trans.DocNo).FirstOrDefaultAsync();

            if (buktibank == null)
            {
                throw new ArgumentNullException("Transaksi cannot be null");
            }

            using (PdfDocument pdfDocument = new PdfDocument())
            {
                //  int paragraphAfterSpacing = 8;
                //  int cellMargin = 8;

                //Add page to the PDF document
                PdfPage page = pdfDocument.Pages.Add();

                //Create a new font
                PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

                //Create a text element to draw a text in PDF page
                PdfTextElement  title  = new PdfTextElement("BUKTI KAS/BANK", font, PdfBrushes.Black);
                PdfLayoutResult result = title.Draw(page, new PointF(0, 0));


                using (MemoryStream stream = new MemoryStream())
                {
                    //Saving the PDF document into the stream
                    pdfDocument.Save(stream);
                    //Closing the PDF document
                    pdfDocument.Close(true);
                    return(stream);
                }
            }
        }
Exemplo n.º 4
0
        private void generatePdf()
        {
            //Add a page
            _document.PageSettings.Margins.All = 0;
            _document.Pages.Add();

            createHeader();
            createFooter();

            currentY = marginTop;
            addTitles();              //title & subtitle

            currentY += spaceLine;

            //testo
            PdfStringFormat stringFormat = new PdfStringFormat()
            {
                Alignment = PdfTextAlignment.Left
            };
            PdfTextElement  element = new PdfTextElement(Text, textFont, brushBlack);
            PdfLayoutFormat format  = new PdfLayoutFormat();

            format.Layout         = PdfLayoutType.Paginate;
            format.PaginateBounds = new RectangleF(marginLeft, heightHeader + spaceDefault + spaceSubtitle, _document.PageSettings.Size.Width - marginRight - marginLeft, _document.PageSettings.Size.Height - marginTop * 3);

            element.Draw(_document.Pages [0], new RectangleF(marginLeft, currentY, _document.PageSettings.Width - marginRight - marginLeft, _document.PageSettings.Height - marginTop * 3));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a text to PDF page and return the layout result.
        /// </summary>
        public PdfLayoutResult AddParagraph(PdfPage page, string text, RectangleF bounds, bool isTitle, bool mainTitle = false)
        {
            //Set string format, font size, style.
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify);
            PdfFontStyle    style  = PdfFontStyle.Regular;
            float           size   = 13;

            if (mainTitle)
            {
                format = new PdfStringFormat(PdfTextAlignment.Center);
            }

            if (isTitle)
            {
                size = 18;
                if (mainTitle)
                {
                    size = 24;
                }
            }

            if (isTitle && !mainTitle)
            {
                style = PdfFontStyle.Bold;
            }

            //Create text element and draw it to PDF page.
            PdfTextElement element = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.Helvetica, size, style), PdfBrushes.Black);

            element.StringFormat = format;
            return(element.Draw(page, bounds));
        }
Exemplo n.º 6
0
        public PdfLayoutResult BodyContent(string text, float yPosition, PdfPage page)
        {
            float          headerBulletsXposition = 35;
            PdfTextElement txtElement             = new PdfTextElement("")
            {
                Font         = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 16),
                StringFormat = new PdfStringFormat()
            };

            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 320, 100));


            txtElement = new PdfTextElement(text)
            {
                Font         = new PdfStandardFont(PdfFontFamily.TimesRoman, 17),
                StringFormat = new PdfStringFormat()
            };

            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 25, yPosition, 450, 130));

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates PDF document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Set compression level
            doc.Compression = PdfCompressionLevel.None;

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

            //Read the text from the text file
            string path = ResolveApplicationDataPath("Manual.txt");
            StreamReader reader = new StreamReader(path, Encoding.ASCII);
            string text = reader.ReadToEnd();
            reader.Close();

            //Set the font
            Font f = new Font("Arial", 12);
            PdfTrueTypeFont font = new PdfTrueTypeFont(f, false);

            //Set the formats for the text
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Justify;
            format.LineAlignment = PdfVerticalAlignment.Top;
            format.ParagraphIndent = 15f;

            //Create a text element
            PdfTextElement element = new PdfTextElement(text, font);
            element.Brush = new PdfSolidBrush(Color.Black);
            element.StringFormat = format;
            element.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

            //Set the properties to paginate the text.
            PdfLayoutFormat layoutFormat = new PdfLayoutFormat();
            layoutFormat.Break = PdfLayoutBreakType.FitPage;
            layoutFormat.Layout = PdfLayoutType.Paginate;

            RectangleF bounds = new RectangleF(PointF.Empty, page.Graphics.ClientSize);

            //Raise the events to draw the graphic elements for each page.
            element.BeginPageLayout += new BeginPageLayoutEventHandler(BeginPageLayout);
            element.EndPageLayout += new EndPageLayoutEventHandler(EndPageLayout);

            //Draw the text element with the properties and formats set.
            PdfTextLayoutResult result = element.Draw(page, bounds, layoutFormat);

            //Stream the output to the browser.
            if (this.CheckBox1.Checked)
            {
                doc.Save("Sample.pdf", Response, HttpReadType.Open);
            }
            else
            {
                doc.Save("Sample.pdf", Response, HttpReadType.Save);
            }
        }
Exemplo n.º 8
0
        //Export weather data to PDF document.
        public MemoryStream CreatePdf(WeatherForecast[] forecasts)
        {
            if (forecasts == null)
            {
                throw new ArgumentNullException("Forecast cannot be null");
            }
            //Create a new PDF document
            using (PdfDocument pdfDocument = new PdfDocument())
            {
                int paragraphAfterSpacing = 8;
                int cellMargin            = 8;
                //    pdfDocument.PageSettings.Size = PdfPageSize.A4;
                //Add page to the PDF document
                PdfPage page = pdfDocument.Pages.Add();

                //Create a new font
                PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

                //Create a text element to draw a text in PDF page
                PdfTextElement  title  = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black);
                PdfLayoutResult result = title.Draw(page, new PointF(0, 0));


                PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfTextElement  content     = new PdfTextElement("This component demonstrates fetching data from a service and Exporting the data to PDF document using Syncfusion .NET PDF library.", contentFont, PdfBrushes.Black);
                PdfLayoutFormat format      = new PdfLayoutFormat();
                format.Layout = PdfLayoutType.Paginate;

                //Draw a text to the PDF document
                result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format);

                //Create a PdfGrid
                PdfGrid pdfGrid = new PdfGrid();
                pdfGrid.Style.CellPadding.Left  = cellMargin;
                pdfGrid.Style.CellPadding.Right = cellMargin;

                //Applying built-in style to the PDF grid
                pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

                //Assign data source
                pdfGrid.DataSource = forecasts;

                pdfGrid.Style.Font = contentFont;

                //Draw PDF grid into the PDF page
                pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + paragraphAfterSpacing));

                using (MemoryStream stream = new MemoryStream())
                {
                    //Saving the PDF document into the stream
                    pdfDocument.Save(stream);
                    //Closing the PDF document
                    pdfDocument.Close(true);
                    return(stream);
                }
            }
        }
        public void DrawText(string text, float x, float y, PdfFont font = null, PdfBrush brush = null, PdfGraphics graphics = null)
        {
            font     = font ?? NormalFont;
            brush    = brush ?? AccentBrush;
            graphics = graphics ?? CurrentPageGraphics;

            PdfTextElement element = new PdfTextElement(text, font, brush);

            element.Draw(graphics, new PointF(x, y));
        }
Exemplo n.º 10
0
        public MemoryStream CreatePdf(WeatherForecast[] weatherForecasts)
        {
            if (weatherForecasts == null)
            {
                throw new ArgumentException("Data cannot be null");
            }
            //Create a new PDF document

            using (PdfDocument pdfDocument = new PdfDocument())
            {
                int paragraphAfterSpacing = 8;
                int cellMargin            = 8;

                //Add page to the pdf Document
                PdfPage page = pdfDocument.Pages.Add();

                //create New Font
                PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

                //Create a text elemet to draw a text in PDf Page
                PdfTextElement  title  = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black);
                PdfLayoutResult result = title.Draw(page, new PointF(0, 0));


                PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
                PdfLayoutFormat format      = new PdfLayoutFormat();
                format.Layout = PdfLayoutType.Paginate;


                //Create PDF
                PdfGrid pdfGrid = new PdfGrid();
                pdfGrid.Style.CellPadding.Left  = cellMargin;
                pdfGrid.Style.CellPadding.Right = cellMargin;

                //Apply built in Styke to the PDF grid
                pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

                //Assing Data Source
                pdfGrid.DataSource = weatherForecasts.ToList();

                pdfGrid.Style.Font = contentFont;


                //Draw PDf Grid into the pdf Page
                pdfGrid.Draw(page, new PointF(0, result.Bounds.Bottom + paragraphAfterSpacing));

                using (MemoryStream stream = new MemoryStream())
                {
                    pdfDocument.Save(stream);
                    pdfDocument.Close(true);
                    return(stream);
                }
            }
        }
Exemplo n.º 11
0
        public void ExportToPdf(List <T> entities, string reportTitle, ReportRequest reportRequest, List <string> columns)
        {
            int         paragraphAfterSpacing = 8;
            int         cellMargin            = 8;
            PdfDocument pdfDocument           = new PdfDocument();
            //Add Page to the PDF document.
            PdfPage page = pdfDocument.Pages.Add();

            //Create a new font.
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

            //Create a text element to draw a text in PDF page.
            PdfTextElement  title  = new PdfTextElement(reportTitle, font, PdfBrushes.Black);
            PdfLayoutResult result = title.Draw(page, new PointF(0, 0));

            var contentInfo = CreateContentInfo(reportRequest, entities);

            PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            PdfTextElement  content     = new PdfTextElement(contentInfo, contentFont, PdfBrushes.Black);
            PdfLayoutFormat format      = new PdfLayoutFormat();

            format.Layout = PdfLayoutType.Paginate;

            //Draw a text to the PDF document.
            result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format);

            //Create a PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();

            pdfGrid.Style.CellPadding.Left  = cellMargin;
            pdfGrid.Style.CellPadding.Right = cellMargin;

            //Applying built-in style to the PDF grid
            pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

            //Create data to populate table
            DataTable table = CreateDataSourceTable(entities, columns);

            //Assign data source.
            pdfGrid.DataSource = table;

            pdfGrid.Style.Font = contentFont;

            //Draw PDF grid into the PDF page.
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + paragraphAfterSpacing));

            MemoryStream memoryStream = new MemoryStream();

            // Save the PDF document.
            pdfDocument.Save(memoryStream);

            // Download the PDF document
            _jsRuntime.SaveAs(reportTitle + ".pdf", memoryStream.ToArray());
        }
Exemplo n.º 12
0
        private void GeneratePDF()
        {
            //Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.arial.ttf");
            //PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12);

            //Create a new PDF document
            using (PdfDocument doc = new PdfDocument())
            {
                //Font initialization.
                System.Drawing.Font tempfont = new System.Drawing.Font("/App_Data/ARIALUNI.ttf", 11, FontStyle.Regular);
                //Enable unicode to draw unicode characters.
                PdfTrueTypeFont currentFont = new PdfTrueTypeFont(tempfont, true);


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

                //Create a PdfGrid
                PdfGrid pdfGrid = new PdfGrid();
                //  RSD --PdfFont font = new PdfTrueTypeFont(Server.MapPath("/App_Data/ARIALUNI.ttf"), 24);
                //   Stream fontStream = typeof(SOSubmitChecklist).GetTypeInfo().Assembly.GetManifestResourceStream("Demo.Assets.arial.ttf");

                pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12);

                //Create a DataTable
                DataTable SO1CheckList = new DataTable();

                dsShowAllDocData = dbFamilyDetailsData.getSO1SubmitCheckList(cmbVillage.SelectedValue.ToString(), cmbDocumentNo.SelectedValue.ToString(), "SO1");
                if (dsShowAllDocData.Tables[0].Rows.Count > 0)
                {
                    SO1CheckList = dsShowAllDocData.Tables[0];
                }

                //Assign data source
                pdfGrid.DataSource = SO1CheckList;

                //Draw grid to the page of PDF document
                pdfGrid.Draw(page, new PointF(20, 10));
                //Font
                pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12);
                //PdfFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS Regular", 12, FontStyle.Regular), true);
                PdfTextElement textElement = new PdfTextElement("Unicode characters राजेंद्र ");
                textElement.Font  = new PdfTrueTypeFont(currentFont, 12);
                textElement.Brush = PdfBrushes.Black;
                textElement.Draw(page, new PointF(10, 10));

                //pdfGrid.PDFFonts = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase);
                //pdfGrid.PDFFonts.Add("MS Mincho", assembly.GetManifestResourceStream("WinRTSampleApplication.Assets.msmincho.ttf"));
                //Save the document

                doc.Save(@"F:\\Output.pdf");
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Add content in table of content and return the layout result.
        /// </summary>
        PdfLayoutResult AddTableOfContents(PdfPage page, string text, RectangleF bounds, bool isTitle, int pageNo, float x, float y, PdfPage destPage)
        {
            //Set font style.
            PdfFontStyle style = isTitle ? PdfFontStyle.Bold : PdfFontStyle.Regular;
            //Create a font and draw the text to PDF page.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 13, style);

            page.Graphics.DrawString(pageNo.ToString(), font, PdfBrushes.Black, new RectangleF(480, bounds.Top + 5, bounds.Width, bounds.Height));
            //Create a pdf destination for document link annotation.
            PdfDestination pdfDestination   = new PdfDestination(destPage, new PointF(x, y));
            RectangleF     annotationBounds = RectangleF.Empty;

            if (isTitle)
            {
                annotationBounds = new RectangleF(bounds.Left, bounds.Top - 45, bounds.Width, font.Height);
            }
            else
            {
                annotationBounds = new RectangleF(bounds.Left + 20, bounds.Top - 45, bounds.Width - 20, font.Height);
            }
            //Create document link annotation with bounds.
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(annotationBounds, pdfDestination);

            annotation.Border.Width = 0;
            //Add annotation to PDF page.
            page.Annotations.Add(annotation);

            //Measure the text size to draw in PDF page.
            string str   = text + ' ';
            float  width = isTitle ? font.MeasureString(text).Width + 20 : font.MeasureString(text).Width + 40;

            for (float i = width; i < 470;)
            {
                str = str + '.';
                i   = i + 3.6140000000000003F;
            }

            //Create text element and draw it to PDF page.
            PdfTextElement element = new PdfTextElement(str, font, PdfBrushes.Black);

            if (isTitle)
            {
                bounds = new RectangleF(bounds.Left, bounds.Top + 5, bounds.Width, bounds.Height);
            }
            else
            {
                bounds = new RectangleF(bounds.Left + 20, bounds.Top + 5, bounds.Width, bounds.Height);
            }

            return(element.Draw(page, bounds));
        }
Exemplo n.º 14
0
 private PdfLayoutResult OutputSingleLine(PdfPage page, PdfLayoutResult result, PdfTextElement element, string question, string answer)
 {
     try
     {
         element       = new PdfTextElement(question, timesRoman);
         element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
         result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + _lineSpacing));
         element       = new PdfTextElement(answer, timesRoman);
         element.Brush = new PdfSolidBrush(new PdfColor(52, 173, 152));
     }
     catch (Exception e)
     {
     }
     return(result = element.Draw(page, new PointF(10, result.Bounds.Bottom + _lineSpacing)));
 }
Exemplo n.º 15
0
        private PdfLayoutResult BodyContent(string text, PdfFont font, Color color, PdfTextAlignment alignment, PdfVerticalAlignment hAlignment, PdfPage page, RectangleF rectangleF)
        {
            PdfTextElement txtElement = new PdfTextElement(text);

            txtElement.Font                       = font;
            txtElement.Brush                      = new PdfSolidBrush(color);
            txtElement.StringFormat               = new PdfStringFormat();
            txtElement.StringFormat.WordWrap      = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit     = true;
            txtElement.StringFormat.Alignment     = alignment;
            txtElement.StringFormat.LineAlignment = hAlignment;
            PdfLayoutResult result = txtElement.Draw(page, rectangleF);

            return(result);
        }
        public ActionResult GenerateGuide(int id)
        {
            Module module = moduleService.FindById(id, new String[] { "Teacher" });

            using (MemoryStream ms = new MemoryStream())
            {
                FileStream imageStream = new FileStream("./wwwroot/images/logo.png", FileMode.Open,
                                                        FileAccess.Read);

                PdfBitmap image = new PdfBitmap(imageStream);

                //Create a new PDF document
                PdfDocument document = new PdfDocument();

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

                //Create PDF graphics for the page
                PdfGraphics graphics = page.Graphics;

                //Set the standard font
                PdfFont headerFont = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
                PdfFont font       = new PdfStandardFont(PdfFontFamily.Helvetica, 13);

                //Header
                graphics.DrawString(String.Format("Academie voor Engineering en ICT"), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
                graphics.DrawString(String.Format("Opleiding Informatica"), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 20));
                graphics.DrawImage(image, 350, 0, 150, 50);

                //Body
                graphics.DrawString(String.Format("Leerwijzer - {0}", module.Name), headerFont, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 100));
                graphics.DrawString(String.Format("Osiris Code - {0}", module.OsirisCode), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 150));

                PdfTextElement textElement = new PdfTextElement(module.Description, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
                textElement.Draw(page, new RectangleF(0, 200, page.GetClientSize().Width, page.GetClientSize().Height));

                //Footer
                graphics.DrawString(String.Format("Verantwoordelijke docent: {0}", module.Teacher.FullName), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, page.GetClientSize().Height - 50));
                //Saving the PDF to the MemoryStream

                document.Save(ms);

                //Set the position as '0'.
                ms.Position = 0;

                return(File(ms.GetBuffer(), "application/pdf", String.Format("{0}_Leerwijzer_{0}_{1}.pdf", module.OsirisCode, module.Name, DateTime.Now)));
            }
        }
        public PdfLayoutResult AddText(string text, float x, float y, PdfFont font = null, PdfBrush brush = null, bool xIsRightOffset = false, float?forceTextSize = null)
        {
            font  = font ?? NormalFont;
            brush = brush ?? AccentBrush;

            if (xIsRightOffset)
            {
                SizeF textSize  = font.MeasureString(text);
                float textWidth = forceTextSize ?? textSize.Width;
                x = PageWidth - textWidth - x;
            }

            PdfTextElement  element = new PdfTextElement(text, font, brush);
            PdfLayoutResult result  = element.Draw(CurrentPage, new PointF(x, y));

            return(result);
        }
Exemplo n.º 18
0
        public static void createPDFfromList <T>(List <T> items, string title, string location)
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();
            //Add a page
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;
            //Set the standard font.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
            //Draw the text.
            PdfTextElement textElement = new PdfTextElement(title, font);

            textElement.Draw(graphics, new PointF(200, 0));

            //Create a PdfGrid
            PdfGrid pdfGrid = new PdfGrid();
            //Create table from list
            var       myType    = typeof(T);
            DataTable dataTable = new DataTable();

            foreach (PropertyInfo info in myType.GetProperties())
            {
                dataTable.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }
            foreach (var item in items)
            {
                DataRow dr = dataTable.NewRow();
                foreach (PropertyInfo info in myType.GetProperties())
                {
                    dr[info.Name] = info.GetValue(item);
                }
                dataTable.Rows.Add(dr);
            }
            //Assign data source
            pdfGrid.DataSource = dataTable;
            //Draw grid to the page of PDF document
            pdfGrid.Draw(page, new PointF(0, 50));

            //Save the document
            doc.Save(location);
            //Close the document
            doc.Close(true);
        }
Exemplo n.º 19
0
        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document.
            PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            //Add a page to the document.
            PdfPage page = document.Pages.Add();

            //Text to draw in PDF
            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.";

            //Set the formats for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment       = PdfTextAlignment.Justify;
            format.LineAlignment   = PdfVerticalAlignment.Top;
            format.ParagraphIndent = 35f;

            //Create a text element
            PdfTextElement element = new PdfTextElement(text);

            element.Brush        = PdfBrushes.Black;
            element.StringFormat = format;
            //Set the font
            Stream fontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.arial.ttf");

            element.Font = new PdfTrueTypeFont(fontStream, 14);

            //Set the properties to paginate the text.
            PdfLayoutFormat layoutFormat = new PdfLayoutFormat();

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

            RectangleF bounds = new RectangleF(PointF.Empty, page.Graphics.ClientSize);

            //Draw the text element with the properties and formats set.
            element.Draw(page, bounds, layoutFormat);
            //Save and close the document.
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "PDF_A1b.pdf");
        }
Exemplo n.º 20
0
        public static byte[] Print(Article a, string filename)
        {
            filename = Folder + filename;
            PdfDocument doc  = new PdfDocument();
            PdfPage     page = doc.Pages.Add();

            //create a new PDF string format
            PdfStringFormat drawFormat = new PdfStringFormat();

            drawFormat.WordWrap      = PdfWordWrapType.Word;
            drawFormat.Alignment     = PdfTextAlignment.Justify;
            drawFormat.LineAlignment = PdfVerticalAlignment.Top;

            //Set the font.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 40f);

            //Create a brush.
            PdfBrush brush = PdfBrushes.Red;

            //bounds
            RectangleF bounds = new RectangleF(new PointF(10, 10),
                                               new SizeF(page.Graphics.ClientSize.Width - 30,
                                                         page.Graphics.ClientSize.Height - 20));

            //Create a new text elememt
            PdfTextElement element = new PdfTextElement(a.Name, font, brush);

            //Set the string format
            element.StringFormat = drawFormat;

            //Draw the text element
            PdfLayoutResult result = element.Draw(page, bounds);

            FileStream s = new FileStream(filename, FileMode.OpenOrCreate);

            doc.Save(s);
            s.Flush();
            s.Close();
            s.Dispose();

            return(File.ReadAllBytes(filename));
        }
Exemplo n.º 21
0
        private PdfLayoutResult HeaderPoints(string text, float yPosition, PdfPage page)
        {
            float          headerBulletsXposition = 220;
            PdfTextElement txtElement             = new PdfTextElement("l");

            txtElement.Font                   = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 10);
            txtElement.Brush                  = new PdfSolidBrush(violet);
            txtElement.StringFormat           = new PdfStringFormat();
            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition, yPosition, 300, 100));
            txtElement                        = new PdfTextElement(text);
            txtElement.Font                   = new PdfStandardFont(PdfFontFamily.TimesRoman, 11);
            txtElement.Brush                  = new PdfSolidBrush(white);
            txtElement.StringFormat           = new PdfStringFormat();
            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            PdfLayoutResult result = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 20, yPosition, 320, 100));

            return(result);
        }
        private PdfLayoutResult BodyContent(string text, float yPosition)
        {
            float          headerBulletsXposition = 35;
            PdfTextElement txtElement             = new PdfTextElement("3");

            txtElement.Font                   = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 16);
            txtElement.Brush                  = new PdfSolidBrush(violet);
            txtElement.StringFormat           = new PdfStringFormat();
            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 320, 100));

            txtElement                        = new PdfTextElement(text);
            txtElement.Font                   = new PdfStandardFont(PdfFontFamily.TimesRoman, 17);
            txtElement.Brush                  = new PdfSolidBrush(white);
            txtElement.StringFormat           = new PdfStringFormat();
            txtElement.StringFormat.WordWrap  = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 25, yPosition, 450, 130));

            return(result);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            Stream   image1     = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.CustomTag.jpg");
            PdfColor blackColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 0));


            PdfFont fontnormal = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
            PdfFont fontTitle  = new PdfStandardFont(PdfFontFamily.TimesRoman, 22, PdfFontStyle.Bold);
            PdfFont fontHead   = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold);
            PdfFont fontHead2  = new PdfStandardFont(PdfFontFamily.TimesRoman, 16, PdfFontStyle.Bold);

            #region content string
            string pdfChapter = "We�ll begin with a conceptual overview of a simple PDF document. This chapter is designed to be a brief orientation before diving in and creating a real document from scratch \r\n \r\n A PDF file can be divided into four parts: a header, body, cross-reference table, and trailer. The header marks the file as a PDF, the body defines the visible document, the cross-reference table lists the location of everything in the file, and the trailer provides instructions for how to start reading the file.";
            string header     = "The header is simply a PDF version number and an arbitrary sequence of binary data.The binary data prevents na�ve applications from processing the PDF as a text file. This would result in a corrupted file, since a PDF typically consists of both plain text and binary data (e.g., a binary font file can be directly embedded in a PDF).";
            string body       = "The page tree serves as the root of the document. In the simplest case, it is just a list of the pages in the document. Each page is defined as an independent entity with metadata (e.g., page dimensions) and a reference to its resources and content, which are defined separately. Together, the page tree and page objects create the �paper� that composes the document.\r\n \r\n  Resources are objects that are required to render a page. For example, a single font is typically used across several pages, so storing the font information in an external resource is much more efficient. A content object defines the text and graphics that actually show up on the page. Together, content objects and resources define theappearance of an individual page. \r\n \r\n  Finally, the document�s catalog tells applications where to start reading the document. Often, this is just a pointer to the root page tree.";
            string resource   = "The third object is a resource defining a font configuration. \r\n \r\n The /Font key contains a whole dictionary, opposed to the name/value pairs we�ve seen previously (e.g., /Type /Page). The font we configured is called /F0, and the font face we selected is /Times-Roman. The /Subtype is the format of the font file, and /Type1 refers to the PostScript type 1 file format. The specification defines 14 �standard� fonts that all PDF applications should support.";
            string resource2  = "Any of these values can be used for the /BaseFont in a /Font dictionary. Nonstandard fonts can be embedded in a PDF document, but it is not easy to do manually. We will put off custom fonts until we can use iTextSharp�s high-level framework.";
            string crossRef   = "After the header and the body comes the cross-reference table. It records the byte location of each object in the body of the file. This enables random-access of the document, so when rendering a page, only the objects required for that page are read from the file. This makes PDFs much faster than their PostScript predecessors, which had to read in the entire file before processing it.";
            string trailer    = "Finally, we come to the last component of a PDF document. The trailer tells applications how to start reading the file. At minimum, it contains three things: \r\n 1. A reference to the catalog which links to the root of the document. \r\n 2. The location of the cross-reference table. \r\n 3. The size of the cross-reference table. \r\n \r\n Since a trailer is all you need to begin processing a document, PDFs are typically read back-to-front: first, the end of the file is found, and then you read backwards until you arrive at the beginning of the trailer. After that, you should have all the information you need to load any page in the PDF.";
            #endregion


            //Create a new PDF document.

            PdfDocument document = new PdfDocument();

            document.DocumentInformation.Title = "CustomTag";

            #region page1
            //Add a page to the document.

            PdfPage page1 = document.Pages.Add();

            //Load the image from the disk.

            PdfBitmap image = new PdfBitmap(image1);

            PdfStructureElement imageElement = new PdfStructureElement(PdfTagType.Figure);
            imageElement.AlternateText = "PDF Succintly image";
            //adding tag to the PDF image
            image.PdfTag = imageElement;
            //Draw the image
            page1.Graphics.DrawImage(image, 0, 0, page1.GetClientSize().Width, page1.GetClientSize().Height - 20);

            #endregion


            #region page2

            PdfPage page2 = document.Pages.Add();



            PdfStructureElement hTextElement1     = new PdfStructureElement(PdfTagType.Heading);
            PdfStructureElement headingFirstLevel = new PdfStructureElement(PdfTagType.HeadingLevel1);
            headingFirstLevel.Parent = hTextElement1;

            PdfTextElement headerElement1 = new PdfTextElement("Chapter 1 Conceptual Overview", fontTitle, PdfBrushes.Black);
            headerElement1.PdfTag = headingFirstLevel;
            headerElement1.Draw(page2, new PointF(100, 0));

            //Initialize the structure element with tag type paragraph.

            PdfStructureElement textElement1 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement1.Parent     = headingFirstLevel;
            textElement1.ActualText = pdfChapter;

            PdfTextElement element1 = new PdfTextElement(pdfChapter, fontnormal);
            element1.PdfTag = textElement1;
            element1.Brush  = new PdfSolidBrush(blackColor);
            element1.Draw(page2, new RectangleF(0, 40, page2.GetClientSize().Width, 70));


            PdfStructureElement hTextElement2 = new PdfStructureElement(PdfTagType.HeadingLevel2);
            hTextElement2.Parent     = hTextElement1;
            hTextElement2.ActualText = "Header";

            PdfTextElement headerElement2 = new PdfTextElement("Header", fontHead2, PdfBrushes.Black);
            headerElement2.PdfTag = hTextElement1;
            headerElement2.Draw(page2, new PointF(0, 140));

            PdfStructureElement textElement2 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement2.Parent     = hTextElement2;
            textElement2.ActualText = header;

            PdfTextElement element2 = new PdfTextElement(header, fontnormal);
            element2.PdfTag = textElement2;
            element2.Brush  = new PdfSolidBrush(blackColor);
            element2.Draw(page2, new RectangleF(0, 170, page2.GetClientSize().Width, 40));


            PdfStructureElement hTextElement3 = new PdfStructureElement(PdfTagType.HeadingLevel2);
            hTextElement3.Parent     = hTextElement1;
            hTextElement3.ActualText = "Body";

            PdfTextElement headerElement3 = new PdfTextElement("Body", fontHead2, PdfBrushes.Black);
            headerElement3.PdfTag = hTextElement1;
            headerElement3.Draw(page2, new PointF(0, 210));

            PdfStructureElement textElement3 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement3.Parent     = hTextElement3;
            textElement3.ActualText = body;

            PdfTextElement element3 = new PdfTextElement(body, fontnormal);
            element3.PdfTag = textElement3;
            element3.Brush  = new PdfSolidBrush(blackColor);
            element3.Draw(page2, new RectangleF(0, 240, page2.GetClientSize().Width, 120));

            PdfStructureElement hTextElement6 = new PdfStructureElement(PdfTagType.HeadingLevel2);
            hTextElement6.Parent     = hTextElement1;
            hTextElement6.ActualText = "Cross-Reference Table";

            PdfTextElement headerElement5 = new PdfTextElement("Cross-Reference Table", fontHead2, PdfBrushes.Black);
            headerElement5.PdfTag = hTextElement6;
            headerElement5.Draw(page2, new PointF(0, 380));

            PdfStructureElement textElement6 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement6.Parent     = hTextElement6;
            textElement6.ActualText = crossRef;

            PdfTextElement element6 = new PdfTextElement(crossRef, fontnormal);
            element6.PdfTag = textElement6;
            element6.Brush  = new PdfSolidBrush(blackColor);
            element6.Draw(page2, new RectangleF(0, 410, page2.GetClientSize().Width, 50));

            PdfStructureElement hTextElement7 = new PdfStructureElement(PdfTagType.HeadingLevel2);
            hTextElement7.Parent     = hTextElement1;
            hTextElement7.ActualText = "Trailer";

            PdfTextElement headerElement6 = new PdfTextElement("Trailer", fontHead2, PdfBrushes.Black);
            headerElement6.PdfTag = hTextElement7;
            headerElement6.Draw(page2, new PointF(0, 470));

            PdfStructureElement textElement7 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement7.Parent     = hTextElement7;
            textElement7.ActualText = trailer;

            PdfTextElement element7 = new PdfTextElement(trailer, fontnormal);
            element7.PdfTag = textElement7;
            element7.Brush  = new PdfSolidBrush(blackColor);
            element7.Draw(page2, new RectangleF(0, 500, page2.GetClientSize().Width, 110));



            #endregion

            #region page3

            PdfPage page3 = document.Pages.Add();

            PdfStructureElement hTextElement4 = new PdfStructureElement(PdfTagType.HeadingLevel2);
            hTextElement4.Parent     = hTextElement1;
            hTextElement4.ActualText = "Resource";

            PdfTextElement headerElement4 = new PdfTextElement("Resource", fontHead2, PdfBrushes.Black);
            headerElement4.PdfTag = hTextElement1;
            headerElement4.Draw(page3, new PointF(0, 0));

            PdfStructureElement textElement4 = new PdfStructureElement(PdfTagType.Paragraph);
            textElement4.Parent     = hTextElement4;
            textElement4.ActualText = resource;

            PdfTextElement element4 = new PdfTextElement(resource, fontnormal);
            element4.PdfTag = textElement4;
            element4.Brush  = new PdfSolidBrush(blackColor);
            element4.Draw(page3, new RectangleF(0, 40, page2.GetClientSize().Width, 70));

            //Create a new PdfGrid.
            PdfGrid pdfGrid = new PdfGrid();

            PdfStructureElement element = new PdfStructureElement(PdfTagType.Table);

            //Adding tag to PDF grid.
            pdfGrid.PdfTag = element;

            //Add three columns.
            pdfGrid.Columns.Add(3);

            PdfGridRow[] headerRow     = pdfGrid.Headers.Add(3);
            PdfGridRow   pdfGridHeader = pdfGrid.Headers[0];
            pdfGridHeader.PdfTag = new PdfStructureElement(PdfTagType.TableRow);

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();
            headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 13);
            pdfGridHeader.ApplyStyle(headerStyle);

            pdfGridHeader.Cells[0].Value  = "Times Roman Family";
            pdfGridHeader.Cells[0].PdfTag = new PdfStructureElement(PdfTagType.TableHeader);

            pdfGridHeader.Cells[1].Value  = "Helvetica Family";
            pdfGridHeader.Cells[1].PdfTag = new PdfStructureElement(PdfTagType.TableHeader);
            pdfGridHeader.Cells[2].Value  = "Courier Family";
            pdfGridHeader.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableHeader);


            PdfGridRow pdfGridRow1 = pdfGrid.Rows.Add();
            pdfGridRow1.PdfTag = new PdfStructureElement(PdfTagType.TableRow);

            pdfGridRow1.Cells[0].Value = "Times roman";

            pdfGridRow1.Cells[1].Value = "Helvetica";

            pdfGridRow1.Cells[2].Value = "Courier";

            pdfGridRow1.Cells[0].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow1.Cells[1].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow1.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);


            PdfGridRow pdfGridRow2 = pdfGrid.Rows.Add();
            pdfGridRow2.PdfTag = new PdfStructureElement(PdfTagType.TableRow);

            pdfGridRow2.Cells[0].Value = "Times-Bold";

            pdfGridRow2.Cells[1].Value = "Helvetica-Bold";

            pdfGridRow2.Cells[2].Value = "Courier-Bold";

            pdfGridRow2.Cells[0].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow2.Cells[1].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow2.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);

            PdfGridRow pdfGridRow3 = pdfGrid.Rows.Add();

            pdfGridRow3.PdfTag = new PdfStructureElement(PdfTagType.TableRow);

            pdfGridRow3.Cells[0].Value = "Times-Italic";

            pdfGridRow3.Cells[1].Value = "Helvetica-Oblique";

            pdfGridRow3.Cells[2].Value = "Courier-Oblique";

            pdfGridRow3.Cells[0].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow3.Cells[1].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow3.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);

            PdfGridRow pdfGridRow4 = pdfGrid.Rows.Add();

            pdfGridRow4.PdfTag = new PdfStructureElement(PdfTagType.TableRow);

            pdfGridRow4.Cells[0].Value = "Times-BoldItalic";

            pdfGridRow4.Cells[1].Value = "Helvetica-BoldOblique";

            pdfGridRow4.Cells[2].Value = "Courier-BoldOblique";

            pdfGridRow4.Cells[0].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow4.Cells[1].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);
            pdfGridRow4.Cells[2].PdfTag = new PdfStructureElement(PdfTagType.TableDataCell);



            pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout;
            pdfGrid.Draw(page3, new PointF(20, 130));

            page3.Graphics.DrawRectangle(PdfPens.Black, new RectangleF(20, 120, 490, 90));



            #endregion


            //Save the document and dispose it.
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "CustomtagSample.pdf");
        }
Exemplo n.º 24
0
        public IActionResult GeneratePDF()
        {
            //Creating new PDF document instance
            PdfDocument document = new PdfDocument();

            //Setting margin
            document.PageSettings.Margins.All = 0;
            //Adding a new page
            PdfPage     page = document.Pages.Add();
            PdfGraphics g    = page.Graphics;
            //Creating font instances
            PdfFont headerFont     = new PdfStandardFont(PdfFontFamily.TimesRoman, 35);
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);

            //Drawing content onto the PDF
            g.DrawRectangle(new PdfSolidBrush(gray), new Syncfusion.Drawing.RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
            g.DrawRectangle(new PdfSolidBrush(black), new Syncfusion.Drawing.RectangleF(0, 0, page.Graphics.ClientSize.Width, 130));
            g.DrawRectangle(new PdfSolidBrush(white), new Syncfusion.Drawing.RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450));
            g.DrawString("Enterprise", headerFont, new PdfSolidBrush(violet), new Syncfusion.Drawing.PointF(10, 20));
            g.DrawRectangle(new PdfSolidBrush(violet), new Syncfusion.Drawing.RectangleF(10, 63, 140, 35));
            g.DrawString("Reporting Solutions", subHeadingFont, new PdfSolidBrush(black), new Syncfusion.Drawing.PointF(15, 70));
            PdfLayoutResult result = HeaderPoints("Develop cloud-ready reporting applications in as little as 20% of the time.", 15, page);

            result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15, page);
            result = HeaderPoints("Microsoft Excel, Word, Adobe PDF, RDL display and editing.", result.Bounds.Bottom + 15, page);
            result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks", result.Bounds.Bottom + 15, page);
            result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45, page);
            result = BodyContent("Our architects and developers have years of reporting experience.", result.Bounds.Bottom + 25, page);
            result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25, page);
            result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25, page);
            result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25, page);
            PdfPen redPen = new PdfPen(PdfBrushes.Red, 2);

            g.DrawLine(redPen, new Syncfusion.Drawing.PointF(40, result.Bounds.Bottom + 92), new Syncfusion.Drawing.PointF(40, result.Bounds.Bottom + 145));
            float          headerBulletsXposition = 40;
            PdfTextElement txtElement             = new PdfTextElement("The Experts");

            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200));
            PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2);

            g.DrawLine(violetPen, new Syncfusion.Drawing.PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new Syncfusion.Drawing.PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145));
            txtElement      = new PdfTextElement("Accurate Estimates");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200));
            txtElement      = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));
            txtElement      = new PdfTextElement("Given our expertise, you can expect estimates to be accurate.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));
            PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2);

            g.DrawLine(greenPen, new Syncfusion.Drawing.PointF(40, result.Bounds.Bottom + 32), new Syncfusion.Drawing.PointF(40, result.Bounds.Bottom + 85));
            txtElement      = new PdfTextElement("Product Licensing");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200));
            PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2);

            g.DrawLine(bluePen, new Syncfusion.Drawing.PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new Syncfusion.Drawing.PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85));
            txtElement      = new PdfTextElement("About Syncfusion");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200));
            txtElement      = new PdfTextElement("Solution packages can be combined with product licensing for great cost savings.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));
            txtElement      = new PdfTextElement("Syncfusion has more than 7,000 customers including large financial institutions and Fortune 100 companies.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result          = txtElement.Draw(page, new Syncfusion.Drawing.RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));
            g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new Syncfusion.Drawing.PointF(10, g.ClientSize.Height - 30));
            PdfTextWebLink linkAnnot = new PdfTextWebLink();

            linkAnnot.Url   = "//www.syncfusion.com";
            linkAnnot.Text  = "www.syncfusion.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(page, new Syncfusion.Drawing.PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30));
            //Saving the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);
            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;
            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Sample.pdf";
            return(fileStreamResult);
        }
Exemplo n.º 25
0
        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            total = 0;
            string id = this.OrderIdList.SelectedValue.ToString();
            IEnumerable <CustOrders> products = Orders.GetProducts(id);

            List <CustOrders> list = new List <CustOrders>();

            foreach (CustOrders cust in products)
            {
                list.Add(cust);
            }
            var reducedList = list.Select(f => new { f.ProductID, f.ProductName, f.Quantity, f.UnitPrice, f.Discount, f.Price }).ToList();

            IEnumerable <ShipDetails> shipDetails = Orders.GetShipDetails();
            PdfDocument document = new PdfDocument();

            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 50;
            PdfPage        page    = document.Pages.Add();
            PdfGraphics    g       = page.Graphics;
            PdfTextElement element = new PdfTextElement("Northwind Traders\n67, rue des Cinquante Otages,\nElgin,\nUnites States.");

            element.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            PdfLayoutResult result    = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Stream          imgStream = typeof(Invoice).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.logo.jpg");

            PdfImage img = new PdfBitmap(imgStream);

            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);

            g.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));


            element       = new PdfTextElement("INVOICE " + id.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE " + DateTime.Now.ToString("MM/dd/yyyy");
            SizeF  textSize    = subHeadingFont.MeasureString(currentDate);

            g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));

            element       = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 10));
            element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(126, 151, 173), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            GetShipDetails(shipDetails);

            element       = new PdfTextElement(shipName, new PdfStandardFont(PdfFontFamily.TimesRoman, 10));
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));

            element       = new PdfTextElement(string.Format("{0}, {1}, {2}", address, shipCity, shipCountry), new PdfStandardFont(PdfFontFamily.TimesRoman, 10));
            element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();

            grid.DataSource = reducedList;


            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();

            headerStyle.Borders.All     = new PdfPen(new PdfColor(126, 151, 173));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
            headerStyle.TextBrush       = PdfBrushes.White;
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0 || i == 1)
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }
            header.ApplyStyle(headerStyle);
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f);
            cellStyle.TextBrush      = new PdfSolidBrush(new PdfColor(131, 130, 136));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 1)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else if (i == 0)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                    }

                    if (i > 2)
                    {
                        float val = float.MinValue;
                        float.TryParse(cell.Value.ToString(), out val);
                        cell.Value = '$' + val.ToString("0.00");
                    }
                }
            }

            grid.Columns[0].Width = 100;
            grid.Columns[1].Width = 200;

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;

            for (int i = 0; i < grid.Columns.Count - 1; i++)
            {
                pos += grid.Columns[i].Width;
            }

            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);

            GetTotalPrice(products);

            gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 20), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new PointF(pos - 55, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString('$' + string.Format("{0:N2}", total), font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 20), new SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));


            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "Invoice.pdf");
        }
Exemplo n.º 26
0
        private void ReportsView_Click(object sender, RoutedEventArgs e)
        {
            var viewBtn = (Button)sender;
            var period  = viewBtn.DataContext as PeriodModel;

            if (period == null)
            {
                return;
            }

            int periodId   = period.Id;
            var reportData = GetReportData(periodId);

            if (!reportData.Any())
            {
                MessageBox.Show("Unable to generate the report for the selected period: no data available!");
                return;
            }

            using (var doc = new PdfDocument())
            {
                PdfPage page = doc.Pages.Add();

                //Create PDF graphics for a page
                PdfGraphics graphics = page.Graphics;

                var bounds = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
                var header = new PdfPageTemplateElement(bounds);
                doc.Template.Top = header;

                PdfFont        subHeadingFont = new PdfTrueTypeFont(new Font("Microsoft Sans Serif", 14, System.Drawing.FontStyle.Bold), 14, true);
                PdfTextElement element        = new PdfTextElement($"ACCRUALS FOR {period.Name}", subHeadingFont);

                PdfLayoutResult result = element.Draw(page, new PointF(page.GetClientSize().Width / 2, bounds.Top + 8));
                graphics.DrawLine(new PdfPen(PdfBrushes.Black), new PointF(0, result.Bounds.Top + 20), new PointF(page.GetClientSize().Width, result.Bounds.Top + 20));

                //Set the standard font
                var font = new PdfTrueTypeFont(new Font("Microsoft Sans Serif", 11), true);
                var from = new PointF(0, result.Bounds.Top + 40);

                foreach (var reportEntry in reportData)
                {
                    House          house   = reportEntry.House;
                    PdfTextElement address = new PdfTextElement($"Address: {house.City} {house.Street} {house.HouseNumber} {house.CaseNumber}", font);
                    result = address.Draw(page, from);
                    from.Y = result.Bounds.Top + 20;
                    PdfLightTable pdfLightTable = new PdfLightTable();
                    pdfLightTable.Style.ShowHeader = true;

                    DataTable table = new DataTable();

                    table.Columns.Add("Owner");
                    table.Columns.Add("Flat Number");
                    table.Columns.Add("Living Space");
                    table.Columns.Add("Total (RUB)");

                    foreach (var flatEntry in reportEntry.Entries)
                    {
                        table.Rows.Add(new[]
                        {
                            flatEntry.Account.Owner,
                            flatEntry.Account.ApartmentNumber.ToString(),
                            flatEntry.Account.LivingSpace.ToString(),
                            flatEntry.Accruals.ToString()
                        });
                    }

                    pdfLightTable.DataSource = table;

                    result = pdfLightTable.Draw(page, from);
                    from.Y = result.Bounds.Bottom + 20;
                }
                //Draw the text

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

                string fileName = "Output.pdf";
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = fileName;
                process.Start();
                process.WaitForExit();
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            Stream   image1     = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.AutoTag.jpg");
            Stream   image2     = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.autotagSmall.jpg");
            PdfColor blackColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 0));


            #region content string
            string toc      = "\r\n What can I do with C#? ..................................................................................................................................... 3 \r\n \r\n What is .NET? .................................................................................................................................................... 3 \r\n \r\n Writing, Running, and Deploying a C# Program .............................................................................................. 3 \r\n \r\n Starting a New Program..................................................................................................................................... 3";
            string Csharp   = "Welcome to C# Succinctly. True to the Succinctly series concept, this book is very focused on a single topic: the C# programming language. I might briefly mention some technologies that you can write with C# or explain how a feature fits into those technologies, but the whole of this book is about helping you become familiar with C# syntax. \r\n \r\n In this chapter, Ill start with some introductory information and then jump straight into a simple C# program.";
            string whatToD0 = "C# is a general purpose, object-oriented, component-based programming language. As a general purpose language, you have a number of ways to apply C# to accomplish many different tasks. You can build web applications with ASP.NET, desktop applications with Windows Presentation Foundation (WPF), or build mobile applications for Windows Phone. Other applications include code that runs in the cloud via Windows Azure, and iOS, Android, and Windows Phone support with the Xamarin platform. There might be times when you need a different language, like C or C++, to communicate with hardware or real-time systems. However, from a general programming perspective, you can do a lot with C#.";
            string dotnet   = "The runtime is more formally named the Common Language Runtime (CLR). Programming languages that target the CLR compile to an Intermediate Language (IL). The CLR itself is a virtual machine that runs IL and provides many services such as memory management, garbage collection, exception management, security, and more.\r\n \r\n The Framework Class Library (FCL) is a set of reusable code that provides both general services and technology-specific platforms. The general services include essential types such as collections, cryptography, networking, and more. In addition to general classes, the FCL includes technology-specific platforms like ASP.NET, WPF, web services, and more. The value the FCL offers is to have common components available for reuse, saving time and money without needing to write that code yourself. \r\n \r\n There is a huge ecosystem of open-source and commercial software that relies on and supports .NET. If you visit CodePlex, GitHub, or any other open-source code repository site, you will see a multitude of projects written in C#. Commercial offerings include tools and services that help you build code, manage systems, and offer applications. Syncfusion is part of this ecosystem, offering reusable components for many of the .NET technologies I have mentioned.";
            string prog     = "The previous section described plenty of great things you can do with C#, but most of them are so detailed that they require their own book. To stay focused on the C# programming language, the code in this book will be for the console application. A console application runs on the command line, which you will learn about in this section. You can write your code with any editor, but this book uses Visual Studio.";

            #endregion

            //Create a new PDF document.

            PdfDocument document = new PdfDocument();

            //Auto Tag the document

            document.AutoTag = true;
            document.DocumentInformation.Title = "AutoTag";
            #region page1
            //Add a page to the document.

            PdfPage page1 = document.Pages.Add();

            //Load the image from the disk.

            PdfBitmap image = new PdfBitmap(image1);

            //Draw the image

            page1.Graphics.DrawImage(image, 0, 0, page1.GetClientSize().Width, page1.GetClientSize().Height - 20);

            #endregion

            #region page2
            PdfPage page2 = document.Pages.Add();

            PdfFont fontnormal = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
            PdfFont fontTitle  = new PdfStandardFont(PdfFontFamily.TimesRoman, 22, PdfFontStyle.Bold);
            PdfFont fontHead   = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold);
            PdfFont fontHead2  = new PdfStandardFont(PdfFontFamily.TimesRoman, 16, PdfFontStyle.Bold);

            page2.Graphics.DrawString("Table of Contents", fontTitle, PdfBrushes.Black, new PointF(300, 0));
            page2.Graphics.DrawLine(new PdfPen(PdfBrushes.Black, 0.5f), new PointF(0, 40), new PointF(page2.GetClientSize().Width, 40));

            page2.Graphics.DrawString("Chapter 1 Introducing C# and .NET .............................................................................................................. 3 \r\n ", fontHead, PdfBrushes.Black, new PointF(0, 60));
            page2.Graphics.DrawString(toc, fontnormal, PdfBrushes.Black, new PointF(0, 80));

            #endregion

            #region page3

            PdfPage page3 = document.Pages.Add();

            page3.Graphics.DrawString("C# Succinctly", new PdfStandardFont(PdfFontFamily.TimesRoman, 32, PdfFontStyle.Bold), PdfBrushes.Black, new PointF(160, 0));

            page3.Graphics.DrawLine(PdfPens.Black, new PointF(0, 40), new PointF(page3.GetClientSize().Width, 40));

            page3.Graphics.DrawString("Chapter 1 Introducing C# and .NET", fontTitle, PdfBrushes.Black, new PointF(160, 60));


            PdfTextElement element1 = new PdfTextElement(Csharp, fontnormal);
            element1.Brush = new PdfSolidBrush(blackColor);
            element1.Draw(page3, new RectangleF(0, 100, page3.GetClientSize().Width, 80));

            page3.Graphics.DrawString("What can I do with C#?", fontHead2, PdfBrushes.Black, new PointF(0, 180));
            PdfTextElement element2 = new PdfTextElement(whatToD0, fontnormal);
            element2.Brush = new PdfSolidBrush(blackColor);
            element2.Draw(page3, new RectangleF(0, 210, page3.GetClientSize().Width, 80));


            page3.Graphics.DrawString("What is .Net", fontHead2, PdfBrushes.Black, new PointF(0, 300));
            PdfTextElement element3 = new PdfTextElement(dotnet, fontnormal);
            element3.Brush = new PdfSolidBrush(blackColor);
            element3.Draw(page3, new RectangleF(0, 330, page3.GetClientSize().Width, 180));


            page3.Graphics.DrawString("Writing, Running, and Deploying a C# Program", fontHead2, PdfBrushes.Black, new PointF(0, 520));
            PdfTextElement element4 = new PdfTextElement(prog, fontnormal);
            element4.Brush = new PdfSolidBrush(blackColor);
            element4.Draw(page3, new RectangleF(0, 550, page3.GetClientSize().Width, 60));

            PdfBitmap img = new PdfBitmap(image2);
            page3.Graphics.DrawImage(img, new PointF(0, 630));
            page3.Graphics.DrawString("Note: The code samples in this book can be downloaded at", fontnormal, PdfBrushes.DarkBlue, new PointF(20, 630));
            page3.Graphics.DrawString("https://bitbucket.org/syncfusiontech/c-succinctly", fontnormal, PdfBrushes.Blue, new PointF(20, 640));
            SizeF      linkSize  = fontnormal.MeasureString("https://bitbucket.org/syncfusiontech/c-succinctly");
            RectangleF rectangle = new RectangleF(20, 640, linkSize.Width, linkSize.Height);

            //Creates a new Uri Annotation

            PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "https://bitbucket.org/syncfusiontech/c-succinctly");
            uriAnnotation.Color = new PdfColor(255, 255, 255);
            //Adds this annotation to a new page
            page3.Annotations.Add(uriAnnotation);

            #endregion



            //Save the document and dispose it.

            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "AutotagSample.pdf");
        }
Exemplo n.º 28
0
        private async void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            PdfDocument document = null;

            if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-1a")
            {
                // Create a new instance of PdfDocument class with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
            }
            else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-1b")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-2a")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2A);
            }
            else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-2b")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2B);
            }
            else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-2u")
            {
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2U);
            }
            else
            {
                if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-3a")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3A);
                }
                else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-3b")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
                }
                else if (this.PdfConformance.SelectionBoxItem.ToString() == "PDF/A-3u")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3U);
                }
                Stream imgStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Products.xml");

                PdfAttachment attachment = new PdfAttachment("Products.xml", imgStream);
                attachment.Relationship     = PdfAttachmentRelationship.Alternative;
                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "PDF_A";

                attachment.MimeType = "application/xml";

                document.Attachments.Add(attachment);
            }
            //Add a page to the document.
            PdfPage page = document.Pages.Add();

            //Create Pdf graphics for the page
            PdfGraphics g = page.Graphics;

            Stream jpegImage = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.AdventureCycle.jpg");

            //Drawing a jpeg image
            PdfImage image = new PdfBitmap(jpegImage);

            g.DrawImage(image, new RectangleF(150, 30, 200, 100));

            //Text to draw in PDF
            string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based," +
                          " is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, " +
                          "European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional" +
                          " sales teams are located throughout their market base";

            ////Set the formats for the text
            //PdfStringFormat format = new PdfStringFormat();
            //format.Alignment = PdfTextAlignment.Justify;
            //format.LineAlignment = PdfVerticalAlignment.Top;
            //format.ParagraphIndent = 35f;

            //Create a text element
            PdfTextElement element = new PdfTextElement(text);

            element.Brush = PdfBrushes.Black;
            // element.StringFormat = format;
            //Set the font
            Stream fontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.arial.ttf");

            element.Font = new PdfTrueTypeFont(fontStream, 14);

            //Set the properties to paginate the text.
            PdfLayoutFormat layoutFormat = new PdfLayoutFormat();

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

            RectangleF bounds = new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height);

            //Draw the text element with the properties and formats set.
            element.Draw(page, bounds, layoutFormat);
            //Save and close the document.
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "Sample.pdf");
        }
Exemplo n.º 29
0
        /// <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 doc = new PdfDocument();

            //Set compression level
            doc.Compression = PdfCompressionLevel.None;

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

            string basePath = _hostingEnvironment.WebRootPath;
            //Read the file
            FileStream file = new FileStream(ResolveApplicationPath("manual.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Read the text from the text file
            StreamReader reader = new StreamReader(file, System.Text.Encoding.ASCII);
            string       text   = reader.ReadToEnd();

            reader.Dispose();

            //Set the font
            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);

            //Set the formats for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment       = PdfTextAlignment.Justify;
            format.LineAlignment   = PdfVerticalAlignment.Top;
            format.ParagraphIndent = 15f;

            //Create a text element
            PdfTextElement element = new PdfTextElement(text, font);

            element.Brush        = new PdfSolidBrush(Color.Black);
            element.StringFormat = format;
            element.Font         = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

            //Set the properties to paginate the text.
            PdfLayoutFormat layoutFormat = new PdfLayoutFormat();

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

            RectangleF bounds = new RectangleF(PointF.Empty, page.Graphics.ClientSize);

            //Raise the events to draw the graphic elements for each page.
            element.BeginPageLayout += new BeginPageLayoutEventHandler(BeginPageLayout);
            element.EndPageLayout   += new EndPageLayoutEventHandler(EndPageLayout);

            //Draw the text element with the properties and formats set.
            PdfTextLayoutResult result = element.Draw(page, bounds, layoutFormat);

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            doc.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Close the PDF document.
            doc.Close(true);
            return(ms);
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;
            page = doc.Pages.Add();
            PdfGraphics g = page.Graphics;

            PdfFont headerFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 35);
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16);
            g.DrawRectangle(new PdfSolidBrush(gray), new RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));
            g.DrawRectangle(new PdfSolidBrush(black), new RectangleF(0, 0, page.Graphics.ClientSize.Width, 130));
            g.DrawRectangle(new PdfSolidBrush(white), new RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450));
            g.DrawString("Enterprise", headerFont, new PdfSolidBrush(violet), new PointF(10, 20));
            g.DrawRectangle(new PdfSolidBrush(violet), new RectangleF(10, 63, 140, 35));
            g.DrawString("Reporting Solutions", subHeadingFont, new PdfSolidBrush(black), new PointF(15, 70));

            PdfLayoutResult result = HeaderPoints("Develop cloud-ready reporting applications in as little as 20% of the time.", 15);
            result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Microsoft Excel, Word, Adobe PDF, RDL display and editing.", result.Bounds.Bottom + 15);
            result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks", result.Bounds.Bottom + 15);

            result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45);
            result = BodyContent("Our architects and developers have years of reporting experience.", result.Bounds.Bottom + 25);
            result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25);
            result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25);
            result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25);

            PdfPen redPen = new PdfPen(PdfBrushes.Red, 2);
            g.DrawLine(redPen, new PointF(40, result.Bounds.Bottom + 92), new PointF(40, result.Bounds.Bottom + 145));
            float headerBulletsXposition = 40;
            PdfTextElement txtElement = new PdfTextElement("The Experts");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200));

            PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2);
            g.DrawLine(violetPen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145));
            txtElement = new PdfTextElement("Accurate Estimates");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200));

            txtElement = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement = new PdfTextElement("Given our expertise, you can expect estimates to be accurate.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));


            PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2);
            g.DrawLine(greenPen, new PointF(40, result.Bounds.Bottom + 32), new PointF(40, result.Bounds.Bottom + 85));

            txtElement = new PdfTextElement("Product Licensing");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200));

            PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2);
            g.DrawLine(bluePen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85));
            txtElement = new PdfTextElement("About Syncfusion");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200));

            txtElement = new PdfTextElement("Solution packages can be combined with product licensing for great cost savings.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200));


            txtElement = new PdfTextElement("Syncfusion has more than 7,000 customers including large financial institutions and Fortune 100 companies.");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular);
            result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200));

            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Reporting-Edition.jpg");

            g.DrawImage(PdfImage.FromStream(imgStream), 280, 600, 300, 170);

            g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new PointF(10, g.ClientSize.Height - 30));
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url = "http://www.syncfusion.com";
            linkAnnot.Text = "www.syncfusion.com";
            linkAnnot.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(page, new PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30));
            MemoryStream stream = new MemoryStream();
            doc.Save(stream);
            doc.Close(true);

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("GettingStarted.pdf", "application/pdf", stream);
            else
                Xamarin.Forms.DependencyService.Get<ISave>().Save("GettingStarted.pdf", "application/pdf", stream);
        }
        public ActionResult Conformance(string InsideBrowser, string conformance)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            PdfDocument document = null;

            if (conformance == "PDF/A-1a")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
            }
            else if (conformance == "PDF/A-1b")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else if (conformance == "PDF/A-2a")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2A);
            }
            else if (conformance == "PDF/A-2b")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2B);
            }
            else if (conformance == "PDF/A-2u")
            {
                //Create a new document with PDF/A standard.
                document = new PdfDocument(PdfConformanceLevel.Pdf_A2U);
            }
            else
            {
                if (conformance == "PDF/A-3a")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3A);
                }
                else if (conformance == "PDF/A-3b")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3B);
                }
                else if (conformance == "PDF/A-3u")
                {
                    document = new PdfDocument(PdfConformanceLevel.Pdf_A3U);
                }
                //Read the file
                FileStream file = new FileStream(dataPath + "Text1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment("Text1.txt", file);

                attachment.Relationship     = PdfAttachmentRelationship.Alternative;
                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "PDF_A";

                attachment.MimeType = "application/xml";

                document.Attachments.Add(attachment);
            }


            //Add a page to the document.
            PdfPage page = document.Pages.Add();
            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;

            FileStream imageStream = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //Load the image from the disk.
            PdfImage img = PdfImage.FromStream(imageStream);

            //Draw the image in the specified location and size.
            graphics.DrawImage(img, new RectangleF(150, 30, 200, 100));


            //Create font
            FileStream fontFileStream = new FileStream(dataPath + "arial.ttf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfFont    font           = new PdfTrueTypeFont(fontFileStream, 14);


            PdfTextElement textElement = new PdfTextElement("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based," +
                                                            " is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, " +
                                                            "European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional" +
                                                            " sales teams are located throughout their market base.")
            {
                Font = font
            };
            PdfLayoutResult layoutResult = textElement.Draw(page, new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height));

            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            document.Close();
            stream.Position = 0;
            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "PDF_A.pdf";
            return(fileStreamResult);
        }
Exemplo n.º 32
0
        void PDFButton_Clicked(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            document.PageSettings.Margins.All = 50;
            PdfPage page = document.Pages.Add();
            PdfGraphics g = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");
            element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg");
            PdfImage img = PdfImage.FromStream(imgStream);
            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 15);
            g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));
            element = new PdfTextElement("INVOICE: " + billInfo.InvoiceNumber.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE: " + billInfo.Date.ToString();
            SizeF textSize = subHeadingFont.MeasureString(currentDate);
            g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));

            element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));

            element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();
            grid.DataSource = this.ListSource;
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();
            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();
            headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            headerStyle.TextBrush = PdfBrushes.White;
            headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                else
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            }
            header.Cells[0].Value = "ITEM";
            header.Cells[1].Value = "QUANTITY";
            header.Cells[2].Value = "RATE";
            header.Cells[3].Value = "TAXES (%)";
            header.Cells[4].Value = "AMOUNT";
            header.ApplyStyle(headerStyle);
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f);
            cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);
            cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    else
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

                    if (i > 1 && i != 3)
                    {
                        //float val = float.MinValue;
                        //float.TryParse(cell.Value.ToString(), out val);
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            cell.Value = "$" + cell.Value.ToString();
                        }
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;
            for (int i = 0; i < grid.Columns.Count - 1; i++)
                pos += grid.Columns[i].Width;

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14f,PdfFontStyle.Bold);

            gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 14), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos -210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + GetNetAmount().ToString(), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 10), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));

            MemoryStream data = new MemoryStream();

            document.Save(data);

            document.Close();

            DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data);

        }
Exemplo n.º 33
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        public void CreatePDF(IList <InvoiceItem> dataSource, BillingInformation billInfo, double totalDue)
        {
            PdfDocument document = new PdfDocument();

            document.PageSettings.Orientation = PdfPageOrientation.Portrait;
            document.PageSettings.Margins.All = 50;
            PdfPage        page    = document.Pages.Add();
            PdfGraphics    g       = page.Graphics;
            PdfTextElement element = new PdfTextElement(@"Syncfusion Software 
2501 Aerial Center Parkway 
Suite 200 Morrisville, NC 27560 USA 
Tel +1 888.936.8638 Fax +1 919.573.0306");

            element.Font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfLayoutResult result    = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
            Assembly        assembly  = typeof(MainPage).Assembly;
            Stream          imgStream = assembly.GetManifestResourceStream("Invoice.Assets.SyncfusionLogo.jpg");
            PdfImage        img       = PdfImage.FromStream(imgStream);

            page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45));
            PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);

            g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));
            element       = new PdfTextElement("INVOICE " + billInfo.InvoiceNumber.ToString(), subHeadingFont);
            element.Brush = PdfBrushes.White;
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48));
            string currentDate = "DATE " + billInfo.Date.ToString("d");
            SizeF  textSize    = subHeadingFont.MeasureString(currentDate);

            g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));

            element       = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 12));
            element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            result        = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25));

            g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));

            element       = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 11));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));

            element       = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 11));
            element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
            result        = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100));

            PdfGrid grid = new PdfGrid();

            grid.DataSource = ConvertToDataTable(dataSource);
            PdfGridCellStyle cellStyle = new PdfGridCellStyle();

            cellStyle.Borders.All = PdfPens.White;
            PdfGridRow header = grid.Headers[0];

            PdfGridCellStyle headerStyle = new PdfGridCellStyle();

            headerStyle.Borders.All     = new PdfPen(new PdfColor(34, 83, 142));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142));
            headerStyle.TextBrush       = PdfBrushes.White;
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular);

            for (int i = 0; i < header.Cells.Count; i++)
            {
                if (i == 0)
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }
            header.Cells[0].Value = "ITEM";
            header.Cells[1].Value = "QUANTITY";
            header.Cells[2].Value = "RATE";
            header.Cells[3].Value = "TAXES";
            header.Cells[4].Value = "AMOUNT";
            header.ApplyStyle(headerStyle);
            grid.Columns[0].Width    = 180;
            cellStyle.Borders.Bottom = new PdfPen(new PdfColor(34, 83, 142), 0.70f);
            cellStyle.Font           = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f);
            cellStyle.TextBrush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            foreach (PdfGridRow row in grid.Rows)
            {
                row.ApplyStyle(cellStyle);
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    PdfGridCell cell = row.Cells[i];
                    if (i == 0)
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                    }

                    if (i > 1)
                    {
                        if (cell.Value.ToString().Contains("$"))
                        {
                            cell.Value = cell.Value.ToString();
                        }
                        else
                        {
                            if (cell.Value is double)
                            {
                                cell.Value = "$" + ((double)cell.Value).ToString("#,###.00", CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                cell.Value = "$" + cell.Value.ToString();
                            }
                        }
                    }
                }
            }

            PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

            layoutFormat.Layout = PdfLayoutType.Paginate;

            PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat);
            float pos = 0.0f;

            for (int i = 0; i < grid.Columns.Count - 1; i++)
            {
                pos += grid.Columns[i].Width;
            }

            PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Bold);

            gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right));
            gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos - 210, gridResult.Bounds.Bottom + 60));
            pos += grid.Columns[4].Width;
            gridResult.Page.Graphics.DrawString("$" + totalDue.ToString("#,###.00", CultureInfo.InvariantCulture), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(pos, gridResult.Bounds.Bottom + 10, grid.Columns[4].Width - pos, 20), new PdfStringFormat(PdfTextAlignment.Right));

            document.Save("Invoice.pdf");
            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                System.Diagnostics.Process.Start("Invoice.pdf");
                //this.Close();
            }
            //else
            // Exit
            //this.Close();

            document.Close(true);
        }
        private PdfLayoutResult HeaderPoints(string text, float yPosition)
        {
            float headerBulletsXposition = 220;
            PdfTextElement txtElement = new PdfTextElement("l");
            txtElement.Font = new PdfStandardFont(PdfFontFamily.ZapfDingbats, 10);
            txtElement.Brush = new PdfSolidBrush(violet);
            txtElement.StringFormat = new PdfStringFormat();
            txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            txtElement.Draw(page, new RectangleF(headerBulletsXposition, yPosition, 300, 100));

            txtElement = new PdfTextElement(text);
            txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11);
            txtElement.Brush = new PdfSolidBrush(white);
            txtElement.StringFormat = new PdfStringFormat();
            txtElement.StringFormat.WordWrap = PdfWordWrapType.Word;
            txtElement.StringFormat.LineLimit = true;
            PdfLayoutResult result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 20, yPosition, 320, 100));
            return result;
        }