private void DrawPath(PdfPageBase page)
        {
            PointF[] points = new PointF[5];
            for (int i = 0; i < points.Length; i++)
            {
                float x = (float)Math.Cos(i * 2 * Math.PI / 5);
                float y = (float)Math.Sin(i * 2 * Math.PI / 5);
                points[i] = new PointF(x, y);
            }
            PdfPath path = new PdfPath();
            path.AddLine(points[2], points[0]);
            path.AddLine(points[0], points[3]);
            path.AddLine(points[3], points[1]);
            path.AddLine(points[1], points[4]);
            path.AddLine(points[4], points[2]);

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();
            PdfPen pen = new PdfPen(Color.DeepSkyBlue, 0.02f);
            PdfBrush brush1 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.ScaleTransform(50f, 50f);
            page.Canvas.TranslateTransform(5f, 1.2f);
            page.Canvas.DrawPath(pen, path);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Alternate;
            page.Canvas.DrawPath(pen, brush1, path);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush1, path);

            PdfLinearGradientBrush brush2 = new PdfLinearGradientBrush(new PointF(-2, 0), new PointF(2, 0), Color.Red, Color.Blue);
            page.Canvas.TranslateTransform(-4f, 2f);
            path.FillMode = PdfFillMode.Alternate;
            page.Canvas.DrawPath(pen, brush2, path);

            PdfRadialGradientBrush brush3 = new PdfRadialGradientBrush(new PointF(0f, 0f), 0f, new PointF(0f, 0f), 1f, Color.Red, Color.Blue);
            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush3, path);

            PdfTilingBrush brush4 = new PdfTilingBrush(new RectangleF(0, 0, 4f, 4f));
            brush4.Graphics.DrawRectangle(brush2, 0, 0, 4f, 4f);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush4, path);

            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

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

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

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

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

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

            //Launching the Pdf file.
            PDFDocumentViewer("Transparency.pdf");
        }
예제 #3
0
        private void AlignText(PdfPageBase page)
        {
            //Draw the text - alignment
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Left!", font, brush, 0, 20, leftAlignment);
            page.Canvas.DrawString("Left!", font, brush, 0, 50, leftAlignment);

            PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 30, rightAlignment);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 60, rightAlignment);

            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, page.Canvas.ClientSize.Width / 2, 40, centerAlignment);

        }
예제 #4
0
        private void TransformText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.Blue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.TranslateTransform(page.Canvas.ClientSize.Width / 2, 20);
            page.Canvas.DrawString("Sales Report Chart", font, brush1, 0, 0, format);

            page.Canvas.ScaleTransform(1f, -0.8f);
            page.Canvas.DrawString("Sales Report Chart", font, brush2, 0, -2 * 18 * 1.2f, format);
            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #5
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            #region Field Definitions
            //Load product data.
            IEnumerable <Products> products = DataProvider.GetProducts();

            //Create a new PDF standard font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
            smallFont = new PdfStandardFont(font, 5f);
            PdfFont bigFont = new PdfStandardFont(font, 16f);

            //Create a new PDF solid brush
            PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29));
            PdfBrush grayBrush   = new PdfSolidBrush(new PdfColor(170, 171, 171));

            //Create a new PDF pen
            borderPen              = new PdfPen(PdfBrushes.DarkGray, .3f);
            borderPen.LineCap      = PdfLineCap.Square;
            transparentPen         = new PdfPen(PdfBrushes.Transparent, .3f);
            transparentPen.LineCap = PdfLineCap.Square;
            # endregion
예제 #6
0
        private void DrawText(PdfPageBase page)
        {
            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw text - brush
            String          text   = "Go! Turn Around! Go! Go! Go!";
            PdfPen          pen    = PdfPens.DeepSkyBlue;
            PdfSolidBrush   brush  = new PdfSolidBrush(Color.White);
            PdfStringFormat format = new PdfStringFormat();
            PdfFont         font   = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic);
            SizeF           size   = font.MeasureString(text, format);
            RectangleF      rctg
                = new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180,
                                 size.Width / 3 * 2, size.Height * 2);

            page.Canvas.DrawString(text, font, pen, brush, rctg, format);

            //Restore graphics
            page.Canvas.Restore(state);
        }
        protected void GanttConditionalExporting_ServerPdfQueryCell(object model, object args)
        {
            var record     = (GanttRecord)((Dictionary <string, object>)args)["Data"];
            var cell       = (PdfTreeGridCell)((Dictionary <string, object>)args)["Cell"];
            var column     = (GanttColumn)((Dictionary <string, object>)args)["Column"];
            var ganttModel = (GanttProperties)model;

            if (column.MappingName == ganttModel.ProgressMapping && !record.IsParentRow)
            {
                if (record.Progress > 80)
                {
                    PdfBrush color = new PdfSolidBrush(new PdfColor(165, 105, 189));
                    cell.Style.BackgroundBrush = color;
                }
                else if (record.Progress < 20)
                {
                    PdfBrush color = new PdfSolidBrush(new PdfColor(240, 128, 128));
                    cell.Style.BackgroundBrush = color;
                }
            }
        }
        public ActionResult TableFeatures(string InsideBrowser)
        {
            #region Field Definitions
            //Load product data.
            IEnumerable <Products> products = DataProvider.GetProducts(_hostingEnvironment.WebRootPath);

            //Create a new PDF standard font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
            smallFont = new PdfStandardFont(font, 5f);
            PdfFont bigFont = new PdfStandardFont(font, 16f);

            //Create a new PDF solid brush
            PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29));
            PdfBrush grayBrush   = new PdfSolidBrush(new PdfColor(170, 171, 171));

            //Create a new PDF pen
            borderPen              = new PdfPen(PdfBrushes.DarkGray, .3f);
            borderPen.LineCap      = PdfLineCap.Square;
            transparentPen         = new PdfPen(PdfBrushes.Transparent, .3f);
            transparentPen.LineCap = PdfLineCap.Square;
            # endregion
예제 #9
0
        private Layout GetRealLayout(PdfObject obj)
        {
            if (obj is TextBlock block)
            {
                var    brush     = new PdfSolidBrush(new PdfColor(GetColor(block.Font.Color)));
                string fontStyle = "";
                if (block.Font.Bold)
                {
                    fontStyle += "b";
                }
                if (block.Font.Italic)
                {
                    fontStyle += "i";
                }

                string fontFile = Path.Combine(Directory.GetCurrentDirectory(), "Fonts", block.Font.Family, fontStyle + ".ttf");
                if (!File.Exists(fontFile))
                {
                    fontFile = Path.Combine(Directory.GetCurrentDirectory(), "Fonts", block.Font.Family + ".ttf");
                }

                Stream  fontStream = new FileStream(fontFile, FileMode.Open, FileAccess.Read);
                PdfFont pdfFont    = new PdfTrueTypeFont(fontStream, (float)block.Font.Size);

                double?width  = block.AutoWidth ? (block.MaxWidth > 0 ? block.MaxWidth : null) : block.Layout.Width;
                double?height = block.AutoHeight ? (block.MaxHeight > 0 ? block.MaxHeight : null) : block.Layout.Height;

                var textProps = GetTextProperties(block.Text, width, height, pdfFont);

                return(new Layout
                {
                    Height = textProps.Height,
                    Width = textProps.Width,
                    X = obj.Layout.X,
                    Y = obj.Layout.Y
                });
            }

            return(obj.Layout);
        }
예제 #10
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

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

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

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

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

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

            MemoryStream stream = new MemoryStream();

            //Save the PDF dcoument.
            document.Save(stream);

            //Close the PDF document.
            document.Close();

            stream.Position = 0;

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("OpenTypeFont.pdf", "application/pdf", stream, m_context);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();

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

            //Create text
            String text = "Welcome to evaluate Spire.PDF for .NET !";

            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);

            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);

            // Defines a font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Calibri", 15f, FontStyle.Regular));

            float x = 50;
            float y = 50;

            // Draw text layer
            page.Canvas.DrawString(text, font, brush, new PointF(x, y), format);

            SizeF size = font.MeasureString("Welcome to  evaluate", format);

            SizeF size2 = font.MeasureString("Spire.PDF for .NET", format);

            // Loads an image
            PdfImage image = PdfImage.FromFile("..\\..\\..\\..\\..\\..\\Data\\MultilayerImage.png");

            // Draw image layer
            page.Canvas.DrawImage(image, new PointF(x + size.Width, y), size2);

            String result = "CreateMultilayerPDF_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
        public ActionResult OpenTypeFont(string InsideBrowser)
        {
            string inputText = @"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.";

            string path = ResolveApplicationDataPath("NotoSerif-Black.otf");

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

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

            //Create font.

            Stream fontStream = System.IO.File.OpenRead(path);

            PdfFont font = new PdfTrueTypeFont(fontStream, 14);

            //Create brush.
            PdfBrush brush = new PdfSolidBrush(Color.Black);

            //Get page client size.
            SizeF clipBounds = page.Graphics.ClientSize;

            RectangleF rect = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

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

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
예제 #13
0
        /// <summary>
        /// https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html
        /// </summary>
        public void pdf()
        {
            PdfDocument      doc             = new PdfDocument();
            PdfPageBase      page            = doc.Pages.Add();
            PdfGraphicsState state           = page.Canvas.Save();
            PdfFont          font            = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush    brush           = new PdfSolidBrush(Color.Blue);
            PdfStringFormat  centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);

            float x = page.Canvas.ClientSize.Width / 2;
            float y = 380;

            page.Canvas.TranslateTransform(x, y);
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.RotateTransform(30);
                page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment);
            }
            page.Canvas.Restore(state);
            doc.SaveToFile("DrawText.pdf");
            doc.Close();
        }
예제 #14
0
파일: Program.cs 프로젝트: svcqa1/POCs
        public static PdfPageTemplateElement AddHeader(PdfDocument doc, string headerLine1, string headerLine2, string headerLine3, string waterMark, string expiryDays)
        {
            RectangleF             rect   = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 55);
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfGrid pdfGrid = new PdfGrid();

            //Add three columns
            pdfGrid.Columns.Add(3);
            PdfBrush        brush  = new PdfSolidBrush(Color.Black);
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;
            string dtNow  = DateTime.Now.ToShortDateString();
            string strSop = "SOP-2023";
            //Add rows
            PdfGridRow pdfGridRow = pdfGrid.Rows.Add();

            pdfGridRow.Cells[0].Value = headerLine1 + ":" + strSop;
            pdfGridRow.Cells[1].Value = headerLine1;
            pdfGridRow.Cells[2].Value = headerLine3 + ":" + dtNow;

            //Create the font for setting the style
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold);

            for (int i = 0; i < pdfGrid.Rows.Count; i++)
            {
                PdfGridRow row = pdfGrid.Rows[i];

                for (int j = 0; j < row.Cells.Count; j++)
                {
                    row.Cells[j].Style.Font        = font;
                    row.Cells[j].StringFormat      = format;
                    row.Cells[j].Style.Borders.All = PdfPens.Transparent;
                }
            }
            pdfGrid.Draw(header.Graphics);
            return(header);
        }
예제 #15
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 document = new PdfDocument();

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

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

            //Read the text from text file
            FileStream rtlText = new FileStream(ResolveApplicationPath("arabic.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader = new StreamReader(rtlText, System.Text.Encoding.Unicode);
            string text = reader.ReadToEnd();
            reader.Dispose();

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

            //Set the property for RTL text
            PdfStringFormat format = new PdfStringFormat();
            format.TextDirection = PdfTextDirection.RightToLeft;
            format.Alignment = PdfTextAlignment.Right;
            format.ParagraphIndent = 35f;

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect, format);
            MemoryStream stream = new MemoryStream();
            document.Save(stream);
            document.Close();
            stream.Position = 0;

            return stream;            
        }      
예제 #16
0
        public ActionResult OpenTypeFont(string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

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

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

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

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

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

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

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

            fileStreamResult.FileDownloadName = "OpenTypeFont.pdf";
            return(fileStreamResult);
        }
