当前位置: 首页>>代码示例>>C#>>正文


C# Document.AddPage方法代码示例

本文整理汇总了C#中Document.AddPage方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AddPage方法的具体用法?C# Document.AddPage怎么用?C# Document.AddPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.AddPage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnCreatePDF_Click

        protected void btnCreatePDF_Click(object sender, EventArgs e)
        {
            // create a PDF document
            Document document = new Document();

            // set the license key
            document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE=";

            // add a page to the PDF document
            PdfPage firstPage = document.AddPage();

            string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), "Images");

            // display image in the available space in page and with a auto determined height to keep the aspect ratio
            ImageElement imageElement1 = new ImageElement(0, 0, System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            AddElementResult addResult = firstPage.AddElement(imageElement1);

            // display image with the specified width and the height auto determined to keep the aspect ratio
            // the images is displayed to the right of the previous image and the bounds of the image inside the current page
            // are taken from the AddElementResult object
            ImageElement imageElement2 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100,
                    System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            addResult = firstPage.AddElement(imageElement2);

            // Display image with the specified width and the specified height. It is possible for the image to not preserve the aspect ratio
            // The images is displayed to the right of the previous image and the bounds of the image inside the current page
            // are taken from the AddElementResult object
            ImageElement imageElement3 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100, 50,
                    System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            addResult = firstPage.AddElement(imageElement3);

            try
            {
                // get the PDF document bytes
                byte[] pdfBytes = document.Save();

                // send the generated PDF document to client browser

                // get the object representing the HTTP response to browser
                HttpResponse httpResponse = HttpContext.Current.Response;

                // add the Content-Type and Content-Disposition HTTP headers
                httpResponse.AddHeader("Content-Type", "application/pdf");
                httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=ImageElement.pdf; size={0}", pdfBytes.Length.ToString()));

                // write the PDF document bytes as attachment to HTTP response
                httpResponse.BinaryWrite(pdfBytes);

                // Note: it is important to end the response, otherwise the ASP.NET
                // web page will render its content to PDF document stream
                httpResponse.End();
            }
            finally
            {
                // close the PDF document to release the resources
                document.Close();
            }
        }
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:58,代码来源:ImageElementDemo.aspx.cs

