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


C# Document.AddTemplate方法代码示例

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


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

示例1: WriteHtmlToPdf

        public static void WriteHtmlToPdf(string html, Stream outputStream)
        {
            LicensingManager.LicenseKey = LicenseKey;
            var document = new Document();

            document.CompressionLevel = CompressionLevel.NormalCompression;
            document.Margins = new Margins();
            document.Security.CanPrint = true;
            document.Security.UserPassword = "";

            document.DocumentInformation.Author = "MvcSolution";
            document.ViewerPreferences.HideToolbar = false;

            var page = document.Pages.AddNewPage(PageSize.A4, new Margins(25, 25, 25, 25), PageOrientation.Portrait);

            var smallfont = document.Fonts.Add(new Font(new FontFamily("Verdana"), 9, GraphicsUnit.Point));

            document.FooterTemplate = document.AddTemplate(document.Pages[0].ClientRectangle.Width, 60);

            document.FooterTemplate.AddElement(new TextElement(document.FooterTemplate.ClientRectangle.Width - 75, 40,
                 "Page &p; of &P;", smallfont));

            var htmlDoc = new HtmlToPdfElement(0, 0, -1, html, string.Empty, 700);

            htmlDoc.FitWidth = true;
            htmlDoc.EmbedFonts = true;
            htmlDoc.LiveUrlsEnabled = false;

            htmlDoc.ScriptsEnabled = false;
            htmlDoc.ActiveXEnabled = false;

            // add the HTML to PDF converter element to the page

            page.AddElement(htmlDoc);
            document.Save(outputStream);
        }
开发者ID:GitObjects,项目名称:mvcsolution,代码行数:36,代码来源:PdfHelper.cs