예제 #17
0
        private void AlignTextInRectangle(PdfPageBase page)
        {
            //Draw the text - align in rectangle
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            RectangleF rctg1 = new RectangleF(0, 70, page.Canvas.ClientSize.Width / 2, 100);
            RectangleF rctg2 = new RectangleF(page.Canvas.ClientSize.Width / 2, 70, page.Canvas.ClientSize.Width / 2, 100);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightBlue), rctg1);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightSkyBlue), rctg2);

            PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg1, leftAlignment);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg2, leftAlignment);

            PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg1, rightAlignment);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg2, rightAlignment);

            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Bottom);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg1, centerAlignment);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg2, centerAlignment);
        }
        private void AddFooter(PdfDocument doc, string footerText)
        {
            RectangleF rect      = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfColor   blueColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 255));
            PdfColor   GrayColor = new PdfColor(System.Drawing.Color.FromArgb(255, 128, 128, 128));
            //Create a page template
            PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8);

            PdfSolidBrush brush = new PdfSolidBrush(GrayColor);

            PdfPen pen = new PdfPen(blueColor, 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;
            footer.Graphics.DrawString(footerText, font, brush, new RectangleF(0, 18, footer.Width, footer.Height), format);

            format               = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Right;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

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

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

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

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

            //Add the footer template at the bottom
            doc.Template.Bottom = footer;
        }
예제 #19
0
        private void Form_Load(object sender, EventArgs e)
        {
            //Create a new PDF document.

            PdfDocument pdfDocument = new PdfDocument();

            //Add a page to the PDF document.

            PdfPage pdfPage = pdfDocument.Pages.Add();

            //Create a PDF Template.

            PdfTemplate template = new PdfTemplate(100, 50);

            //Draw a rectangle on the template graphics

            template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new System.Drawing.RectangleF(0, 0, 100, 50));

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

            PdfBrush brush = new PdfSolidBrush(Color.Black);

            //Draw a string using the graphics of the template.

            template.Graphics.DrawString("Hello World", font, brush, 5, 5);

            //Draw the template on the page graphics of the document.

            pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty);

            //Save the document.

            pdfDocument.Save("Output.pdf");

            //close the document

            pdfDocument.Close(true);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a Pdf document from disk
            PdfDocument document = new PdfDocument();

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

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

            //Set the font and brush
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular), true);
            PdfSolidBrush   brush = new PdfSolidBrush(Color.Blue);

            //Time text
            String timeString = DateTime.Now.ToString("MM/dd/yy hh:mm:ss tt ");

            //Create a template and rectangle, draw the string
            PdfTemplate template = new PdfTemplate(140, 15);
            RectangleF  rect     = new RectangleF(new PointF(page.ActualSize.Width - template.Width - 10, page.ActualSize.Height - template.Height - 10), template.Size);

            template.Graphics.DrawString(timeString, font, brush, new PointF(0, 0));

            //Create stamp annoation
            PdfRubberStampAnnotation stamp       = new PdfRubberStampAnnotation(rect);
            PdfAppearance            apprearance = new PdfAppearance(stamp);

            apprearance.Normal = template;
            stamp.Appearance   = apprearance;
            page.AnnotationsWidget.Add(stamp);

            //Sabe the document
            string output = "AddDateTimeStamp_result.pdf";

            document.SaveToFile(output, FileFormat.PDF);

            PDFDocumentViewer(output);
        }
예제 #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf");
            //Create one page
            PdfPageBase page = pdf.Pages[0];

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw rectangles
            int          x      = 200;
            int          y      = 300;
            int          width  = 200;
            int          height = 100;
            PdfPen       pen    = new PdfPen(Color.Black, 1f);
            PdfBrush     brush  = new PdfSolidBrush(Color.Red);
            PdfBlendMode mode   = new PdfBlendMode();

            page.Canvas.SetTransparency(0.5f, 0.5f, mode);
            page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height)));

            x = x + width / 2;
            y = y - height / 2;
            page.Canvas.SetTransparency(0.2f, 0.2f, mode);
            page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height)));

            //Restor graphics
            page.Canvas.Restore(state);

            String result = "SetRectangleTransparency_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
예제 #22
0
        private void TransformText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform
            PdfFont       font   = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.TranslateTransform(20, 200);
            page.Canvas.ScaleTransform(1f, 0.6f);
            page.Canvas.SkewTransform(-10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);

            page.Canvas.SkewTransform(10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);

            page.Canvas.ScaleTransform(1f, -1f);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);
            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #23
0
        private void createPDFPage(PdfDocument pdfDoc, List <QuestionAnswers> listQuestion)
        {
            int countItems = 0;
            int point      = 20;

            PdfPageBase     page       = pdfDoc.Pages.Add();
            PdfTrueTypeFont fontTrue   = new PdfTrueTypeFont(new Font("Courier", 12f, FontStyle.Bold), true);
            PdfTrueTypeFont fontFalse  = new PdfTrueTypeFont(new Font("Courier", 11f), true);
            PdfSolidBrush   brushTrue  = new PdfSolidBrush(System.Drawing.Color.Green);
            PdfSolidBrush   brushFalse = new PdfSolidBrush(System.Drawing.Color.Black);

            page.Canvas.DrawString(listQuestion[0].CategoryName, new PdfTrueTypeFont(new Font("Courier", 13f, FontStyle.Bold), true), PdfBrushes.Black, new System.Drawing.PointF(150, point));

            foreach (QuestionAnswers question in listQuestion)
            {
                countItems++;
                page.Canvas.DrawString(countItems + ") " + question.Question, new PdfTrueTypeFont(new Font("Courier", 12f, FontStyle.Bold), true), PdfBrushes.Black, new System.Drawing.PointF(0, point          += 13));
                page.Canvas.DrawString("a) " + question.ResponseA.Item2, question.ResponseA.Item1 ? fontTrue : fontFalse, question.ResponseA.Item1 ? brushTrue : brushFalse, new System.Drawing.PointF(10, point += 15));
                page.Canvas.DrawString("b) " + question.ResponseB.Item2, question.ResponseB.Item1 ? fontTrue : fontFalse, question.ResponseB.Item1 ? brushTrue : brushFalse, new System.Drawing.PointF(10, point += 14));
                page.Canvas.DrawString("c) " + question.ResponseC.Item2, question.ResponseC.Item1 ? fontTrue : fontFalse, question.ResponseC.Item1 ? brushTrue : brushFalse, new System.Drawing.PointF(10, point += 14));
                page.Canvas.DrawString("d) " + question.ResponseD.Item2, question.ResponseD.Item1 ? fontTrue : fontFalse, question.ResponseD.Item1 ? brushTrue : brushFalse, new System.Drawing.PointF(10, point += 14));
            }
        }
예제 #24
0
        private void RotateText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform
            PdfFont       font  = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            float           x = page.Canvas.ClientSize.Width / 2;
            float           y = 380;

            page.Canvas.TranslateTransform(x, y);
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.RotateTransform(30);
                page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment);
            }

            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #25
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

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

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

            string text = "Hello, World!";

            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Times New Roman", 11, FontStyle.Regular), true);
            SizeF           size  = font.MeasureString(text);
            PdfSolidBrush   brush = new PdfSolidBrush(Color.Black);
            int             x     = 60;
            int             y     = 300;

            //Draw the text on page
            page.Canvas.DrawString(text,
                                   font,
                                   new PdfSolidBrush(Color.Black),
                                   x, y);

            //Draw border for text
            page.Canvas.DrawRectangle(new PdfPen(brush, 0.5f), new Rectangle(x, y, (int)size.Width, (int)size.Height));

            String result = "AddBorderForText-result.pdf";

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

            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
