예제 #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);
          

        }
예제 #2
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));
        }
        public ActionResult Create(FullcalendarModel fullcalendarModel)
        {
            if (ModelState.IsValid)
            {
                // create a new pdf document
                PdfDocument doc = new PdfDocument();

                // add a new page to the document
                PdfPage page = doc.AddPage();

                // create a new pdf font
                PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
                font.Size = 15;

                // create a new text element and add it to the page
                PdfTextElement text = new PdfTextElement(50, 50, fullcalendarModel.title.ToString() + "\n" + fullcalendarModel.address.ToString() + "\n" + fullcalendarModel.description.ToString() + "\n" + fullcalendarModel.date.ToString() + "\n" + "Signature:_________________________________" + "\n" + "Total:______________________" + "\n" + "Tax:______________________" + "\n" + "Subtotal:______________________", font);
                page.Add(text);
                doc.Save("C:/Users/Charles/Documents/Visual Studio 2015/Projects/CiezkiCapStone/CCiezkiCapstone/CCiezkiCapstone/Invoices/" + fullcalendarModel.title.ToString() + ".pdf");
                // save pdf document
                //doc.Save("~/Sample.pdf");

                // close pdf document
                doc.Close();

                db.FullcalendarModel.Add(fullcalendarModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fullcalendarModel));
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
        private float DrawBuyer(InvoicePdfModel model, PdfPage page, float x, float y)
        {
            PdfLayoutResult layoutResult;

            layoutResult = new PdfTextElement("nabywca:", fontNormalItalicUnderline, brushBlack).Draw(page, new PointF(x, y));

            y            = layoutResult.Bounds.Bottom;
            layoutResult = new PdfTextElement(model.Customer.Name, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            y            = layoutResult.Bounds.Bottom;
            layoutResult = new PdfTextElement(model.Customer.StreetNumber, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            y            = layoutResult.Bounds.Bottom;
            x            = page.Size.Width / 2;
            layoutResult = new PdfTextElement(model.Customer.ZipCode, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));
            x           += layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement(model.Customer.City, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            y            = layoutResult.Bounds.Bottom;
            x            = page.Size.Width / 2;
            layoutResult = new PdfTextElement("NIP: ", fontNormalItalic, brushBlack).Draw(page, new PointF(x, y));
            x           += layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement(model.Customer.Nip, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            return(layoutResult.Bounds.Bottom);
        }
예제 #7
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);
                }
            }
        }
예제 #8
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));
        }
예제 #9
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);
            }
        }
예제 #10
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));
        }
예제 #12
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);
                }
            }
        }
예제 #13
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());
        }
예제 #14
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");
            }
        }
예제 #15
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));
        }
예제 #16
0
        public byte[] ProForma(InvoicePdfModel model)
        {
            PdfLayoutResult layoutResult;
            string          data;
            float           y        = 30;
            float           x        = 0;
            var             document = new PdfDocument();

            document.PageSettings.Margins.All = marginSize;

            var page = document.Pages.Add();

            data         = $"Faktura PRO FORMA nr {model.Number}";
            layoutResult = new PdfTextElement(data, fontBig, brushBlack).Draw(page, new PointF(x, y));

            data         = $"Data wystawienia: {model.ExposureDate.ToString("yyyy-MM-dd")}";
            y            = layoutResult.Bounds.Bottom;
            x            = page.Size.Width - fontNormal.MeasureString(data).Width - marginSize * 2 - 4;
            layoutResult = new PdfTextElement("data wystawienia:", fontNormalItalic, brushBlack).Draw(page, new PointF(x, y));
            x           += layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement(model.ExposureDate.ToString("yyyy-MM-dd"), fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            data         = $"Miejsce wystawienia: {model.InvoiceConfig.ExposurePlace}";
            y            = layoutResult.Bounds.Bottom;
            x            = page.Size.Width - fontNormal.MeasureString(data).Width - marginSize * 2 - 4;
            layoutResult = new PdfTextElement("miejsce wystawienia:", fontNormalItalic, brushBlack).Draw(page, new PointF(x, y));
            x           += layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement(model.InvoiceConfig.ExposurePlace, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            float section = layoutResult.Bounds.Bottom + 32;

            DrawBuyer(model, page, page.Size.Width / 2, section);

            section = DrawSeller(model, page, 0, section);

            section = section + 48;

            section = DrawProducts(model, page, section);

            section = section + 48;

            section = DrawFooter(model, page, 0, section);

            using (var memoryStream = new MemoryStream())
            {
                document.Save(memoryStream);
                return(memoryStream.ToArray());
            }
        }
예제 #17
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);
        }
예제 #18
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)));
 }
        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)));
            }
        }
