栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

处理Spire.Pdf 生成书签有 Evaluation Warning : The document was created with Spire.PDF for .NET.字样的问题

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

处理Spire.Pdf 生成书签有 Evaluation Warning : The document was created with Spire.PDF for .NET.字样的问题

处理spire.Pdf生成时的警告信息

这俩天在使用spire.Pdf生成书签的时候总是会有Evaluation Warning : The document was created with Spire.PDF for .NET.的警告字样,当时在网上也找了一些方法,例如:生成俩页再删掉第一页之类的,都没能很好的解决问题,遂换了一种思路,用一个白底的图片覆盖字样。

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Grid;
using System;
using System.Drawing;
using System.IO;
using Spire.Pdf.Annotations;
using Spire.Pdf.Annotations.Appearance;

namespace Server.Utils
{
    public class test
    {
        public void CreatePDF()
        {
            //创建一个PdfDocument类对象,并新添加一页到PDF文档
            PdfDocument doc = new PdfDocument();
            //添加一个空页
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4);

            //创建一个PdfGrid对象
            PdfGrid grid = new PdfGrid();

            #region 添加白底图片覆盖字样
            PdfRubberStampAnnotation logoStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(0, 0), new SizeF(350, 15)));
            PdfAppearance logoApprearance = new PdfAppearance(logoStamp);
            var logoPath = AppDomain.CurrentDomain.BaseDirectory + "white.jpg";

            PdfImage image = PdfImage.FromFile(logoPath);
            PdfTemplate template = new PdfTemplate(350, 15);
            template.Graphics.DrawImage(image, 0, 0);

            logoApprearance.Normal = template;
            logoStamp.Appearance = logoApprearance;
            page.AnnotationsWidget.Add(logoStamp);
            #endregion

            #region  添加标题
            //文本、字体、颜色
            string titleText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "测试PDF标题";
            PdfTrueTypeFont titleFont = new PdfTrueTypeFont(new Font("宋体", 15), true);
            PdfSolidBrush titleBrush = new PdfSolidBrush(Color.Black);

            page.Canvas.DrawString(titleText, titleFont, titleBrush, 150, 20);
            #endregion

            //保存到文档D:PDF文档
            var path = AppDomain.CurrentDomain.BaseDirectory + @"PDF";

            var dif = new DirectoryInfo(path);
            if (!dif.Exists)
                dif.Create();

            var name = "xxx" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
            string savePath = path + name;
            doc.SaveToFile(savePath);
        }
    }
}

附上效果图

PDF中添加文本信息
#region  添加标题
//文本、字体、颜色
string titleText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "测试PDF标题";
PdfTrueTypeFont titleFont = new PdfTrueTypeFont(new Font("宋体", 15), true);
PdfSolidBrush titleBrush = new PdfSolidBrush(Color.Black);
page.Canvas.DrawString(titleText, titleFont, titleBrush, 150, 20);
#endregion
白底图

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/909133.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号