예제 #26
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 Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();

            document.PageSettings.SetMargins(0);

            PdfFont  font  = new PdfStandardFont(PdfFontFamily.Helvetica, 10f);
            PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
            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 Washington with 290 employees, several regional sales teams are located throughout their market base.";

            page.Graphics.DrawString("Annotation with Comments and Reviews", font, brush, new PointF(30, 10));
            page.Graphics.DrawString(text, font, brush, new RectangleF(30, 40, page.GetClientSize().Width - 60, 60));

            string markupText = "North American, European and Asian commercial markets";
            PdfTextMarkupAnnotation textMarkupAnnot = new PdfTextMarkupAnnotation("sample", "Highlight", markupText, new PointF(147, 63.5f), font);

            textMarkupAnnot.Author                   = "Annotation";
            textMarkupAnnot.Opacity                  = 1.0f;
            textMarkupAnnot.Subject                  = "Comments and Reviews";
            textMarkupAnnot.ModifiedDate             = new DateTime(2015, 1, 18);
            textMarkupAnnot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
            textMarkupAnnot.TextMarkupColor          = new PdfColor(System.Drawing.Color.Yellow);
            textMarkupAnnot.InnerColor               = new PdfColor(System.Drawing.Color.Red);
            textMarkupAnnot.Color = new PdfColor(System.Drawing.Color.Yellow);
            if (flatten.IsChecked == true)
            {
                textMarkupAnnot.Flatten = true;
            }
            //Create a new comment.
            PdfPopupAnnotation userQuery = new PdfPopupAnnotation();

            userQuery.Author       = "John";
            userQuery.Text         = "Can you please change South Asian to Asian?";
            userQuery.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userQuery);

            //Creates a new comment
            PdfPopupAnnotation userAnswer = new PdfPopupAnnotation();

            userAnswer.Author       = "Smith";
            userAnswer.Text         = "South Asian has changed as Asian";
            userAnswer.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userAnswer);

            //Creates a new review
            PdfPopupAnnotation userAnswerReview = new PdfPopupAnnotation();

            userAnswerReview.Author       = "Smith";
            userAnswerReview.State        = PdfAnnotationState.Completed;
            userAnswerReview.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReview.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReview);

            //Creates a new review
            PdfPopupAnnotation userAnswerReviewJohn = new PdfPopupAnnotation();

            userAnswerReviewJohn.Author       = "John";
            userAnswerReviewJohn.State        = PdfAnnotationState.Accepted;
            userAnswerReviewJohn.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReviewJohn.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReviewJohn);

            //Add annotation to the page
            page.Annotations.Add(textMarkupAnnot);

            RectangleF bounds = new RectangleF(350, 170, 80, 80);

            //Creates a new Circle annotation.
            PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds);

            circleannotation.InnerColor      = new PdfColor(System.Drawing.Color.Yellow);
            circleannotation.Color           = new PdfColor(System.Drawing.Color.Red);
            circleannotation.AnnotationFlags = PdfAnnotationFlags.Default;
            circleannotation.Author          = "Syncfusion";
            circleannotation.Subject         = "CircleAnnotation";
            circleannotation.ModifiedDate    = new DateTime(2015, 1, 18);
            page.Annotations.Add(circleannotation);
            page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 130));


            //Creates a new Ellipse annotation.
            PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 150, 50, 100), "Ellipse Annotation");

            ellipseannotation.Color      = new PdfColor(System.Drawing.Color.Red);
            ellipseannotation.InnerColor = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 130));
            page.Annotations.Add(ellipseannotation);

            //Creates a new Square annotation.
            PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 300, 80, 80));

            squareannotation.Text       = "SquareAnnotation";
            squareannotation.InnerColor = new PdfColor(System.Drawing.Color.Red);
            squareannotation.Color      = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 280));
            page.Annotations.Add(squareannotation);

            //Creates a new Rectangle annotation.
            RectangleF             rectannot           = new RectangleF(350, 320, 100, 50);
            PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation");

            rectangleannotation.InnerColor = new PdfColor(System.Drawing.Color.Red);
            rectangleannotation.Color      = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 280));
            page.Annotations.Add(rectangleannotation);

            //Creates a new Line annotation.
            int[]             points         = new int[] { 400, 350, 550, 350 };
            PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type...");

            lineAnnotation.Author       = "Syncfusion";
            lineAnnotation.Subject      = "LineAnnotation";
            lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18);
            lineAnnotation.Text         = "PdfLineAnnotation";
            lineAnnotation.BackColor    = new PdfColor(System.Drawing.Color.Red);
            page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 420));
            page.Annotations.Add(lineAnnotation);

            //Creates a new Polygon annotation.
            int[] polypoints = new int[] { 50, 298, 100, 325, 200, 355, 300, 230, 180, 230 };
            PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation");

            polygonannotation.Bounds = new RectangleF(30, 210, 300, 200);
            PdfPen pen = new PdfPen(System.Drawing.Color.Red);

            polygonannotation.Text       = "polygon";
            polygonannotation.Color      = new PdfColor(System.Drawing.Color.Red);
            polygonannotation.InnerColor = new PdfColor(System.Drawing.Color.LightPink);
            page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 420));
            page.Annotations.Add(polygonannotation);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect = new RectangleF(405, 645, 80, 30);
            PdfFreeTextAnnotation freeText     = new PdfFreeTextAnnotation(freetextrect);

            freeText.MarkupText      = "Free Text with Callouts";
            freeText.TextMarkupColor = new PdfColor(System.Drawing.Color.Green);
            freeText.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText.BorderColor     = new PdfColor(System.Drawing.Color.Blue);
            freeText.Border          = new PdfAnnotationBorder(.5f);
            freeText.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText.Text            = "Free Text";
            freeText.Color           = new PdfColor(System.Drawing.Color.Yellow);
            PointF[] Freetextpoints = { new PointF(365, 700), new PointF(379, 654), new PointF(405, 654) };
            freeText.CalloutLines = Freetextpoints;
            page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 610));
            page.Annotations.Add(freeText);

            //Creates a new Ink annotation.
            List <float> linePoints = new List <float> {
                72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f
            };
            RectangleF       rectangle     = new RectangleF(30, 580, 300, 400);
            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints);

            inkAnnotation.Bounds = rectangle;
            inkAnnotation.Color  = new PdfColor(System.Drawing.Color.Red);
            page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610));
            page.Annotations.Add(inkAnnotation);

            PdfPage secondPage = document.Pages.Add();


            //Creates a new TextMarkup annotation.
            string s = "This is TextMarkup annotation!!!";

            secondPage.Graphics.DrawString(s, font, brush, new PointF(30, 70));
            PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Strikeout", s, new PointF(30, 70), font);

            textannot.Author                   = "Annotation";
            textannot.Opacity                  = 1.0f;
            textannot.Subject                  = "pdftextmarkupannotation";
            textannot.ModifiedDate             = new DateTime(2015, 1, 18);
            textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut;
            textannot.TextMarkupColor          = new PdfColor(System.Drawing.Color.Yellow);
            textannot.InnerColor               = new PdfColor(System.Drawing.Color.Red);
            textannot.Color = new PdfColor(System.Drawing.Color.Yellow);
            if (flatten.IsChecked == true)
            {
                textannot.Flatten = true;
            }
            secondPage.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 40));
            secondPage.Annotations.Add(textannot);

            //Creates a new popup annotation.
            RectangleF         popupRect       = new RectangleF(430, 70, 30, 30);
            PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation();

            popupAnnotation.Border.Width            = 4;
            popupAnnotation.Border.HorizontalRadius = 20;
            popupAnnotation.Border.VerticalRadius   = 30;
            popupAnnotation.Opacity    = 1;
            popupAnnotation.Open       = true;
            popupAnnotation.Text       = "Popup Annotation";
            popupAnnotation.Color      = System.Drawing.Color.Green;
            popupAnnotation.InnerColor = System.Drawing.Color.Blue;
            popupAnnotation.Bounds     = popupRect;
            if (flatten.IsChecked == true)
            {
                popupAnnotation.FlattenPopUps = true;
                popupAnnotation.Flatten       = true;
            }
            secondPage.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 40));
            secondPage.Annotations.Add(popupAnnotation);

            //Creates a new Line measurement annotation.
            points = new int[] { 400, 630, 550, 630 };
            PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points);

            lineMeasureAnnot.Author                 = "Syncfusion";
            lineMeasureAnnot.Subject                = "LineAnnotation";
            lineMeasureAnnot.ModifiedDate           = new DateTime(2015, 1, 18);
            lineMeasureAnnot.Unit                   = PdfMeasurementUnit.Inch;
            lineMeasureAnnot.lineBorder.BorderWidth = 2;
            lineMeasureAnnot.Font                   = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);
            lineMeasureAnnot.Color                  = new PdfColor(System.Drawing.Color.Red);
            if (flatten.IsChecked == true)
            {
                lineMeasureAnnot.Flatten = true;
            }
            secondPage.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 130));
            secondPage.Annotations.Add(lineMeasureAnnot);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect0 = new RectangleF(80, 160, 100, 50);
            PdfFreeTextAnnotation freeText0     = new PdfFreeTextAnnotation(freetextrect0);

            freeText0.MarkupText      = "Free Text with Callouts";
            freeText0.TextMarkupColor = new PdfColor(System.Drawing.Color.Green);
            freeText0.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText0.BorderColor     = new PdfColor(System.Drawing.Color.Blue);
            freeText0.Border          = new PdfAnnotationBorder(.5f);
            freeText0.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText0.Text            = "Free Text";
            freeText0.Rotate          = PdfAnnotationRotateAngle.RotateAngle90;
            freeText0.Color           = new PdfColor(System.Drawing.Color.Yellow);
            PointF[] Freetextpoints0 = { new PointF(45, 220), new PointF(60, 175), new PointF(80, 175) };
            freeText0.CalloutLines = Freetextpoints0;
            secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 130));
            if (flatten.IsChecked == true)
            {
                freeText0.Flatten = true;
            }
            secondPage.Annotations.Add(freeText0);

            PdfRectangleAnnotation cloudannotation = new PdfRectangleAnnotation(new RectangleF(30, 300, 100, 50), "Rectangle Cloud Annoatation");

            cloudannotation.Border.BorderWidth = 1;
            cloudannotation.Color      = System.Drawing.Color.Red;
            cloudannotation.InnerColor = System.Drawing.Color.Blue;
            PdfBorderEffect bordereffect = new PdfBorderEffect();

            bordereffect.Intensity       = 2;
            bordereffect.Style           = PdfBorderEffectStyle.Cloudy;
            cloudannotation.BorderEffect = bordereffect;
            secondPage.Graphics.DrawString("Cloud Annotation", font, brush, new PointF(40, 260));
            secondPage.Annotations.Add(cloudannotation);
            if (flatten.IsChecked == false)
            {
                PdfRedactionAnnotation redactionannot = new PdfRedactionAnnotation();
                redactionannot.Bounds        = new RectangleF(350, 300, 100, 50);
                redactionannot.Text          = "Redaction Annotation";
                redactionannot.InnerColor    = System.Drawing.Color.Orange;
                redactionannot.BorderColor   = System.Drawing.Color.Red;
                redactionannot.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 13);
                redactionannot.TextColor     = System.Drawing.Color.Green;
                redactionannot.OverlayText   = "REDACTED";
                redactionannot.RepeatText    = true;
                redactionannot.TextAlignment = PdfTextAlignment.Left;
                redactionannot.SetAppearance(true);
                secondPage.Graphics.DrawString("Redaction Annotation", font, brush, new PointF(350, 260));
                secondPage.Annotations.Add(redactionannot);
            }
            //Saving the document
            MemoryStream SourceStream = new MemoryStream();

            document.Save(SourceStream);
            document.Close(true);

            //Loading and flatten the  annotation
            PdfLoadedDocument lDoc   = new PdfLoadedDocument(SourceStream);
            PdfLoadedPage     lpage1 = lDoc.Pages[0] as PdfLoadedPage;
            PdfLoadedPage     lpage2 = lDoc.Pages[1] as PdfLoadedPage;

            if (flatten.IsChecked == true)
            {
                lpage1.Annotations.Flatten = true;
                lpage2.Annotations.Flatten = true;
            }
            MemoryStream stream = new MemoryStream();
            await lDoc.SaveAsync(stream);

            lDoc.Close(true);

            Save(stream, "Sample.pdf");
        }
        public ActionResult DrawingShapes(string InsideBrowser)
        {
            // Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            int         i;
            // Create a new page.
            PdfPage page = doc.Pages.Add();
            // Obtain PdfGraphics object.
            PdfGraphics g    = page.Graphics;
            PdfFont     font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);

            #region Polygon
            PdfPen pen = new PdfPen(Color.Black);
            pen.Width = 3;
            PointF p1 = new PointF(05, 10);
            PointF p2 = new PointF(05, 10);
            PointF p3 = new PointF(60, 70);
            PointF p4 = new PointF(40, 70);

            PointF[] points = { p1, p2, p3, p4 };

            int pointNum = 16;
            points = new PointF[pointNum];
            double       f      = 360.0 / pointNum * Math.PI / 180.0;
            const double r      = 100;
            PointF       center = new PointF(140, 140);

            for (i = 0; i < pointNum; ++i)
            {
                PointF p     = new PointF();
                double theta = i * f;

                p.Y = (float)(Math.Sin(theta) * r + center.Y);
                p.X = (float)(Math.Cos(theta) * r + center.X);

                points[i] = p;
            }

            PdfSolidBrush brush = new PdfSolidBrush(Color.Green);
            pen.Color    = Color.Brown;
            pen.Width    = 10;
            pen.LineJoin = PdfLineJoin.Round;
            g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0));
            g.DrawPolygon(pen, brush, points);

            #endregion

            #region  Pie

            RectangleF rect = new RectangleF(200, 50, 200, 200);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            pen.Width   = 10;

            rect.Location = new PointF(20, 280);
            pen.LineJoin  = PdfLineJoin.Round;
            g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250));
            g.DrawPie(pen, brush, rect, 180, 60);
            g.DrawPie(pen, brush, rect, 360 - 60, 60);
            g.DrawPie(pen, brush, rect, 60, 60);

            #endregion

            #region Arc

            g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0));
            pen         = new PdfPen(Color.Black);
            pen.Width   = 11;
            pen.LineCap = PdfLineCap.Round;
            pen.Color   = Color.Brown;
            rect        = new RectangleF(310, 40, 200, 200);
            g.DrawArc(pen, rect, 0, 90);

            pen.Color = Color.DarkGreen;
            rect.X   -= 10;
            g.DrawArc(pen, rect, 90, 90);

            pen.Color = Color.Brown;
            rect.Y   -= 10;
            g.DrawArc(pen, rect, 180, 90);

            pen.Color = Color.DarkGreen;
            rect.X   += 10;
            g.DrawArc(pen, rect, 270, 90);

            #endregion

            #region Rectangle
            rect        = new RectangleF(310, 280, 200, 100);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255));
            g.DrawRectangle(pen, brush, rect);
            #endregion

            #region ellipse
            pen  = new PdfPen(Color.Black);
            rect = new RectangleF(270, 400, 160, 1000);
            g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390));
            PdfEllipse      ellipse = new PdfEllipse(rect);
            PdfLayoutFormat format  = new PdfLayoutFormat();
            format.Break  = PdfLayoutBreakType.FitPage;
            format.Layout = PdfLayoutType.Paginate;
            ellipse.Brush = PdfBrushes.Brown;
            ellipse.Draw(page, 20, 20, format);

            brush         = new PdfSolidBrush(Color.Black);
            ellipse.Brush = PdfBrushes.DarkGreen;
            ellipse.Draw(page, 40, 40, format);

            #endregion

            #region Transaparency

            page = doc.Pages[1];
            g    = page.Graphics;
            g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80));
            PdfBrush gBrush;
            rect = new RectangleF(10, 150, 100, 100);

            pen    = new PdfPen(Color.Black);
            gBrush = new PdfSolidBrush(Color.DarkGreen);

            g.DrawRectangle(pen, gBrush, rect);
            gBrush  = new PdfSolidBrush(Color.Brown);
            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Brown);
            g.SetTransparency(0.7f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            gBrush  = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal);
            g.SetTransparency(0.5f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Blue);
            gBrush  = new PdfSolidBrush(Color.Gray);
            g.SetTransparency(0.25f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Black);
            gBrush  = new PdfSolidBrush(Color.Green);
            g.SetTransparency(0.1f);
            g.DrawRectangle(pen, gBrush, rect);

            #endregion

            #region Rectangle with Color space



            PointF location = new PointF(10, 50);
            page = doc.Pages.Add();
            g    = page.Graphics;

            doc.ColorSpace = (PdfColorSpace)i;

            // SolidBrush
            gBrush = new PdfSolidBrush(Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // LinearGradient
            location = new PointF(180, 50);

            PointF point2 = location;

            point2.X += 180;
            gBrush    = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // Raidal Gradient
            location = new PointF(360, 50);
            point2   = location;

            point2 = new PointF(location.X + 50, location.Y + 50);
            //point2.Y += 250;
            //point2.X = 150;
            gBrush = new PdfRadialGradientBrush(point2, 0, point2, 100, Color.Blue, Color.Red);
            (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.Both;
            DrawRectangles(location, g, font, gBrush, pen, doc);

            g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0));
            #endregion

            //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);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Shapes.pdf";
            return(fileStreamResult);
        }
        /// <summary>
        /// Create ZugFerd Invoice Pdf
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public PdfDocument CreateZugFerdInvoicePDF(PdfDocument document)
        {
            //Add page to the PDF
            PdfPage page = document.Pages.Add();

            PdfGraphics graphics = page.Graphics;

            //Create border color
            PdfColor borderColor = Syncfusion.Drawing.Color.FromArgb(255, 142, 170, 219);

            //Get the page width and height
            float pageWidth  = page.GetClientSize().Width;
            float pageHeight = page.GetClientSize().Height;

            //Set the header height
            float headerHeight = 90;


            PdfColor lightBlue      = Syncfusion.Drawing.Color.FromArgb(255, 91, 126, 215);
            PdfBrush lightBlueBrush = new PdfSolidBrush(lightBlue);

            PdfColor darkBlue      = Syncfusion.Drawing.Color.FromArgb(255, 65, 104, 209);
            PdfBrush darkBlueBrush = new PdfSolidBrush(darkBlue);

            PdfBrush whiteBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 255, 255));