예제 #20
0
        private float DrawFooter(InvoicePdfModel model, PdfPage page, float x, float y)
        {
            PdfLayoutResult layoutResult;

            layoutResult = new PdfTextElement("do zapłaty: ", fontNormalItalic, brushBlack).Draw(page, new PointF(x, y));
            x            = layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement($"{model.GrossAmount.ToString("#,##0.00")} zł", fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            y            = layoutResult.Bounds.Bottom;
            x            = 0;
            layoutResult = new PdfTextElement("słownie: ", fontNormalItalic, brushBlack).Draw(page, new PointF(x, y));
            x            = layoutResult.Bounds.Width + 4;
            layoutResult = new PdfTextElement(model.GrossAmountStringified, fontNormalBold, brushBlack).Draw(page, new PointF(x, y));

            return(layoutResult.Bounds.Bottom);
        }
예제 #21
0
        private void PageNumbering(int pageIndex)
        {
            FontFamily fontFamily = new FontFamily("Arial");
            Font       font       = new Font(
                fontFamily,
                8,
                FontStyle.Regular,
                GraphicsUnit.Pixel);

            Doc.Footer            = Doc.AddTemplate(Doc.Pages[pageIndex].ClientRectangle.Width, 100);
            Doc.Footer.Foreground = false;
            PdfElement textFooter = new PdfTextElement(converter.Options.MarginLeft, 80, "Página: {page_number} de {total_pages}", Doc.AddFont(font));

            textFooter.ForeColor = System.Drawing.Color.Black;
            Doc.Footer.Add(textFooter);
        }
        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);
        }
예제 #23
0
        public MemoryStream CreatePdf(WeatherForecast[] forecasts)
        {
            if (forecasts == null)
            {
                throw new ArgumentNullException("Data cannot be null");
            }

            using PdfDocument pdfDocument = new PdfDocument();

            int paragraphAfterSpacing = 8;
            int cellMargin            = 8;

            PdfPage page = pdfDocument.Pages.Add();

            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);

            PdfTextElement title = new PdfTextElement("Weather Forecast", font, PdfBrush);
        }
예제 #24
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);
        }
예제 #25
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");
        }
예제 #26
0
        private void CreateChart(PdfPage page, PdfLayoutResult result, PdfTextElement element, RapportVragenlijstVM answerlist)
        {
            List <RapportVragenlijstStap> chartList = new List <RapportVragenlijstStap>();

            foreach (var x in answerlist.Stappen)
            {
                if (x.TypeNaam.Equals("Getal"))
                {
                    chartList.Add(x);
                }
            }

            CartesianChart Chart = new CartesianChart
            {
                DisableAnimations = true,
                Width             = 600,
                Height            = 400,
                Series            = new SeriesCollection
                {
                    new ColumnSeries
                    {
                        Values = new ChartValues <double> {
                            4, 3, 2, 5, 10
                        }
                    }
                }
            };

            Chart.AxisY.Add(new Axis
            {
                MinValue  = 0,
                MaxValue  = 10,
                Separator = new LiveCharts.Wpf.Separator
                {
                    Step      = 1,
                    IsEnabled = true
                }
            });

            string path = "chart.png";

            Chart.Update(true, true);
            SaveToPng(Chart, path);
        }
예제 #27
0
        private PdfDocument CreatePdfWithImageFile(string fullName, string name)
        {
            PdfDocument doc  = new PdfDocument();
            PdfPage     page = doc.AddPage();
            PdfFont     font = doc.AddFont(PdfStandardFont.Helvetica);

            font.Size = 12;

            PdfRenderingResult result;

            PdfTextElement text = new PdfTextElement(0, 0, name, font);

            result = page.Add(text);
            PdfImageElement img = new PdfImageElement(0, result.PdfPageLastRectangle.Bottom + 50, fullName);

            result = page.Add(img);

            return(doc);
        }
        public ActionResult SubmitAction(FormCollection collection)
        {
            // the test file
            string filePdf = Server.MapPath("~/files/selectpdf.pdf");
            string imgFile = Server.MapPath("~/files/logo.png");
            // resize the content
            PdfResizeManager resizer = new PdfResizeManager();

            resizer.Load(filePdf);
            // add extra top and bottom margins
            resizer.PageMargins = new PdfMargins(0, 0, 90, 40);
            // add the header and footer to the existing (now resized pdf document)
            PdfDocument doc = resizer.GetDocument();
            // header template (90 points in height) with image element
            PdfTemplate     header = doc.AddTemplate(doc.Pages[0].ClientRectangle.Width, 90);
            PdfImageElement img1   = new PdfImageElement(10, 10, imgFile);

            header.Add(img1);
            // footer template (40 points in height) with text element
            PdfTemplate footer = doc.AddTemplate(new RectangleF(0,
                                                                doc.Pages[0].ClientRectangle.Height - 40,
                                                                doc.Pages[0].ClientRectangle.Width, 40));
            // create a new pdf font
            PdfFont font2 = doc.AddFont(PdfStandardFont.Helvetica);

            font2.Size = 12;
            PdfTextElement text1 = new PdfTextElement(10, 10,
                                                      "Generated by SelectPdf. Page number {page_number} of {total_pages}.",
                                                      font2);

            text1.ForeColor = System.Drawing.Color.Blue;
            footer.Add(text1);
            // save pdf document
            byte[] pdf = doc.Save();
            // close pdf document
            resizer.Close();
            // return resulted pdf document
            FileResult fileResult = new FileContentResult(pdf, "application/pdf");

            fileResult.FileDownloadName = "Document.pdf";
            return(fileResult);
        }
