我试图使用PdfSharp在pdf文件上添加水印,我尝试从这个链接中添加水印。
http://www.pdfsharp.net/wiki/Watermark-sample.ashx
但是无法获得如何获得现有的pdf文件页对象,以及如何在该页上水印。
帮助?
发布于 2017-08-23 07:11:59
基本上,样本只是片段。您可以下载源代码,并从中获得一堆示例,包括这个水印示例。
以下内容来自PDFSharp-MigraDocFoundation-1_32/PDFsharp/samples/Samples C#/Based on GDI+/Watermark/Program.cs
很简单,真的..。我只是将代码显示到遍历每一页的for循环。你应该看看完整的文件。
[...]
const string watermark = "PDFsharp";
const int emSize = 150;
// Get a fresh copy of the sample PDF file
const string filename = "Portable Document Format.pdf";
File.Copy(Path.Combine("../../../../../PDFs/", filename),
Path.Combine(Directory.GetCurrentDirectory(), filename), true);
// Create the font for drawing the watermark
XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);
// Open an existing document for editing and loop through its pages
PdfDocument document = PdfReader.Open(filename);
// Set version to PDF 1.4 (Acrobat 5) because we use transparency.
if (document.Version < 14)
document.Version = 14;
for (int idx = 0; idx < document.Pages.Count; idx++)
{
//if (idx == 1) break;
PdfPage page = document.Pages[idx];
[...]https://stackoverflow.com/questions/45832641
复制相似问题