#if COMMONSB
            Stream fontStream = typeof(ZugFerd).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.arial.ttf");
#else
            Stream fontStream = typeof(ZugFerd).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.arial.ttf");
#endif

            PdfTrueTypeFont headerFont = new PdfTrueTypeFont(fontStream, 30, PdfFontStyle.Regular);

            PdfTrueTypeFont arialRegularFont = new PdfTrueTypeFont(fontStream, 18, PdfFontStyle.Regular);
            PdfTrueTypeFont arialBoldFont    = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Bold);

            //Create string format.
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            float y = 0;
            float x = 0;

            //Set the margins of address.
            float margin = 30;

            //Set the line space
            float lineSpace = 7;

            PdfPen borderPen = new PdfPen(borderColor, 1f);

            //Draw page border
            graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight));


            PdfGrid grid = new PdfGrid();

            grid.DataSource = GetProductReport();

            #region Header

            //Fill the header with light Brush
            graphics.DrawRectangle(lightBlueBrush, new RectangleF(0, 0, pageWidth, headerHeight));

            string title = "INVOICE";

            SizeF textSize = headerFont.MeasureString(title);

            RectangleF headerTotalBounds = new RectangleF(400, 0, pageWidth - 400, headerHeight);

            graphics.DrawString(title, headerFont, whiteBrush, new RectangleF(0, 0, textSize.Width + 50, headerHeight), format);

            graphics.DrawRectangle(darkBlueBrush, headerTotalBounds);

            graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight + 10), format);

            arialRegularFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Regular);

            format.LineAlignment = PdfVerticalAlignment.Bottom;
            graphics.DrawString("Amount", arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight / 2 - arialRegularFont.Height), format);

            #endregion


            SizeF size = arialRegularFont.MeasureString("Invoice Number: 2058557939");
            y = headerHeight + margin;
            x = (pageWidth - margin) - size.Width;

            graphics.DrawString("Invoice Number: 2058557939", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            size = arialRegularFont.MeasureString("Date :" + DateTime.Now.ToString("dddd dd, MMMM yyyy"));
            x    = (pageWidth - margin) - size.Width;
            y   += arialRegularFont.Height + lineSpace;

            graphics.DrawString("Date: " + DateTime.Now.ToString("dddd dd, MMMM yyyy"), arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y = headerHeight + margin;
            x = margin;
            graphics.DrawString("Bill To:", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("Abraham Swearegin,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("United States, California, San Mateo,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("9920 BridgePointe Parkway,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("9365550136", arialRegularFont, PdfBrushes.Black, new PointF(x, y));


            #region Grid

            grid.Columns[0].Width = 110;
            grid.Columns[1].Width = 150;
            grid.Columns[2].Width = 110;
            grid.Columns[3].Width = 70;
            grid.Columns[4].Width = 100;

            for (int i = 0; i < grid.Headers.Count; i++)
            {
                grid.Headers[i].Height = 20;
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    PdfStringFormat pdfStringFormat = new PdfStringFormat();
                    pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle;

                    pdfStringFormat.Alignment = PdfTextAlignment.Left;
                    if (j == 0 || j == 2)
                    {
                        grid.Headers[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1);
                    }

                    grid.Headers[i].Cells[j].StringFormat = pdfStringFormat;

                    grid.Headers[i].Cells[j].Style.Font = arialBoldFont;
                }
                grid.Headers[0].Cells[0].Value = "Product Id";
            }
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Height = 23;
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    PdfStringFormat pdfStringFormat = new PdfStringFormat();
                    pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle;

                    pdfStringFormat.Alignment = PdfTextAlignment.Left;
                    if (j == 0 || j == 2)
                    {
                        grid.Rows[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1);
                    }

                    grid.Rows[i].Cells[j].StringFormat = pdfStringFormat;
                    grid.Rows[i].Cells[j].Style.Font   = arialRegularFont;
                }
            }
            grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.ListTable4Accent5);
            grid.BeginCellLayout += Grid_BeginCellLayout;


            PdfGridLayoutResult result = grid.Draw(page, new PointF(0, y + 40));

            y                = result.Bounds.Bottom + lineSpace;
            format           = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Center;
            RectangleF bounds = new RectangleF(QuantityCellBounds.X, y, QuantityCellBounds.Width, QuantityCellBounds.Height);

            page.Graphics.DrawString("Grand Total:", arialBoldFont, PdfBrushes.Black, bounds, format);

            bounds = new RectangleF(TotalPriceCellBounds.X, y, TotalPriceCellBounds.Width, TotalPriceCellBounds.Height);
            page.Graphics.DrawString(GetTotalAmount(grid).ToString(), arialBoldFont, PdfBrushes.Black, bounds);


            #endregion



            borderPen.DashStyle   = PdfDashStyle.Custom;
            borderPen.DashPattern = new float[] { 3, 3 };

            graphics.DrawLine(borderPen, new PointF(0, pageHeight - 100), new PointF(pageWidth, pageHeight - 100));

            y = pageHeight - 100 + margin;

            size = arialRegularFont.MeasureString("800 Interchange Blvd.");

            x = pageWidth - size.Width - margin;

            graphics.DrawString("800 Interchange Blvd.", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y += arialRegularFont.Height + lineSpace;

            size = arialRegularFont.MeasureString("Suite 2501,  Austin, TX 78721");

            x = pageWidth - size.Width - margin;

            graphics.DrawString("Suite 2501,  Austin, TX 78721", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y += arialRegularFont.Height + lineSpace;

            size = arialRegularFont.MeasureString("Any Questions? [email protected]");

            x = pageWidth - size.Width - margin;
            graphics.DrawString("Any Questions? [email protected]", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            return(document);
        }
예제 #29
0
        static void LinesTable_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
        {
            PdfFont helv11 = new PdfFont(PdfFontFamily.Helvetica, 11f);
            PdfFont helv12Bold = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            PdfStringFormat centered = new PdfStringFormat(PdfTextAlignment.Center);
            PdfBrush gray = new PdfSolidBrush(Color.LightGray);
            PdfBrush clear = new PdfSolidBrush(Color.Transparent);

            args.CellStyle.BorderPen = new PdfPen(Color.Transparent);
            args.CellStyle.BackgroundBrush = clear;

            if(args.RowIndex == 0)
            {
                //header
                args.CellStyle.Font = helv12Bold;

            }
            else
                args.CellStyle.Font = helv11;

            if(args.RowIndex % 2 != 0)
            {
                args.CellStyle.BackgroundBrush = gray;
            }
        }
예제 #30
0
        protected void PDFQuote(Object source, EventArgs e)
        {
            //demos: http://www.e-iceblue.com/Tutorials/Spire.PDF/Demos.html //had to add permissions to IIS Express Folder for Network Users. Wont export more than 10 pages on free version.

            SaveQuote();

            var filename = PdfFileName.Value;
            if (filename == "CANCELDONOTMAKE") return;

            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
                float pageWidth = page.Canvas.ClientSize.Width;
                float y = 0;

            //formatting helpers
            PdfStringFormat centered = new PdfStringFormat(PdfTextAlignment.Center);
            PdfStringFormat rightAlign = new PdfStringFormat(PdfTextAlignment.Right);
            PdfFont helv24 = new PdfFont(PdfFontFamily.Helvetica, 24f, PdfFontStyle.Bold);
            PdfFont helv20 = new PdfFont(PdfFontFamily.Helvetica, 20f, PdfFontStyle.Bold);
            PdfFont helv16 = new PdfFont(PdfFontFamily.Helvetica, 16f, PdfFontStyle.Bold);
            PdfFont helv14 = new PdfFont(PdfFontFamily.Helvetica, 14f);
            PdfFont helv12 = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfFont helv12Bold = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            PdfFont helv11 = new PdfFont(PdfFontFamily.Helvetica, 11f);
            PdfFont helv9Ital = new PdfFont(PdfFontFamily.Helvetica, 9f, PdfFontStyle.Italic);
            PdfFont helv8  = new PdfFont(PdfFontFamily.Helvetica, 8f);
            PdfBrush black = new PdfSolidBrush(Color.Black);
            SizeF size;

            string brand = "Texas Digital Systems, Inc.";
            string address = "400 Technology Parkway  College Station, TX 77845";
            string contact = "(979) 693-9378 Voice  (979) 764-8650 Fax";
            string title = "Proposal Summary";

            //HEADER
            page.Canvas.DrawString(brand, helv24, new PdfSolidBrush(Color.Black), pageWidth/2, y, centered);
                size = helv24.MeasureString(brand);
                y += size.Height + 1;
            page.Canvas.DrawString(address, helv12, black, pageWidth/2, y, centered);
                size = helv12.MeasureString(address);
                y += size.Height + 1;
            page.Canvas.DrawString(contact, helv12, black, pageWidth / 2, y, centered);
                size = helv12.MeasureString(contact);
                y += size.Height + 1;
            page.Canvas.DrawString("By: " + quote.Owner, helv12, black, 0, y);
            page.Canvas.DrawString(quote.Email, helv12, black, pageWidth, y, rightAlign);
            size = helv12.MeasureString(contact);
            y += size.Height + 1;
            page.Canvas.DrawString("Date: " + quote.Date, helv12, black, 0, y);
            page.Canvas.DrawString("PN: " + quote.PhoneNumber, helv12, black, pageWidth, y, rightAlign);
                size = helv12.MeasureString(quote.Owner);
                y += size.Height + 5;
            page.Canvas.DrawString(title, helv20, black, pageWidth / 2, y, centered);
                size = helv20.MeasureString(title);
                y += size.Height + 5;

            //ADDRESS TABLE
            PdfTable addressTable = new PdfTable();
            addressTable.Style.CellPadding = 1;
            addressTable.Style.BorderPen = new PdfPen(PdfBrushes.Black, .5f);

            string[] addressData
                = {
                      ";Customer Address;Billing Address;Shipping Address",
                      "Contact;"+quote.Customer.Contact+";"+quote.Billing.Contact+";"+quote.Shipping.Contact,
                      "Company;"+quote.Customer.Company+";"+quote.Billing.Company+";"+quote.Shipping.Company,
                      "Address1;"+quote.Customer.Address1+";"+quote.Billing.Address1+";"+quote.Shipping.Address1,
                      "Address2;"+quote.Customer.Address2+";"+quote.Billing.Address2+";"+quote.Shipping.Address2,
                      "City/State/Zip;"+quote.Customer.CityState+";"+quote.Billing.CityState+";"+quote.Shipping.CityState,
                      "Phone;"+quote.Customer.Phone+";"+quote.Billing.Phone+";"+quote.Shipping.Phone,
                      "Fax;"+quote.Customer.Fax+";"+quote.Billing.Fax+";"+quote.Shipping.Fax,
                      "Email;"+quote.Customer.Email+";"+quote.Billing.Email+";"+quote.Shipping.Email
                  };

            string[][] addressDataSource = new string[addressData.Length][];
            for (int i = 0; i < addressData.Length; i++)
                addressDataSource[i] = addressData[i].Split(';');

            addressTable.DataSource = addressDataSource;
            float width = page.Canvas.ClientSize.Width - (addressTable.Columns.Count + 1) * addressTable.Style.BorderPen.Width;
            for (int i = 0; i < addressTable.Columns.Count; i++)
            {
                if(i==0)
                    addressTable.Columns[i].Width = width * .12f * width;
                else
                    addressTable.Columns[i].Width = width * .2f * width;
            }
            addressTable.BeginRowLayout += new BeginRowLayoutEventHandler(addressTable_BeginRowLayout);

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

            //QUOTE DETAILS
            PdfTable detailsTable = new PdfTable();
            detailsTable.Style.CellPadding = 1;
            detailsTable.Style.BorderPen = new PdfPen(PdfBrushes.Black, .5f);
            detailsTable.Style.DefaultStyle.Font = helv11;
            detailsTable.Style.DefaultStyle.StringFormat = centered;
            width = page.Canvas.ClientSize.Width - (detailsTable.Columns.Count + 1) * detailsTable.Style.BorderPen.Width;

            //converting t/f to y/n
            string NewLocation, Dealer, TaxExempt;
            if (quote.NewLocation) NewLocation = "Yes";
                else NewLocation = "No";
            if (quote.Dealer) Dealer = "Yes";
                else Dealer = "No";
            if (quote.TaxExempt == "exempt") TaxExempt = "Yes";
                else TaxExempt = "No";

            string[] detailsData
                = {
                      "Source: ;"+quote.Source+";Source Specific: ;"+quote.SpecificSource+";No. Of Locations: ;"+quote.LocationCount,
                      "POS Provider: ;"+quote.POSProvidor+";Install Date: ;"+quote.InstallDate+";Business Unit: ;"+quote.BusinessUnit,
                      "New Location: ;"+NewLocation+";Dealer: ;"+Dealer+";Tax Exempt: ;"+TaxExempt
                  };

            string[][] detailsDataSource = new string[detailsData.Length][];
            for (int i = 0; i < detailsData.Length; i++)
                detailsDataSource[i] = detailsData[i].Split(';');

            detailsTable.DataSource = detailsDataSource;
            for (int i = 0; i < detailsTable.Columns.Count; i++)
            {
                if (i %2 != 0)
                    detailsTable.Columns[i].Width = width * .05f * width;
                else
                    detailsTable.Columns[i].Width = width * .08f * width;
            }

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

            //QUOTE LINES
            if(quote.linesHW.Count > 0)
            {
                page.Canvas.DrawString("Hardware", helv16, black, pageWidth / 2, y, centered);
                    size = helv14.MeasureString("Hardware");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesHW,"Hardware", y)).Bounds.Height + 2;
            }

            if(quote.linesSW.Count > 0)
            {
                page.Canvas.DrawString("Software", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Software & Maintenance");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesSW,"Software", y)).Bounds.Height + 2;
            }

            if(quote.linesCC.Count > 0)
            {
                page.Canvas.DrawString("Content", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Content");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesCC,"Content", y)).Bounds.Height + 2;
            }

            if(quote.linesInst.Count > 0)
            {
                page.Canvas.DrawString("Installation", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Installation");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesInst, "Installation", y)).Bounds.Height + 2;
            }

            if (quote.linesRec.Count > 0)
            {
                page.Canvas.DrawString("Recurring", helv16, black, pageWidth / 2, y, centered);
                size = helv16.MeasureString("Recurring");
                y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesRec, "Recurring", y)).Bounds.Height + 2;
            }

            bool FreightExists = false; if (quote.Freight > 0) FreightExists = true;
            bool SalesTaxExists = false; if (quote.SalesTax > 0) SalesTaxExists = true;
            double GrandTotal = quote.GetGrandTotal();

            //NOTES
            if (quote.ExternalNotes.Length > 0)
            {
                string notes = quote.ExternalNotes;
                PdfStringLayouter layouter = new PdfStringLayouter();
                PdfStringFormat format = new PdfStringFormat();
                format.LineSpacing = helv11.Size * 1.5f;

                PdfStringLayoutResult result = layouter.Layout(notes, helv11, format, new SizeF(pageWidth, y));

                page.Canvas.DrawString("Notes", helv14, black, pageWidth / 2, y, centered);
                size = helv14.MeasureString("LULZ");
                y += size.Height + 2;

                foreach (LineInfo line in result.Lines)
                {
                    page.Canvas.DrawString(line.Text, helv11, black, 0, y, format);
                    y = y + result.LineHeight;
                }

            }

            y += 5;
            page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, y), new PointF(pageWidth, y));
            y += 5;

            //TOTALS
            if(FreightExists || SalesTaxExists)
            {
                page.Canvas.DrawString("Subtotal: $" + GrandTotal.ToString(), helv12, black, 0, y);
            }
            if(FreightExists)
            {
                page.Canvas.DrawString("Freight: $" + quote.Freight.ToString(), helv12, black, pageWidth/4, y);
                GrandTotal += quote.Freight;
            }
            if (SalesTaxExists)
            {
                page.Canvas.DrawString("Sales Tax: $" + quote.SalesTax.ToString(), helv12, black, pageWidth / 2, y);
                GrandTotal += quote.SalesTax;
            }

            page.Canvas.DrawString("Total: $" + GrandTotal.ToString(), helv12Bold, black, pageWidth, y, rightAlign);
                size = helv12Bold.MeasureString("999999");

            y += size.Height + 5;
            page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, y), new PointF(pageWidth, y));
            y += 5;

            //FINE PRINT
            page.Canvas.DrawString("Quote is good for: " + quote.QuoteLength + " days", helv8, black, 0, y);
            page.Canvas.DrawString("F.O.B. College Station, TX", helv8, black, pageWidth / 2, y, centered);
            page.Canvas.DrawString("Payment Terms: " + quote.PaymentTerms, helv8, black, pageWidth, y, rightAlign);
                size = helv8.MeasureString("THESE WORDS DON'T MATTER");
                y += size.Height + 1;

            page.Canvas.DrawString("This is not an invoice and may not include freight and/or sales tax. An invoice will be sent upon receipt of the signed quote.", helv9Ital, black, pageWidth/2, y, centered);
                size = helv9Ital.MeasureString("ONLY DEVS WILL SEE THIS");
                y += size.Height + 10;

            page.Canvas.DrawString("Please sign to accept this quotation: ", helv8, black, 0, y);
                size = helv8.MeasureString("I CAN SAY WHATEVER I WANT");
                page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(150, y+size.Height), new PointF(350, y+size.Height));
                y += size.Height + 1;

            page.Canvas.DrawString("By signing I agree that I have read, understand and agree to be bound by the Texas Digital Standard Terms and Conditions Applicable to", helv8, black, 0, y);
                size = helv8.MeasureString("PAY UP GUY");
                y += size.Height + 1;

            page.Canvas.DrawString("Quotes and Purchase Orders accessible at: ", helv8, black, 0, y);
                size = helv8.MeasureString("Quotes and Purchase Orders accessible at: ");
                page.Canvas.DrawString("http://www.ncr.com/wp-content/uploads/TXDigital_Terms_and_Conditions.pdf", helv8, PdfBrushes.DarkGreen, size.Width, y);
                y += size.Height + 1;

            page.Canvas.DrawString("After signing please fax to (979) 764-8650", helv8, black, 0, y);
            page.Canvas.DrawString("Delivery ARO: 45-60 days", helv8, black, pageWidth, y, rightAlign);
                size = helv8.MeasureString("THIS ISNT THE END LOL");
                y += size.Height + 1;

            //pdf.SaveToFile(filename);
            pdf.SaveToHttpResponse(filename, Response, HttpReadType.Save);
            pdf.Close();
            System.Diagnostics.Process.Start(filename);
        }
        public ActionResult RtlSupport(string InsideBrowser)
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();

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

            //Create font
            Font    f    = new Font("Arial", 14);
            PdfFont font = new PdfTrueTypeFont(f, true);
            string  path = ResolveApplicationDataPath("arabic.txt");

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

            reader.Close();

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

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

            format.TextDirection   = PdfTextDirection.RightToLeft;
            format.Alignment       = PdfTextAlignment.Right;
            format.ParagraphIndent = 35f;

            page.Graphics.DrawString(text, font, brush, rect, format);
            page.Graphics.DrawRectangle(pen, rect);

            //Set the alignment
            format.Alignment = PdfTextAlignment.Center;
            rect.Offset(rect.Width, 0);
            page.Graphics.DrawString(text, font, brush, rect, format);
            page.Graphics.DrawRectangle(pen, rect);

            format.Alignment = PdfTextAlignment.Right;
            rect.Offset(-rect.Width, rect.Height);
            page.Graphics.DrawString(text, font, brush, rect, format);
            page.Graphics.DrawRectangle(pen, rect);

            format.Alignment     = PdfTextAlignment.Justify;
            format.LineAlignment = PdfVerticalAlignment.Middle;
            rect.Offset(rect.Width, 0);
            page.Graphics.DrawString(text, font, brush, rect, format);
            page.Graphics.DrawRectangle(pen, rect);

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
예제 #32
0
        private void TransformText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.TranslateTransform(20, 200);
            page.Canvas.ScaleTransform(1f, 0.6f);
            page.Canvas.SkewTransform(-10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);

            page.Canvas.SkewTransform(10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);

            page.Canvas.ScaleTransform(1f, -1f);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);
            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #33