示例2: btnCreatePDF_Click

        protected void btnCreatePDF_Click(object sender, EventArgs e)
        {
            string pdfToModify = textBoxPdfFilePath.Text.Trim();

            // create a PDF document
            Document document = new Document(pdfToModify);

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

            // get the first page the PDF document
            PdfPage firstPage = document.Pages[0];

            string logoTransImagePath = System.IO.Path.Combine(Server.MapPath("~"), @"images\evologo-100-trans.png");
            string logoOpaqueImagePath = System.IO.Path.Combine(Server.MapPath("~"), @"images\evologo-100.jpg");

            // add an opaque image stamp in the top left corner of the first page
            // and make it semitransparent when rendered in PDF
            ImageElement imageStamp = new ImageElement(1, 1, logoOpaqueImagePath);
            imageStamp.Opacity = 50;
            AddElementResult addResult = firstPage.AddElement(imageStamp);

            // add a border for the image stamp
            RectangleElement imageBorderRectangleElement = new RectangleElement(1, 1, addResult.EndPageBounds.Width,
                                addResult.EndPageBounds.Height);
            firstPage.AddElement(imageBorderRectangleElement);

            // add a template stamp to the document repeated on each document page
            // the template contains an image and a text

            System.Drawing.Image logoImg = System.Drawing.Image.FromFile(logoTransImagePath);

            // calculate the template stamp location and size
            System.Drawing.SizeF imageSizePx = logoImg.PhysicalDimension;

            float imageWidthPoints = UnitsConverter.PixelsToPoints(imageSizePx.Width);
            float imageHeightPoints = UnitsConverter.PixelsToPoints(imageSizePx.Height);

            float templateStampXLocation = (firstPage.ClientRectangle.Width - imageWidthPoints) / 2;
            float templateStampYLocation = firstPage.ClientRectangle.Height / 4;

            // the stamp size is equal to image size in points
            Template templateStamp = document.AddTemplate(new System.Drawing.RectangleF(templateStampXLocation, templateStampYLocation,
                    imageWidthPoints, imageHeightPoints + 20));

            // set a semitransparent background color for template
            RectangleElement background = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width, templateStamp.ClientRectangle.Height);
            background.BackColor = Color.White;
            background.Opacity = 25;
            templateStamp.AddElement(background);

            // add a true type font to the document
            System.Drawing.Font ttfFontBoldItalic = new System.Drawing.Font("Times New Roman", 10,
                        System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
            PdfFont templateStampTextFont = document.AddFont(ttfFontBoldItalic, true);

            // Add a text element to the template. You can add any other types of elements to a template like a HtmlToPdfElement.
            TextElement templateStampTextElement = new TextElement(3, 0, "This is the Stamp Text", templateStampTextFont);
            templateStampTextElement.ForeColor = System.Drawing.Color.DarkBlue;
            templateStamp.AddElement(templateStampTextElement);

            // Add an image with transparency to the template. You can add any other types of elements to a template like a HtmlToPdfElement.
            ImageElement templateStampImageElement = new ImageElement(0, 20, logoImg);
            // instruct the library to use transparency information
            templateStampImageElement.RenderTransparentImage = true;
            templateStamp.AddElement(templateStampImageElement);

            // add a border to template
            RectangleElement templateStampRectangleElement = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width,
                        templateStamp.ClientRectangle.Height);
            templateStamp.AddElement(templateStampRectangleElement);

            // dispose the image
            logoImg.Dispose();

            // save the document on http response stream
            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=PdfStamps.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
            {
                document.Close();
//.........这里部分代码省略.........
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:101,代码来源:PdfStamps.aspx.cs

示例3: AddHtmlHeader

        private void AddHtmlHeader(Document document)
        {
            string thisPageURL = HttpContext.Current.Request.Url.AbsoluteUri;
            string headerAndFooterHtmlUrl = thisPageURL.Substring(0, thisPageURL.LastIndexOf('/')) + "/HeaderFooter/HeaderAndFooterHtml.htm";

            //create a template to be added in the header and footer
            document.Header = document.AddTemplate(document.Pages[0].ClientRectangle.Width, 60);
            // create a HTML to PDF converter element to be added to the header template
            HtmlToPdfElement headerHtmlToPdf = new HtmlToPdfElement(0, 0, document.Header.ClientRectangle.Width,
                    document.Header.ClientRectangle.Height, headerAndFooterHtmlUrl);
            headerHtmlToPdf.FitHeight = true;
            document.Header.AddElement(headerHtmlToPdf);
        }
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:13,代码来源:HtmlToPdfElementDemo.aspx.cs

示例4: AddHtmlFooter

        private void AddHtmlFooter(Document document, PdfFont footerPageNumberFont)
        {
            string thisPageURL = HttpContext.Current.Request.Url.AbsoluteUri;
            string headerAndFooterHtmlUrl = thisPageURL.Substring(0, thisPageURL.LastIndexOf('/')) + "/HeaderFooter/HeaderAndFooterHtml.htm";

            //create a template to be added in the header and footer
            document.Footer = document.AddTemplate(document.Pages[0].ClientRectangle.Width, 60);
            // create a HTML to PDF converter element to be added to the header template
            HtmlToPdfElement footerHtmlToPdf = new HtmlToPdfElement(0, 0, document.Footer.ClientRectangle.Width,
                    document.Footer.ClientRectangle.Height, headerAndFooterHtmlUrl);
            footerHtmlToPdf.FitHeight = true;
            document.Footer.AddElement(footerHtmlToPdf);

            // add page number to the footer
            TextElement pageNumberText = new TextElement(document.Footer.ClientRectangle.Width - 100, 30,
                                "This is page &p; of &P; pages", footerPageNumberFont);
            document.Footer.AddElement(pageNumberText);
        }
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:18,代码来源:HtmlToPdfElementDemo.aspx.cs

示例5: AddHtmlFooter

        private void AddHtmlFooter(Document document, PdfFont footerPageNumberFont)
        {
            string headerAndFooterHtmlUrl = @"HeaderAndFooterHtml.htm";

            //create a template to be added in the header and footer
            document.FooterTemplate = document.AddTemplate(document.Pages[0].ClientRectangle.Width, 100);
            // create a HTML to PDF converter element to be added to the header template
            HtmlToPdfElement footerHtmlToPdf = new HtmlToPdfElement(headerAndFooterHtmlUrl);
            document.FooterTemplate.AddElement(footerHtmlToPdf);

            // add page number to the footer
            TextElement pageNumberText = new TextElement(document.FooterTemplate.ClientRectangle.Width - 100, 30,
                                "This is page &p; of &P; pages", footerPageNumberFont);
            document.FooterTemplate.AddElement(pageNumberText);
        }
开发者ID:BlueSkyStatistics,项目名称:BlueSkyRepository,代码行数:15,代码来源:OutputSaveAsCommand.cs

示例6: AddHtmlHeader

        private void AddHtmlHeader(Document document)
        {
            string headerAndFooterHtmlUrl =  @"HeaderAndFooterHtml.htm";

            //create a template to be added in the header and footer
            document.HeaderTemplate = document.AddTemplate(document.Pages[0].ClientRectangle.Width, 100);
            // create a HTML to PDF converter element to be added to the header template
            HtmlToPdfElement headerHtmlToPdf = new HtmlToPdfElement(headerAndFooterHtmlUrl);
            document.HeaderTemplate.AddElement(headerHtmlToPdf);
        }
开发者ID:BlueSkyStatistics,项目名称:BlueSkyRepository,代码行数:10,代码来源:OutputSaveAsCommand.cs


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