处理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

白底图

白底图

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值