Spire.PDF for.NET 去水印方法 及用法示例
阿里云优惠卷,戳我领取!
使用Spire.PDF for.NET的时候,会出现Evaluation Warning : The document was created with Spire.PDF for .NET. 水印。
如果需求是不到10页的pdf,可以使用官方免费版本,没有水印。
官方免费版本下载地址:
https://u20002878.pipipan.com/fs/20002878-372752254
另外附上这个dll的一些代码作为参考:
(以下代码参考自:https://www.cnblogs.com/Yesi/p/9844042.html 但稍作修改并非完全相同)
阿里云优惠卷,戳我领取!
using System;
using System.Drawing;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Annotations;
namespace GetPDF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CreatPDF(string url,string name)
{
float x = 50;
float y = 50;
string hang1 = "测试文字1";
string hang2 = "测试文字2";
string hang3 = "测试文字3";
PdfDocument pdf = new PdfDocument();//新建一个pdf
PdfPageBase page = pdf.Pages.Add();//新建pdf的一页
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial Unicode MS", 30f, FontStyle.Regular), true);//创建一个pdf的字体
page.Canvas.DrawString(hang1, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
page.Canvas.DrawString(hang2, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
page.Canvas.DrawString(hang3, font1, PdfBrushes.Black, new PointF(x, y)); y += 50;
// PdfStringFormat format = new PdfStringFormat();
// format.MeasureTrailingSpaces = true;
//// x += font1.MeasureString(str, format).Width;
//超链接
PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial Unicode MS", 30f, FontStyle.Underline), true);
PdfTextWebLink webLink = new PdfTextWebLink();
webLink.Url = url;
webLink.Text = url;
webLink.Font = font2;
webLink.Brush = PdfBrushes.Blue;
webLink.DrawTextWebLink(page.Canvas, new PointF(x, y));
pdf.SaveToFile(name + ".pdf");////创建pdf
}
private void button1_Click(object sender, EventArgs e)
{
CreatPDF(textBox2.Text, textBox1.Text);
}
}
}
阿里云优惠卷,戳我领取!