0
        protected void Grid1_ServerPdfExporting(object sender, GridEventArgs e)
        {
            PdfExport exp = new PdfExport();

            SummaryGridBind();
            if (dsSummary.Tables[0].Rows.Count > 0)
            {
                DataTable dtSummary = dsSummary.Tables[0];
                //List<DataRow> list = FamilyDetails.AsEnumerable().ToList();
                List <DataRow> list = new List <DataRow>(dtSummary.Select());

                PdfPageSettings pageSettings = new PdfPageSettings(50f);
                pageSettings.Margins.Left = 15;

                pageSettings.Margins.Right = 15;

                pageSettings.Margins.Top = 10;

                pageSettings.Margins.Bottom = 10;

                PdfDocument pdfDocument = exp.Export(Grid1.Model, (IEnumerable)list, "FindDocumentStatus.pdf", true, true, "flat-lime", true);

                RectangleF rect  = new RectangleF(0, 0, pdfDocument.PageSettings.Width, 50);
                RectangleF rect1 = new RectangleF(0, 0, pdfDocument.PageSettings.Width, 50);

                //create a header pager template
                PdfPageTemplateElement header  = new PdfPageTemplateElement(rect);
                PdfPageTemplateElement header1 = new PdfPageTemplateElement(rect1);

                //create a footer pager template
                PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);

                Font f = new Font("Arial", 11, FontStyle.Bold);

                PdfFont font = new PdfTrueTypeFont(f, true);

                //header.Graphics.DrawString("Land Aquisition", font, PdfBrushes.Black, new Point(250, 0)); //Add custom text to the Header
                //pdfDocument.Template.Top = header; //Append custom template to the document

                //header1.Graphics.DrawString("All Family Details", font, PdfBrushes.Black, new Point(0, 3)); //Add custom text to the Header
                //pdfDocument.Template.Top = header1; //Append custom template to the document
                PdfBrush brush = new PdfSolidBrush(Color.Black);
                //Add the fields in composite fields
                PdfCompositeField compositeField  = new PdfCompositeField(font, brush, "Land Aquisition - SEZ Thane");
                PdfCompositeField compositeField1 = new PdfCompositeField(font, brush, "Find Document Status");
                //PdfCompositeField compositeField2 = new PdfCompositeField(font, brush, "Report");
                //PdfCompositeField compositeField3 = new PdfCompositeField(font, brush, "Family Details");
                compositeField.Bounds = header.Bounds;
                //Draw the composite field in footer
                compositeField.Draw(footer.Graphics, new PointF(200, 0));
                compositeField1.Draw(footer.Graphics, new PointF(230, 10));
                //compositeField2.Draw(footer.Graphics, new PointF(205, 20));
                //compositeField3.Draw(footer.Graphics, new PointF(228, 40));
                //Add the footer template at the bottom
                pdfDocument.Template.Top = header;

                footer.Graphics.DrawString("CopyRights", font, PdfBrushes.Gray, new Point(250, 0)); //Add Custom text to footer
                pdfDocument.Template.Bottom = footer;                                               //Add the footer template to document

                pdfDocument.Save("FindDocumentStatus.pdf", Response, HttpReadType.Save);
            }
            else
            {
            }
        }
