首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在现有pdf文件上添加水印

如何在现有pdf文件上添加水印
EN

Stack Overflow用户
提问于 2017-08-23 06:55:11
回答 1查看 1.9K关注 0票数 0

我试图使用PdfSharp在pdf文件上添加水印,我尝试从这个链接中添加水印。

http://www.pdfsharp.net/wiki/Watermark-sample.ashx

但是无法获得如何获得现有的pdf文件页对象,以及如何在该页上水印。

帮助?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-23 07:11:59

基本上,样本只是片段。您可以下载源代码,并从中获得一堆示例,包括这个水印示例。

以下内容来自PDFSharp-MigraDocFoundation-1_32/PDFsharp/samples/Samples C#/Based on GDI+/Watermark/Program.cs

很简单,真的..。我只是将代码显示到遍历每一页的for循环。你应该看看完整的文件。

代码语言:javascript
复制
  [...]
  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];
  [...]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45832641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档