示例2: btnCreatePDF_Click

        protected void btnCreatePDF_Click(object sender, EventArgs e)
        {
            // create a PDF document
            Document document = new Document();

            // set the license key
            document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE=";

            // add a page to the PDF document
            PdfPage firstPage = document.AddPage();

            // Create a Times New Roman .NET font of 10 points
            System.Drawing.Font ttfFont = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            // Create a Times New Roman Italic .NET font of 10 points
            System.Drawing.Font ttfFontItalic = new System.Drawing.Font("Times New Roman", 10,
                        System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
            // Create a Times New Roman Bold .NET font of 10 points
            System.Drawing.Font ttfFontBold = new System.Drawing.Font("Times New Roman", 10,
                        System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
            // Create a Times New Roman Bold .NET font of 10 points
            System.Drawing.Font ttfFontBoldItalic = new System.Drawing.Font("Times New Roman", 10,
                        System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);

            // Create a Sim Sun .NET font of 10 points
            System.Drawing.Font ttfCJKFont = new System.Drawing.Font("SimSun", 10,
                        System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            // Create the PDF fonts based on the .NET true type fonts
            PdfFont newTimesFont = document.AddFont(ttfFont);
            PdfFont newTimesFontItalic = document.AddFont(ttfFontItalic);
            PdfFont newTimesFontBold = document.AddFont(ttfFontBold);
            PdfFont newTimesFontBoldItalic = document.AddFont(ttfFontBoldItalic);

            // Create the embedded PDF fonts based on the .NET true type fonts
            PdfFont newTimesEmbeddedFont = document.AddFont(ttfFont, true);
            PdfFont newTimesItalicEmbeddedFont = document.AddFont(ttfFontItalic, true);
            PdfFont newTimesBoldEmbeddedFont = document.AddFont(ttfFontBold, true);
            PdfFont newTimesBoldItalicEmbeddedFont = document.AddFont(ttfFontBoldItalic, true);

            PdfFont cjkEmbeddedFont = document.AddFont(ttfCJKFont, true);

            // Create a standard Times New Roman Type 1 Font
            PdfFont stdTimesFont = document.AddFont(StdFontBaseFamily.TimesRoman);
            PdfFont stdTimesFontItalic = document.AddFont(StdFontBaseFamily.TimesItalic);
            PdfFont stdTimesFontBold = document.AddFont(StdFontBaseFamily.TimesBold);
            PdfFont stdTimesFontBoldItalic = document.AddFont(StdFontBaseFamily.TimesBoldItalic);

            // Create CJK standard Type 1 fonts
            PdfFont cjkJapaneseStandardFont = document.AddFont(StandardCJKFont.HeiseiKakuGothicW5);
            PdfFont cjkChineseTraditionalStandardFont = document.AddFont(StandardCJKFont.MonotypeHeiMedium);

            // Add text elements to the document

            TextElement trueTypeText = new TextElement(0, 10, "True Type Fonts Demo:", newTimesFontBold);
            AddElementResult addResult = firstPage.AddElement(trueTypeText);

            // Create the text element
            TextElement textElement1 = new TextElement(20, addResult.EndPageBounds.Bottom + 10, "Hello World !!!!", newTimesFont);
            // Add element to page. The result of adding the text element is stored into the addResult object
            // which can be used to get information about the rendered size in PDF page.
            addResult = firstPage.AddElement(textElement1);

            // Add another element 5 points below the text above. The bottom of the text above is taken from the AddElementResult object
            // set the font size
            newTimesFontItalic.Size = 15;
            TextElement textElement2 = new TextElement(20, addResult.EndPageBounds.Bottom + 5, "Hello World !!!!", newTimesFontItalic);
            textElement2.ForeColor = System.Drawing.Color.Green;
            addResult = firstPage.AddElement(textElement2);

            newTimesFontBoldItalic.Size = 20;
            TextElement textElement3 = new TextElement(20, addResult.EndPageBounds.Bottom + 5, "Hello World !!!!", newTimesFontBoldItalic);
            textElement3.ForeColor = System.Drawing.Color.Blue;
            addResult = firstPage.AddElement(textElement3);

            TextElement stdTypeText = new TextElement(0, addResult.EndPageBounds.Bottom + 10, "Standard PDF Fonts Demo:", newTimesFontBold);
            addResult = firstPage.AddElement(stdTypeText);

            TextElement textElement4 = new TextElement(20, addResult.EndPageBounds.Bottom + 10, "Hello World !!!!", stdTimesFont);
            addResult = firstPage.AddElement(textElement4);

            stdTimesFontItalic.Size = 15;
            TextElement textElement5 = new TextElement(20, addResult.EndPageBounds.Bottom + 5, "Hello World !!!!", stdTimesFontItalic);
            textElement5.ForeColor = System.Drawing.Color.Green;
            addResult = firstPage.AddElement(textElement5);

            stdTimesFontBoldItalic.Size = 20;
            TextElement textElement6 = new TextElement(20, addResult.EndPageBounds.Bottom + 5, "Hello World !!!!", stdTimesFontBoldItalic);
            textElement6.ForeColor = System.Drawing.Color.Blue;
            addResult = firstPage.AddElement(textElement6);

            // embedded true type fonts

            TextElement embeddedTtfText = new TextElement(0, addResult.EndPageBounds.Bottom + 10, "Embedded True Type Fonts Demo:", newTimesFontBold);
            addResult = firstPage.AddElement(embeddedTtfText);

            // russian text
            TextElement textElement8 = new TextElement(20, addResult.EndPageBounds.Bottom + 5, "Появление на свет!!", newTimesEmbeddedFont);
            addResult = firstPage.AddElement(textElement8);

            try
//.........这里部分代码省略.........
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:101,代码来源:TextAndFonts.aspx.cs

示例3: btnCreatePDF_Click

        protected void btnCreatePDF_Click(object sender, EventArgs e)
        {
            // create a PDF document
            Document document = new Document();

            // set the license key
            document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE=";

            // add a page to the PDF document
            PdfPage firstPage = document.AddPage();

            // draw rectangle
            RectangleElement rectangle1 = new RectangleElement(10, 10, 150, 100);
            rectangle1.ForeColor = System.Drawing.Color.Blue;
            rectangle1.LineStyle.LineWidth = 5; // a 5 points line width
            rectangle1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            firstPage.AddElement(rectangle1);

            // draw colored rectangle
            RectangleElement rectangle2 = new RectangleElement(200, 10, 150, 100);
            rectangle2.ForeColor = System.Drawing.Color.Blue;
            rectangle2.BackColor = System.Drawing.Color.Green;
            firstPage.AddElement(rectangle2);

            // draw gradient colored rectangle
            RectangleElement rectangle3 = new RectangleElement(400, 25, 100, 50);
            rectangle3.ForeColor = System.Drawing.Color.Blue;
            rectangle3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue);
            firstPage.AddElement(rectangle3);

            // draw ellipse
            EllipseElement ellipse1 = new EllipseElement(75, 200, 70, 50);
            ellipse1.ForeColor = System.Drawing.Color.Blue;
            ellipse1.LineStyle.LineDashStyle = LineDashStyle.Dash;
            firstPage.AddElement(ellipse1);

            // draw ellipse
            EllipseElement ellipse2 = new EllipseElement(275, 200, 70, 50);
            ellipse2.ForeColor = System.Drawing.Color.Blue;
            ellipse2.BackColor = System.Drawing.Color.Green;
            firstPage.AddElement(ellipse2);

            // draw ellipse
            EllipseElement ellipse3 = new EllipseElement(450, 200, 50, 25);
            ellipse3.ForeColor = System.Drawing.Color.Blue;
            ellipse3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue);
            firstPage.AddElement(ellipse3);

            BezierCurveElement bezierCurve1 = new BezierCurveElement(10, 350, 100, 300, 200, 400, 300, 350);
            bezierCurve1.ForeColor = System.Drawing.Color.Blue;
            bezierCurve1.LineStyle.LineWidth = 3;
            bezierCurve1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            firstPage.AddElement(bezierCurve1);

            BezierCurveElement bezierCurve2 = new BezierCurveElement(10, 350, 100, 400, 200, 300, 300, 350);
            bezierCurve2.ForeColor = System.Drawing.Color.Green;
            bezierCurve2.LineStyle.LineWidth = 3;
            bezierCurve2.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            firstPage.AddElement(bezierCurve2);

            try
            {
                // get the PDF document bytes
                byte[] pdfBytes = document.Save();

                // send the generated PDF document to client browser

                // get the object representing the HTTP response to browser
                HttpResponse httpResponse = HttpContext.Current.Response;

                // add the Content-Type and Content-Disposition HTTP headers
                httpResponse.AddHeader("Content-Type", "application/pdf");
                httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=Shapes.pdf; size={0}", pdfBytes.Length.ToString()));

                // write the PDF document bytes as attachment to HTTP response
                httpResponse.BinaryWrite(pdfBytes);

                // Note: it is important to end the response, otherwise the ASP.NET
                // web page will render its content to PDF document stream
                httpResponse.End();
            }
            finally
            {
                // close the PDF document to release the resources
                document.Close();
            }
        }
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:87,代码来源:PdfShapes.aspx.cs

示例4: AddWarningTitleToNewPDfPage

        /// <summary>
        /// Adds the warning title to new Pdf page.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="strText">The STR text.</param>
        internal void AddWarningTitleToNewPDfPage(Document docPDF, String strText)
        {
            pdfPage = docPDF.AddPage();

            /// Generate Text
            /// Create a Bold .NET font of 10 points
            System.Drawing.Font ttfFontBold = new System.Drawing.Font("Verdana", 12,
                        System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
            /// Create the PDF fonts based on the .NET true type fonts
            PdfFont newVerdanaFontBold = docPDF.AddFont(ttfFontBold);

            /// Add Title elements to the document
            TextElement WarningTitle = new TextElement(0, 200, strText, newVerdanaFontBold);
            WarningTitle.TextAlign = HorizontalTextAlign.Center;
            pdfPage.AddElement(WarningTitle);
        }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:21,代码来源:PDFHelper.cs

示例5: AddHTMLtoPDF

        /// <summary>
        /// Adds the HTM lto PDF.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="strBTOC">The STR BTOC.</param>
        internal void AddHTMLtoPDF(Document docPDF, String strBTOC, string strContext, bool blnIsTOC)
        {
            if (blnIsTOC)
            {
                strbaseURL = strContext;
                htmlToPdfElement = new HtmlToPdfElement(Convert.ToString(strBTOC), strbaseURL);

                pdfPage = docPDF.InsertPage(1, PageSize.A4, new Margins(40), PageOrientation.Portrait);
                //docPDF.AddPage(PageSize.A4, new Margins(10, 10, 0, 0), PageOrientation.Portrait);
                pdfPage.AddElement(htmlToPdfElement);
                docPDF.Pages.Add(pdfPage);
            }
            else
            {
                strbaseURL = strContext;
                htmlToPdfElement = new HtmlToPdfElement(Convert.ToString(strBTOC), strbaseURL);
                pdfPage = docPDF.AddPage(PageSize.A4, new Margins(40), PageOrientation.Portrait);
                pdfPage.AddElement(htmlToPdfElement);
                docPDF.Pages.Add(pdfPage);
            }
        }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:26,代码来源:PDFHelper.cs

示例6: AddFiletoPDFDoc

        /// <summary>
        /// Adds the file to PDF document.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="file">The file.</param>
        internal void AddFiletoPDFDoc(Document docPDF, SPFile file)
        {
            pdfHelper = new PDFHelper();
            if (file != null)
            {
                FileExtn = file.Name.Substring(file.Name.LastIndexOf(".") + 1).ToLowerInvariant();
                if (FileExtn.Equals("pdf"))
                {

                    Document newDoc = new Document(file.OpenBinaryStream());
                    docPDF.AppendDocument(newDoc);
                }
                else if (FileExtn.Equals("bmp") || FileExtn.Equals("gif") || FileExtn.Equals("jpg") ||
                         FileExtn.Equals("tif") || FileExtn.Equals("png") || FileExtn.Equals("jpeg") ||
                         FileExtn.Equals("tiff") || FileExtn.Equals("png"))
                {
                    PdfPage pagePDF = docPDF.AddPage();
                    Stream ImageStream = file.OpenBinaryStream();
                    System.Drawing.Image Image = System.Drawing.Image.FromStream(ImageStream);
                    /// Display image in the available space in page and with a auto determined height to keep the aspect ratio
                    ImageElement imageElement = new ImageElement(0, 0, Image);
                    pagePDF.AddElement(imageElement);
                }
                else
                {
                    pdfHelper.AddWarningTitleToNewPDfPage(docPDF, "File Type is not Supported");
                }
            }
            else
            {
                pdfHelper.AddWarningTitleToNewPDfPage(docPDF, "File Does not Exist");
            }
        }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:38,代码来源:PDFHelper.cs

示例7: AddChapterTitlePage

        /// <summary>
        /// Adds the chapter title page.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="ChapterTitle">The chapter title.</param>
        internal void AddChapterTitlePage(Document docPDF, String ChapterTitle)
        {
            pdfPage = docPDF.AddPage(new Margins(40));

            #region Chapter Title
            /// Generate Text
            /// Create a Times New Roman Bold .NET font of 10 points
            System.Drawing.Font ttfFontBold = new System.Drawing.Font("Verdana", 40,
                        System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
            /// Create the PDF fonts based on the .NET true type fonts
            PdfFont newVerdanaFontBold = docPDF.AddFont(ttfFontBold);

            /// Add Title elements to the document
            TextElement TypeTitle = new TextElement(3, 300, ChapterTitle, newVerdanaFontBold);
            TypeTitle.TextAlign = HorizontalTextAlign.Center;
            pdfPage.AddElement(TypeTitle);
            #endregion
        }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:23,代码来源:PDFHelper.cs


注:本文中的Document.AddPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。