예제 #34
0
        private void RotateText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            float x = page.Canvas.ClientSize.Width / 2;
            float y = 380;

            page.Canvas.TranslateTransform(x, y);
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.RotateTransform(30);
                page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment);
            }

            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #35
0
        private void DrawCover(PdfSection section, PdfMargins margin)
        {
            section.PageNumber = new PdfPageNumber();
            section.PageNumber.NumberStyle = PdfNumberStyle.LowerRoman;
            section.PageNumber.Prefix = "cover ";
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins.All = 0;
            PdfPageBase page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, true);

            //refenrence content
            PdfBrush brush1 = PdfBrushes.LightGray;
            PdfBrush brush2 = PdfBrushes.Blue;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f));
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            String text1 = "(All text and picture from ";
            String text2 = "Wikipedia";
            String text3 = ", the free encyclopedia)";
            float x = 0, y = 10;
            x = x + margin.Left;
            y = y + margin.Top;
            page.Canvas.DrawString(text1, font1, brush1, x, y, format);
            x = x + font1.MeasureString(text1, format).Width;
            page.Canvas.DrawString(text2, font1, brush2, x, y, format);
            x = x + font1.MeasureString(text2, format).Width;
            page.Canvas.DrawString(text3, font1, brush1, x, y, format);

            //cover
            PdfBrush brush3 = PdfBrushes.Black;
            PdfBrush brush4 = new PdfSolidBrush(new PdfRGBColor(0xf9, 0xf9, 0xf9));
            PdfImage image
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            String text = Pagination.Properties.Resources.ImageDescription;
            float r = image.PhysicalDimension.Height / image.Height;
            PdfPen pen = new PdfPen(brush1, r);
            SizeF size = font1.MeasureString(text, image.PhysicalDimension.Width - 2);
            PdfTemplate template
                = new PdfTemplate(image.PhysicalDimension.Width + 4 * r + 4,
                    image.PhysicalDimension.Height + 4 * r + 7 + size.Height);
            template.Graphics.DrawRectangle(pen, brush4, 0, 0, template.Width, template.Height);
            x = y = r + 2;
            template.Graphics.DrawRectangle(brush1, x, y,
                image.PhysicalDimension.Width + 2 * r,
                image.PhysicalDimension.Height + 2 * r);
            x = y = x + r;
            template.Graphics.DrawImage(image, x, y);

            x = x - 1;
            y = y + image.PhysicalDimension.Height + r + 2;
            template.Graphics.DrawString(text, font1, brush3,
                new RectangleF(new PointF(x, y), size));

            float x1 = (page.Canvas.ClientSize.Width - template.Width) / 2;
            float y1 = (page.Canvas.ClientSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f) - template.Height / 2 + margin.Top;
            template.Draw(page.Canvas, x1, y1);

            //title
            format.Alignment = PdfTextAlignment.Center;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 24f, FontStyle.Bold));
            x = page.Canvas.ClientSize.Width / 2;
            y = y1 + template.Height + 10;
            page.Canvas.DrawString(Pagination.Properties.Resources.Title, font2, brush3, x, y, format);
        }
예제 #36
0
        private void TekenHelePyramideOpPapier(PdfPageBase page, int[,] pyramide, int basislengte, int papierhoogte)
        {
            PdfSolidBrush blackBrush = new PdfSolidBrush(Color.Black);
            PdfFont helv = new PdfFont(PdfFontFamily.Helvetica, 15f);
            Random rnd = new Random();
            int xOffset = 50;
            // draw the rectangles
            for (int rij = 0; rij <= basislengte - 1; rij++)
            {
                for (int aantal = 0; aantal <= (basislengte - 1 - rij); aantal++)
                {
                    int x = aantal * 50 + 25 * rij+xOffset;
                    int y = papierhoogte - rij * 25;
                    int rechthook = 50;

                    RectangleF rectangleFLine = new RectangleF(x - 6, y - 6, rechthook + 3, 25);
                    page.Canvas.DrawRectangle(blackBrush, rectangleFLine);

                    RectangleF rectangleF = new RectangleF(x - 4, y - 4, rechthook - 1, 22);
                    PdfLinearGradientBrush gradBrush = new PdfLinearGradientBrush(rectangleF, new PdfRGBColor(200, 200, 200), new PdfRGBColor(200, 200, 200), PdfLinearGradientMode.Horizontal);
                    page.Canvas.DrawRectangle(gradBrush, rectangleF);

                }
            }

            // draw all the numbers on the paper
            for (int rij = 0; rij <= basislengte - 1; rij++)
            {
                for (int aantal = 0; aantal <= (basislengte - rij - 1); aantal++)
                {
                    Console.Write(pyramide[rij, aantal].ToString() + " ");
                    int x = aantal * 50 + 25 * rij + 5 +xOffset;
                    int y = papierhoogte - rij * 25;

                    if (DezeCelTekenen(basislengte, rnd, rij, aantal))
                    {
                        page.Canvas.DrawString(pyramide[rij, aantal].ToString(),
                            helv,
                            blackBrush, x,
                            y);
                    }

                }
                Console.WriteLine();

            }
        }
예제 #37
0
        private void DrawBorder(PdfGraphics g, PdfObject obj)
        {
            if (obj.Border == null)
            {
                return;
            }

            // Store the needed properties in local variables for easy access
            var topThickness    = obj.Border.Top;
            var rightThickness  = obj.Border.Right;
            var bottomThickness = obj.Border.Bottom;
            var leftThickness   = obj.Border.Left;
            var x      = obj.Layout.X;
            var y      = obj.Layout.Y;
            var height = obj.Layout.Height;
            var width  = obj.Layout.Width;

            // Create a brush with the right color
            PdfBrush fill = new PdfSolidBrush(new PdfColor(GetColor(obj.Border.Color)));

            /**
            ** The following four if statements work with the following logic:
            ** If the border has a size, figure out the size it should be
            ** The size includes the size of neighboring border. Such that,
            ** if there is a top and right border, the top's width will be
            ** extended so that it goes all the way to the right of the right
            ** border, and the right's height and y position will be adjusted
            ** so that the right border will go to the top of the top border.
            ** This is a little redundant, But it keeps all the logic the same.
            ** Might change it someday.
            ** Then a rectangle is drawn to represent the border
            */

            if (topThickness > 0)
            {
                var bY = (float)(y - topThickness);
                var bX = (float)(x - leftThickness);
                var bW = (float)(width + leftThickness + rightThickness);

                g.DrawRectangle(fill, bX, bY, bW, (float)topThickness);
            }

            if (rightThickness > 0)
            {
                var bX = (float)(x + width);
                var bY = (float)(y - topThickness);
                var bH = (float)(height + topThickness + bottomThickness);

                g.DrawRectangle(fill, bX, bY, (float)rightThickness, bH);
            }

            if (bottomThickness > 0)
            {
                var bY = (float)(y + height);
                var bX = (float)(x - leftThickness);
                var bW = (float)(width + leftThickness + rightThickness);

                g.DrawRectangle(fill, bX, bY, bW, (float)bottomThickness);
            }

            if (leftThickness > 0)
            {
                var bX = (float)(x - leftThickness);
                var bY = (float)(y - topThickness);
                var bH = (float)(height + topThickness + bottomThickness);

                g.DrawRectangle(fill, bX, bY, (float)leftThickness, bH);
            }
        }
예제 #38
0
        private void DrawPage(PdfPageBase page)
        {
            float pageWidth = page.Canvas.ClientSize.Width;
            float y = 0;

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

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

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

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

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

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

            //content
            PdfStringFormat format4 = new PdfStringFormat();
            text = System.IO.File.ReadAllText(@"..\..\..\..\..\..\Data\Summary_of_Science.txt");
            PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f));
            format4.LineSpacing = font5.Size * 1.5f;
            PdfStringLayouter textLayouter = new PdfStringLayouter();
            float imageLeftBlockHeight = imageBottom - y;
            PdfStringLayoutResult result
                = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            if (result.ActualSize.Height < imageBottom - y)
            {
                imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight;
                result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            }
            foreach (LineInfo line in result.Lines)
            {
                page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4);
                y = y + result.LineHeight;
            }
            PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2);
            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
            textWidget.StringFormat = format4;
            textWidget.Draw(page, bounds, textLayout);
        }
