當前位置: 首頁>>代碼示例>>C#>>正文


C# Document.AddPage方法代碼示例

本文整理匯總了C#中System.Windows.Forms.Document.AddPage方法的典型用法代碼示例。如果您正苦於以下問題:C# Document.AddPage方法的具體用法?C# Document.AddPage怎麽用?C# Document.AddPage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.Document的用法示例。


在下文中一共展示了Document.AddPage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: btnCreatePdf_Click

        private 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 logoImagePath = System.IO.Path.Combine(Application.StartupPath, @"..\..\img\evologo-250.png");
            string certificateFilePath = System.IO.Path.Combine(Application.StartupPath, @"..\..\certificates\evopdf.pfx");

            PdfFont pdfFont = document.Fonts.Add(new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point));
            TextElement descriptionTextElement = new TextElement(0, 0,
                "A digital signature was applied on the logo image below. Click on the image to see the signature details", pdfFont);
            AddElementResult addResult = firstPage.AddElement(descriptionTextElement);

            // create the area where the digital signature will be displayed in the PDF document
            // in this sample the area is a logo image but it could be anything else
            ImageElement logoElement = new ImageElement(0, addResult.EndPageBounds.Bottom + 10, 100, logoImagePath);
            addResult = firstPage.AddElement(logoElement);

            //get the #PKCS 12 certificate from file
            DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf");
            DigitalCertificate certificate = certificates[0];

            // create the digital signature over the logo image element
            DigitalSignatureElement signature = new DigitalSignatureElement(addResult.EndPageBounds, certificate);
            signature.Reason = "Protect the document from unwanted changes";
            signature.ContactInfo = "The contact email is [email protected]";
            signature.Location = "Development server";
            firstPage.AddElement(signature);

            string outFilePath = System.IO.Path.Combine(Application.StartupPath, "DigitalSignature.pdf");

            // save the PDF document to disk
            document.Save(outFilePath);

            // close the PDF document to release the resources
            document.Close();

            DialogResult dr = MessageBox.Show("Open the saved file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                try
                {
                    System.Diagnostics.Process.Start(outFilePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
開發者ID:ParallaxIT,項目名稱:tdb-ws,代碼行數:57,代碼來源:DigitalSignature.cs

示例2: btnCreatePdf_Click

        private 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(Application.StartupPath, @"..\..\Img");

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

            string outFilePath = System.IO.Path.Combine(Application.StartupPath, "ImageElementDemo.pdf");

            // save the PDF document to disk
            document.Save(outFilePath);

            // close the PDF document to release the resources
            document.Close();

            DialogResult dr = MessageBox.Show("Open the saved file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                try
                {
                    System.Diagnostics.Process.Start(outFilePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
開發者ID:ParallaxIT,項目名稱:tdb-ws,代碼行數:53,代碼來源:ImageElementDemo.cs

示例3: btnCreatePdf_Click

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

            string outFilePath = System.IO.Path.Combine(Application.StartupPath, "ShapesDemo.pdf");

            // save the PDF document to disk
            document.Save(outFilePath);

            // close the PDF document to release the resources
            document.Close();

            DialogResult dr = MessageBox.Show("Open the saved file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                try
                {
                    System.Diagnostics.Process.Start(outFilePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
開發者ID:ParallaxIT,項目名稱:tdb-ws,代碼行數:82,代碼來源:ShapesDemo.cs

示例4: btnCreatePdf_Click

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

            string outFilePath = System.IO.Path.Combine(Application.StartupPath, "TextsAndFontsDemo.pdf");
//.........這裏部分代碼省略.........
開發者ID:ParallaxIT,項目名稱:tdb-ws,代碼行數:101,代碼來源:TextAndFonts.cs


注:本文中的System.Windows.Forms.Document.AddPage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。