예제 #29
0
        private float DrawRates(InvoicePdfModel model, PdfPage page, float y)
        {
            PdfLayoutResult layoutResult;

            layoutResult = new PdfTextElement("ogółem stawkami:", fontSmallItalic, brushBlack).Draw(page, new PointF(0, y));
            y            = layoutResult.Bounds.Bottom + 4;

            float xCol1 = 2;
            float xCol2 = xCol1 + 60;
            float xCol3 = xCol2 + 60;
            float xCol4 = xCol3 + 60;
            float xCol5 = xCol4 + 80;

            float padding = 2;
            float height  = 0;

            layoutResult = new PdfTextElement("Stawka VAT", fontSmallItalic, brushBlack).Draw(page, new PointF(xCol1, y));
            height       = layoutResult.Bounds.Height + padding * 2;
            page.Graphics.DrawRectangle(penGray, xCol1 - padding, y - padding, xCol2 - xCol1, height);
            layoutResult = new PdfTextElement("Wartość netto", fontSmallItalic, brushBlack).Draw(page, new PointF(xCol2, y));
            page.Graphics.DrawRectangle(penGray, xCol2 - padding, y - padding, xCol3 - xCol2, height);
            layoutResult = new PdfTextElement("Kwota VAT", fontSmallItalic, brushBlack).Draw(page, new PointF(xCol3, y));
            page.Graphics.DrawRectangle(penGray, xCol3 - padding, y - padding, xCol4 - xCol3, height);
            layoutResult = new PdfTextElement("Wartość brutto", fontSmallItalic, brushBlack).Draw(page, new PointF(xCol4, y));
            page.Graphics.DrawRectangle(penGray, xCol4 - padding, y - padding, xCol5 - xCol4, height);
            y = layoutResult.Bounds.Bottom + padding * 2;

            foreach (var tax in model.Rates)
            {
                layoutResult = new PdfTextElement(tax.VatRateCaption, fontSmallBold, brushBlack).Draw(page, new PointF(xCol1, y));
                height       = layoutResult.Bounds.Height + padding * 2;
                page.Graphics.DrawRectangle(penGray, xCol1 - padding, y - padding, xCol2 - xCol1, height);
                layoutResult = new PdfTextElement($"{tax.NetAmount.ToString("#,##0.00")} zł", fontSmallBold, brushBlack).Draw(page, new PointF(xCol2, y));
                page.Graphics.DrawRectangle(penGray, xCol2 - padding, y - padding, xCol3 - xCol2, height);
                layoutResult = new PdfTextElement($"{tax.VatAmount.ToString("#,##0.00")} zł", fontSmallBold, brushBlack).Draw(page, new PointF(xCol3, y));
                page.Graphics.DrawRectangle(penGray, xCol3 - padding, y - padding, xCol4 - xCol3, height);
                layoutResult = new PdfTextElement($"{tax.GrossAmount.ToString("#,##0.00")} zł", fontSmallBold, brushBlack).Draw(page, new PointF(xCol4, y));
                page.Graphics.DrawRectangle(penGray, xCol4 - padding, y - padding, xCol5 - xCol4, height);
                y = layoutResult.Bounds.Bottom;
            }
            return(layoutResult.Bounds.Bottom);
        }
예제 #30
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));
        }
예제 #31
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);
        }
예제 #32
0
        public ActionResult Pay(OrderViewModel order)
        {
            // create a new pdf document
            PdfDocument doc = new PdfDocument();

            // add a new page to the document
            PdfPage page = doc.AddPage();

            // create a new pdf font
            PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
            font.Size = 20;

            // create a new text element and add it to the page
            PdfTextElement text = new PdfTextElement(50, 50, "Date: " + order.OrderDate.ToString(), font);
            page.Add(text);
            page.Add(new PdfTextElement(50, 100, "CustomerId:" + order.CustomerId.ToString(), font));

            // save pdf document
            var bytes = doc.Save();

            // close pdf document
            doc.Close();
            return new FileContentResult(bytes, "application/pdf");
        }
        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);
        }
예제 #34
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);

        }
        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;
        }