예제 #39
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ofdSingleFile.SafeFileName))
            {
                MessageBox.Show("Please select a pdf file");
                return;
            }
            btnRun.Enabled = false;

            Task.Factory.StartNew(() =>
            {
                var filePath = ofdSingleFile.FileName;
                var helper = new PdfHelper();
                var pdf = new PdfDocument(filePath);
                var pdfTemp = new PdfDocument();
                var docWillSave = new PdfDocument();
                var totalPage = pdf.Pages.Count;
                pbSplitProgress.Maximum = totalPage;
                var curPage = 0;
                foreach (PdfPageBase itemPage in pdf.Pages)
                {
                    curPage++;
                    #region Lable one
                    var pageOrigin = itemPage;
                    var template = pageOrigin.CreateTemplate();
                    var pageTemp = pdfTemp.Pages.Add(PdfHelper.SizeF4x6, new PdfMargins(0));
                    pageTemp.Canvas.DrawTemplate(template, new PointF(38, 9));
                    var templateNew = pageTemp.CreateTemplate();
                    var page = docWillSave.Pages.Add(PdfHelper.SizeF4x6, new PdfMargins(0));
                    page.Canvas.DrawTemplate(templateNew, new PointF(-40, -9));

                    PdfGraphicsState state = page.Canvas.Save();
                    PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
                    PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
                    page.Canvas.RotateTransform(-90);
                    page.Canvas.DrawString(txtText.Text, font, brush, new PointF(-250, 25), leftAlignment);
                    //  page.Canvas.Restore(state);

                    pdfTemp.Pages.RemoveAt(0);
                    #endregion

                    #region Lable two
                    var ListImage = itemPage.ExtractImages();
                    #region Second Page
                    PdfPageBase page2 = docWillSave.Pages.Add(new SizeF(288, 432), new PdfMargins(0));
                    ListImage[1].RotateFlip(RotateFlipType.Rotate90FlipNone);

                    #region cut image
                    System.Drawing.Rectangle cropArea = new System.Drawing.Rectangle(0, 0, 800, 1204);
                    var img = ListImage[1];
                    System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(img);
                    System.Drawing.Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
                    #endregion
                    PdfImage image = PdfImage.FromImage(bmpCrop);
                    page2.Canvas.DrawImage(image, 0, 0, page2.Canvas.ClientSize.Width, page2.Canvas.ClientSize.Height);
                    #endregion
                    #endregion
                    pbSplitProgress.Value = curPage ;
                }

                var newFile = filePath.Remove(filePath.LastIndexOf('.'), 4) + "_cut" + DateTime.Now.ToFileTime() + ".pdf";
                docWillSave.SaveToFile(newFile);
                docWillSave.Close();
                lblMsg.Text = "File has been save as " + newFile;
                System.Diagnostics.Process.Start(newFile);
            });
        }
        public ActionResult MultiColumnHTML(string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

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

            doc.PageSettings.Size = new SizeF(870, 732);

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


            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfPen        pen   = new PdfPen(Color.Black, 1f);

            //Create font
            PdfStandardFont font       = new PdfStandardFont(PdfFontFamily.Helvetica, 11.5f);
            FileStream      fontstream = new FileStream(dataPath + "Calibri.ttf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfTrueTypeFont heading    = new PdfTrueTypeFont(fontstream, 14f, PdfFontStyle.Bold);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 8.5f);

            //Adding Header
            this.AddMulticolumnHeader(doc, "Syncfusion Essential PDF", "MultiColumnText Demo");

            //Adding Footer
            this.AddFooter(doc, "@Copyright 2015");

            #region htmlText

            string longtext = "<font color='#FF0000F'><b>PDF</b></font> stands for <i>\"Portable Document Format\"</i>." +
                              " The key word is <i>portable</i>, intended to combine the qualities of <u>authenticity," +
                              " reliability and ease of use together into a single packaged concept</u>.<br/><br/>" +
                              "Adobe Systems invented PDF technology in the early 1990s to smooth the " +
                              "process of moving text and graphics from publishers to printing-presses." +
                              " <font color='#FF0000F'><b>PDF</b></font> turned out to be the very essence of paper, brought to life in a computer." +
                              " In creating PDF, Adobe had almost unwittingly invented nothing less than a " +
                              "bridge between the paper and computer worlds. <br/><br/>To be truly portable, an authentic electronic " +
                              "document would have to appear exactly the same way on any computer at any time," +
                              " at no cost to the user. It will deliver the exact same results in print or on-screen " +
                              "with near-total reliability. ";
            #endregion


            //Rendering HtmlText
            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(longtext, font, brush);

            // Formatting Layout
            PdfLayoutFormat format = new PdfLayoutFormat();
            format.Layout = PdfLayoutType.OnePage;

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(0, 15, 190, page.GetClientSize().Height), format);

            FileStream imageStream = new FileStream(dataPath + "PDFImage.png", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ////Drawing Image
            PdfBitmap image = new PdfBitmap(imageStream);
            page.Graphics.DrawImage(image, new PointF(50, 295));

            #region HtmlText
            longtext = "<font color='#FF0000F'><b>PDF</b></font> is used for representing two-dimensional documents in " +
                       "a manner independent of the application software, hardware, and operating system.<sup>[1]</sup>" +
                       "<br/><br/>Each PDF file encapsulates a complete description of a fixed-layout 2-D document " +
                       "(and, with Acrobat 3-D, embedded 3-D documents) that includes the text, fonts, images, " +
                       "and 2-D vector graphics which comprise the documents." +
                       " <br/><br/><b>PDF</b> is an open standard that was officially published on July 1, 2008 by the ISO as" +
                       "ISO 32000-1:2008.<sub>[2]</sub><br/><br/>" +
                       "The PDF combines the technologies such as A sub-set of the PostScript page description programming " +
                       "language, a font-embedding/replacement system to allow fonts to travel with the documents and a " +
                       "structured storage system to bundle these elements and any associated content into a single file," +
                       "with data compression where appropriate.";
            #endregion

            richTextElement = new PdfHTMLTextElement(longtext, font, brush);

            richTextElement.Draw(page, new RectangleF(0, 375, 190, page.GetClientSize().Height), format);

            #region HtmlText
            ////HtmlString
            string longText = "<font color='#0000F8'>Essential PDF</font> is a <u><i>.NET</i></u> " +
                              "library with the capability to produce Adobe PDF files " +
                              "It features a full-fledged object model for the easy creation of PDF files from any .NET language. " +
                              " It does not use any external libraries and is built from scratch in C#. ";
            #endregion


            ////Rendering HtmlText
            richTextElement = new PdfHTMLTextElement(longText, font, brush);


            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(195, 15, 225, page.GetClientSize().Height), format);
            FileStream gifStream = new FileStream(dataPath + "Essen PDF.gif", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ////Drawing Image
            PdfImage image1 = new PdfTiffImage(gifStream);
            page.Graphics.DrawImage(image1, new PointF(225, 100));

            #region HtmlText
            string htmlText = "Essential PDF supports many features for creating a PDF document including <b>" +
                              "drawing text, images, tables and other shapes</b>. " +
                              "<br/><br/><font face='TimesRoman'>The generated PDF document can also be protected using <I>" +
                              "40 Bit and 128 Bit encryption.</I></font><br/>" +
                              "<p>Essential PDF is compatible with Microsoft Visual Studio .NET 2005 and 2008. " +
                              "It is also compatible with the Express editions of Visual Studio.NET. <br/><br/>" +
                              "The Essential PDF library can be used in any .NET environment including C#, VB.NET and managed C++.</p>" +
                              "The PDF file that is created using Essential PDF can be viewed using Adobe Acrobat or the free " +
                              "version of <u> Acrobat Viewer from Adobe only.</u>" +
                              "<font color='#0000F8'><b><br/><br/>Essential PDF</b></font> It can be used on the server " +
                              "side (ASP.NET or any other environment) or with Windows Forms applications. " +
                              "The library is 100% managed, being written in C#.<br/><br/> " +
                              "<font color='#FF0000F'>PdfDocument</font> is a top-level object in Essential PDF which implies a " +
                              "representation of a PDF document. <br/><br/> " +
                              "The document contains a collection of sections that are represented by the <font color='#FF0000F'>PdfSection</font> class, " +
                              "which is a logical entity containing a collection of pages and their settings. <br/><br/> Pages (which are represented by <font color='#FF0000F'>PdfPage</font> class) " +
                              "are the main destinations of the graphics output.<br/><br/>" +
                              "A document can be saved through its <font color='#0000F8'>Save()</font> method. It can be saved either to a file or stream.<br/><br/>" +
                              "In order to use the Essential PDF library in your project, add the PdfConfig component found in the toolbox to a project to enable support for PDF. ";

            #endregion

            //Rendering HtmlText
            PdfHTMLTextElement richTextElement1 = new PdfHTMLTextElement(htmlText, font, brush);


            //Drawing htmlString
            richTextElement1.Draw(page, new RectangleF(195, 200, 225, page.GetClientSize().Height), format);


            #region HtmlText
            htmlText = "<p>Every Syncfusion license includes a <i>one-year subscription</i> for unlimited technical support and new releases." +
                       "Syncfusion licenses each product on a simple per-developer basis and charges no royalties," +
                       "runtimes, or server deployment fees. A licensee can install his/her " +
                       "license on multiple personal machines at <u>no extra charge.</u></p>"
                       + "<p> At Syncfusion we are very excited about the Microsoft .NET platform.<br/><br/> " +
                       "We believe that one of the key benefits of <font color='#0000F8'>.NET</font> is improved programmer productivity. " +
                       "Solutions that used to take a very long time with traditional tools can now be " +
                       "implemented in a much shorter time period with the <font color='#0000F8'>.NET</font> platform.</p>" +
                       "Essential Studio includes seven component libraries in one great package." +
                       "Essential Studio is available with full source code. It incorporates a " +
                       "unique debugging support system that allows switching between 'Debug' and " +
                       "\'Release\' versions of our library with a single click from inside the Visual" +
                       "Studio.NET IDE. <br/><br/> <p> To ensure the highest quality of support possible," +
                       "we use a state of the art <font color='#0000F8'>Customer Relationship Management software (CRM)</font> " +
                       "based Developer Support System called Direct-Trac. Syncfusion Direc-Trac is a " +
                       "support system that is uniquely tailored for developer needs. Support incidents " +
                       "can be created and tracked to completion 24 hours a day, 7 days a week.</p><br/><br/> " +
                       "We have a simple, royalty-free licensing model. Components are licensed to a single user." +
                       " We recognize that you often work at home or on your laptop in addition to your work machine." +
                       "Therefore, our license permits our products to be installed in more than one location." +
                       " At Syncfusion, we stand behind our products 100%. <br/><br/>We have top notch management" +
                       ", architects, product managers, sales people, support personnel, and developers " +
                       "all working with you, the customer, as their focal point.";
            #endregion


            richTextElement = new PdfHTMLTextElement(htmlText, font, brush);

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(425, 15, 225, page.GetClientSize().Height), format);

            #region HtmlText
            htmlText = "Each licensed control would need to have an entry in the licx file. This would mean that if you were using 20 licensed controls, you would have 20 different entries complete with a full version number in your licx file." +
                       "<br/><br/> This posed major problems when upgrading to a newer version since these entries would need to have their version numbers changed. This also made trouble shooting licensing issues very difficult. ";
            #endregion


            richTextElement = new PdfHTMLTextElement(htmlText, font, brush);

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(425, 500, 225, page.GetClientSize().Height), format);
            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            doc.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
            fileStreamResult.FileDownloadName = "MultiColumnHtmlText.pdf";
            return(fileStreamResult);
        }
예제 #41
0
        public void GeneratePdf()
        {
            decimal     totale = 0;
            PdfDocument doc    = new PdfDocument();
            PdfPageBase page   = doc.Pages.Add(PdfPageSize.A6);
            PdfPageBase page2  = null;
            PdfPageBase page3  = null;
            PdfPageBase page4  = null;

            PdfPageBase[] pages = { page, page2, page3, page4 };

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - alignment
            PdfFont       font  = new PdfFont(PdfFontFamily.Courier, 6f);
            PdfFont       font2 = new PdfFont(PdfFontFamily.Courier, 4f);
            PdfFont       font3 = new PdfFont(PdfFontFamily.Courier, 4f, PdfFontStyle.Strikeout);
            PdfSolidBrush brush = new PdfSolidBrush(System.Drawing.Color.Black);

            PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);

            page.Canvas.DrawString(DateTime.Now.ToString(), font, brush, 0, 40, leftAlignment);

            PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            page.Canvas.DrawString(Receipe.Name,
                                   font, brush, page.Canvas.ClientSize.Width / 2, 20, centerAlignment);
            PdfStringFormat centerAlignment2
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            page.Canvas.DrawString(Receipe.Address,
                                   font, brush, page.Canvas.ClientSize.Width / 2, 30, centerAlignment2);
            PdfStringFormat centerAlignment3
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            page.Canvas.DrawString("PODSUMOWANIE DNIA",
                                   font, brush, page.Canvas.ClientSize.Width / 2, 50, centerAlignment3);

            PdfPath path = new PdfPath();

            path.AddLine(new PointF(10, 55), new PointF(page.Canvas.ClientSize.Width - 10, 55));

            PdfPen pen = new PdfPen(System.Drawing.Color.Black, 0.8f);

            page.Canvas.DrawPath(pen, path);

            float pageoneh   = 60;
            float pagetwoh   = 20;
            float pagethreeh = 20;
            float pagefourh  = 20;

            //_recp.listOfBoughtProducts.RemoveRange(24, _recp.listOfBoughtProducts.Count-24);
            foreach (var x in _listOfObjects)
            {
                if (x.Name != null)
                {
                    totale += x.TotalPrice;
                    string ilosc = "Ilosc sprzedanych: " + x.Sum.ToString();
                    string cena  = "Suma cenowa: " + x.TotalPrice.ToString();
                    string nazwa = x.Name.Substring(0, x.Name.Length > 45 ? 45 : x.Name.Length) + " " + ilosc;

                    if (pageoneh < 310)
                    {
                        page.Canvas.DrawString(nazwa, font2, brush, 0, pageoneh, leftAlignment);
                        page.Canvas.DrawString(cena, font2, brush, page.Canvas.ClientSize.Width, pageoneh,
                                               rightAlignment);
                        pageoneh += 10;
                    }
                    if (pageoneh == 310)
                    {
                        if (page2 == null)
                        {
                            page2 = doc.Pages.Add(PdfPageSize.A6);
                        }
                    }
                    if (pageoneh == 310 && pagetwoh < 310)
                    {
                        page2.Canvas.DrawString(nazwa, font2, brush, 0, pagetwoh, leftAlignment);
                        page2.Canvas.DrawString(cena, font2, brush, page.Canvas.ClientSize.Width, pagetwoh,
                                                rightAlignment);
                        pagetwoh += 10;
                    }
                    if (pagetwoh == 310)
                    {
                        if (page3 == null)
                        {
                            page3 = doc.Pages.Add(PdfPageSize.A6);
                        }
                    }
                    if (pagetwoh == 310 && pagethreeh < 310)
                    {
                        page3.Canvas.DrawString(nazwa, font2, brush, 0, pagethreeh, leftAlignment);
                        page3.Canvas.DrawString(cena, font2, brush, page.Canvas.ClientSize.Width, pagethreeh,
                                                rightAlignment);
                        pagethreeh += 10;
                    }
                    if (pagethreeh == 310)
                    {
                        if (page4 == null)
                        {
                            page4 = doc.Pages.Add(PdfPageSize.A6);
                        }
                    }
                    if (pagethreeh == 310 && pagefourh < 310)
                    {
                        page4.Canvas.DrawString(nazwa, font2, brush, 0, pagefourh, leftAlignment);
                        page4.Canvas.DrawString(cena, font2, brush, page.Canvas.ClientSize.Width, pagefourh,
                                                rightAlignment);
                        pagefourh += 10;
                    }
                }
            }

            PdfPath path2 = null;
            PdfPen  pen2  = null;

            if (page4 != null)
            {
                path2 = new PdfPath();

                path2.AddLine(new PointF(10, pagefourh + 5),
                              new PointF(page.Canvas.ClientSize.Width - 10, pagefourh + 5));

                pen2 = new PdfPen(System.Drawing.Color.Black, 0.8f);
                page4.Canvas.DrawPath(pen2, path2);

                page4.Canvas.DrawString("UTARG PLN DNIOWY: " + totale, font2, brush, page.Canvas.ClientSize.Width,
                                        pagefourh + 10, rightAlignment);
            }
            else if (page4 == null && page3 != null)
            {
                path2 = new PdfPath();

                path2.AddLine(new PointF(10, pagethreeh + 5),
                              new PointF(page.Canvas.ClientSize.Width - 10, pagethreeh + 5));

                pen2 = new PdfPen(System.Drawing.Color.Black, 0.8f);
                page3.Canvas.DrawPath(pen2, path2);

                page3.Canvas.DrawString("UTARG PLN DNIOWY: " + totale, font2, brush, page.Canvas.ClientSize.Width,
                                        pagethreeh + 10, rightAlignment);
            }
            else if (page3 == null && page2 != null)
            {
                path2 = new PdfPath();

                path2.AddLine(new PointF(10, pagetwoh + 5),
                              new PointF(page.Canvas.ClientSize.Width - 10, pagetwoh + 5));

                pen2 = new PdfPen(System.Drawing.Color.Black, 0.8f);
                page2.Canvas.DrawPath(pen2, path2);

                page2.Canvas.DrawString("UTARG PLN DNIOWY: " + totale, font2, brush, page.Canvas.ClientSize.Width,
                                        pagetwoh + 10, rightAlignment);
            }
            else if (page2 == null && page != null)
            {
                path2 = new PdfPath();

                path2.AddLine(new PointF(10, pageoneh + 5),
                              new PointF(page.Canvas.ClientSize.Width - 10, pageoneh + 5));

                pen2 = new PdfPen(System.Drawing.Color.Black, 0.8f);
                page.Canvas.DrawPath(pen2, path2);

                page.Canvas.DrawString("UTARG PLN DNIOWY: " + totale, font2, brush, page.Canvas.ClientSize.Width,
                                       pageoneh + 10, rightAlignment);
            }
            //page.Canvas.DrawString("Left!", font, brush, 0, 60, leftAlignment);


            //restor graphics
            page.Canvas.Restore(state);
            //Save doc file.
            string fileName = "RaportDniowy.pdf";

            doc.SaveToFile(fileName);
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start(fileName);
        }
예제 #42
0
        private void DrawText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw text - brush
            String text = "Go! Turn Around! Go! Go! Go!";
            PdfPen pen = PdfPens.DeepSkyBlue;
            PdfSolidBrush brush = new PdfSolidBrush(Color.White);
            PdfStringFormat format = new PdfStringFormat();
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic);
            SizeF size = font.MeasureString(text, format);
            RectangleF rctg
                = new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180,
                size.Width / 3 * 2, size.Height * 2);
            page.Canvas.DrawString(text, font, pen, brush, rctg, format);

            //restor graphics
            page.Canvas.Restore(state);
        }
예제 #43
0
        public ActionResult InteractiveFeatures(string InsideBrowser)
        {
            #region Field Definitions
            document = new PdfDocument();
            document.PageSettings.Margins.All = 0;
            document.PageSettings.Size        = new SizeF(PdfPageSize.A4.Width, 600);
            interactivePage = document.Pages.Add();
            PdfGraphics g    = interactivePage.Graphics;
            RectangleF  rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100);

            PdfBrush whiteBrush  = new PdfSolidBrush(white);
            PdfPen   whitePen    = new PdfPen(white, 5);
            PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160));
            PdfFont  font        = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60);
            Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73);
            #endregion

            #region Header
            g.DrawRectangle(purpleBrush, rect);
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180);
            g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200));
            g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;
            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130));
            #endregion

            #region Body

            //Invoice Number
            Random invoiceNumber = new Random();
            g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210));
            g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210));

            //Current Date
            PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date");
            textBoxField.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
            textBoxField.Bounds        = new RectangleF(384, 204, 150, 30);
            textBoxField.ForeColor     = new PdfColor(maroonColor);
            textBoxField.ReadOnly      = true;
            document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); 
            var thisfieldis = this.getField('date');  
            
            var theday = util.printd('dddd',newdate); 
            var thedate = util.printd('d',newdate); 
            var themonth = util.printd('mmmm',newdate);
            var theyear = util.printd('yyyy',newdate);  
            
            thisfieldis.strokeColor=color.transparent;
            thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;");
            document.Form.Fields.Add(textBoxField);

            //invoice table
            PdfLightTable table = new PdfLightTable();
            table.Style.ShowHeader = true;
            g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140));

            //Header Style
            PdfCellStyle headerStyle = new PdfCellStyle();
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            headerStyle.TextBrush       = whiteBrush;
            headerStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor);
            headerStyle.BorderPen       = new PdfPen(whiteBrush, 0);
            table.Style.HeaderStyle     = headerStyle;

            //Cell Style
            PdfCellStyle bodyStyle = new PdfCellStyle();
            bodyStyle.Font           = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            bodyStyle.StringFormat   = new PdfStringFormat(PdfTextAlignment.Left);
            bodyStyle.BorderPen      = new PdfPen(whiteBrush, 0);
            table.Style.DefaultStyle = bodyStyle;
            table.DataSource         = GetProductReport(_hostingEnvironment.WebRootPath);
            table.Columns[0].Width   = 90;
            table.Columns[1].Width   = 160;
            table.Columns[3].Width   = 100;
            table.Columns[4].Width   = 65;
            table.Style.CellPadding  = 3;
            table.BeginCellLayout   += table_BeginCellLayout;

            PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140));

            g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom));
            CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, "");


            //Send to Server
            PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline");
            sendButton.Bounds      = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25);
            sendButton.BorderColor = white;
            sendButton.BackColor   = maroonColor;
            sendButton.ForeColor   = white;
            sendButton.Text        = "Order Online";
            PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php");
            submitAction.DataFormat    = SubmitDataFormat.Html;
            sendButton.Actions.MouseUp = submitAction;
            document.Form.Fields.Add(sendButton);

            //Order by Mail
            PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail");
            sendMail.Bounds      = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25);
            sendMail.Text        = "Order By Mail";
            sendMail.BorderColor = white;
            sendMail.BackColor   = maroonColor;
            sendMail.ForeColor   = white;

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "var aSubmitFields = [];"
                                                                     + "for( var i = 0 ; i < this.numFields; i++){"
                                                                     + "aSubmitFields[i] = this.getNthFieldName(i);"
                                                                     + "}"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}");

            sendMail.Actions.MouseUp = javaAction;
            document.Form.Fields.Add(sendMail);

            //Print
            PdfButtonField printButton = new PdfButtonField(interactivePage, "print");
            printButton.Bounds          = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25);
            printButton.BorderColor     = white;
            printButton.BackColor       = maroonColor;
            printButton.ForeColor       = white;
            printButton.Text            = "Print";
            printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); ");
            document.Form.Fields.Add(printButton);
            file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file);
            attachment.ModificationDate = DateTime.Now;
            attachment.Description      = "Specification";
            document.Attachments.Add(attachment);

            //Open Specification
            PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Open Specification";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });");
            document.Form.Fields.Add(openSpecificationButton);

            RectangleF     uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20);
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url   = "http://www.adventure-works.com";
            linkAnnot.Text  = "http://www.adventure-works.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location);
            #endregion

            #region Footer
            g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100));
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180);
            #endregion

            //Save 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;

            //Close the PDF document.
            document.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Interactive features.pdf";
            return(fileStreamResult);
        }
예제 #44
0
        public ActionResult CreateDocumentWithoutFilter()
        {
            PdfFont font    = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            PdfBrush    brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
            PdfDocument doc   = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            PdfGrid     pdfGrid  = new PdfGrid();

            //Load the image as stream.
            FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 200, 200);

            //Draw the image
            Syncfusion.Drawing.RectangleF bounds    = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement        header    = new PdfPageTemplateElement(bounds);
            PdfCompositeField             compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o referentnim tipovima");

            compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0));

            //Add the header at the top.

            doc.Template.Top = header;
            //Save the PDF document to stream
            //Create a Page template that can be used as footer.


            PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);



            //Create page number field.

            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field.

            PdfPageCountField count = new PdfPageCountField(font, brush);

            //Add the fields in composite fields.

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

            compositeField.Bounds = footer.Bounds;

            //Draw the composite field in footer.

            compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40));

            //Add the footer template at the bottom.

            doc.Template.Bottom = footer;

            MemoryStream  stream = new MemoryStream();
            List <object> data   = new List <object>();

            var oprema = _context.ReferentniTip
                         .AsNoTracking()
                         .OrderBy(o => o.Id)
                         .ToList();

            foreach (var komad in oprema)
            {
                var row = new
                {
                    Naziv = komad.Naziv,
                };
                data.Add(row);
            }



            //Add list to IEnumerable
            IEnumerable <object> dataTable = data;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50));
            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Referentni tipovi-Reports.pdf";

            return(File(stream, contentType, fileName));
        }