1. public void ConvertDocToPDF(string docPath,string savePdfPath)
  2. {
  3. Aspose.Words.Document wordDocument = new Aspose.Words.Document(docPath);
  4. InsertWatermarkText(wordDocument, "内部资料 注意保密\r\n XX公司  ");
  5. wordDocument.Save("D:\\abc.doc");
  6. Aspose.Words.Saving.PdfSaveOptions saveOption = new Aspose.Words.Saving.PdfSaveOptions();
  7. saveOption.SaveFormat = Aspose.Words.SaveFormat.Pdf;
  8. //user pass 设置了打开时,需要密码
  9. //owner pass 控件编辑等权限
  10. PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "PasswordHere", PdfEncryptionAlgorithm.RC4_128);
  11. encryptionDetails.Permissions = PdfPermissions.DisallowAll;
  12. saveOption.EncryptionDetails = encryptionDetails;
  13. wordDocument.Save(savePdfPath, saveOption);
  14. }
  15. private static void InsertWatermarkText(Aspose.Words.Document doc, string watermarkText)
  16. {
  17. // Create a watermark shape. This will be a WordArt shape.
  18. // You are free to try other shape types as watermarks.
  19. Aspose.Words.Drawing.Shape watermark = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);
  20. // Set up the text of the watermark.
  21. watermark.TextPath.Text = watermarkText;
  22. watermark.TextPath.FontFamily = "宋体";
  23. watermark.Width = 500;
  24. watermark.Height = 100;
  25. // Text will be directed from the bottom-left to the top-right corner.
  26. watermark.Rotation = -40;
  27. // Remove the following two lines if you need a solid black text.
  28. watermark.Fill.Color = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
  29. watermark.StrokeColor = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
  30. // Place the watermark in the page center.
  31. watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
  32. watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
  33. watermark.WrapType = WrapType.None;
  34. watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
  35. watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
  36. // Create a new paragraph and append the watermark to this paragraph.
  37. Aspose.Words.Paragraph watermarkPara = new Aspose.Words.Paragraph(doc);
  38. watermarkPara.AppendChild(watermark);
  39. foreach (Section sect in doc.Sections)
  40. {
  41. // There could be up to three different headers in each section, since we want
  42. // the watermark to appear on all pages, insert into all headers.
  43. InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
  44. InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
  45. InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);
  46. }
  47. }
  48. private static void InsertWatermarkIntoHeader(Aspose.Words.Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
  49. {
  50. Aspose.Words.HeaderFooter header = sect.HeadersFooters[headerType];
  51. if (header == null)
  52. {
  53. // There is no header of the specified type in the current section, create it.
  54. header = new Aspose.Words.HeaderFooter(sect.Document, headerType);
  55. sect.HeadersFooters.Add(header);
  56. }
  57. // Insert a clone of the watermark into the header.
  58. header.AppendChild(watermarkPara.Clone(true));
  59. }
以上代码,主要实现添加水印及生成PDF时加上安全设置

Aspose.word保存PDF时进行授权访问设置相关推荐

  1. 解决 linux(centos7)word转换pdf时,pdf乱码问题

    本文解决当word转换为pdf时,pdf文档中的中文字体全部都是乱码(方框)的问题. 先简单的写一下word转换pdf的代码,这个网上有很多(最下方有引用一遍博客详细的讲解了如何转换) /**** @ ...

  2. word转pdf时图片质量下降的解决方案__亲测有效

    写论文时经常需要将word文档转成pdf文档,通常的做法是word另存为pdf文档,这样很简洁很方面,可是最大的问题是图片质量会大大下降.究其原因,"另存为"选项会压缩图片,以降低 ...

  3. word转pdf时,图片错位,乱跑

    参考:word转pdf时,图片错位 问题: 在word通过另存为转换pdf时,经常出现图片错误的现象,如何解决呢? 方法: 点word-文件-打印-adobe pdf-另存为-桌面,通过这方法打印出的 ...

  4. Word另存为PDF时出现“错误!未找到引用源”的解决

    Word另存为PDF时,交叉引用的位置有时会出问题,导致排版混乱,比如交叉引用位置出现"错误!未找到引用源".可以通过锁定域更新解决. 如果要对某个域锁定,方法为:单击选定此域,然 ...

  5. WORD保存文件时,内存不足,是否存为挽救文档

    今天碰到这种问题,保存WORD文档时.提示"WORD保存文件时,内存不足,是否存为挽救文档" 解决的办法,就是在windows下找riched20.dll这个文件,覆盖到C:\Pr ...

  6. Linux系统下Java 转换Word到PDF时,结果文档内容乱码的解决方法

    本文分享在Linux系统下,通过Java 程序代码将Word转为PDF文档时,结果文档内容出现乱码该如何解决.具体可参考如下内容: 1.问题出现的背景 在Windows系统中,使用Spire.Doc ...

  7. java使用Aspose.word保存word更新目录页码报错以及样式错乱解决

    保存文件之前,使用aspose.word中的这个方法: Document.updateFields() 更新域时会更新目录,但是页码可能会有偏差,原因是无法保证域的更新顺序,目录可能不是最后一个更新的 ...

  8. word中存储矢量图,word转为PDF时矢量图不失真。以及Visio图片放入word后有大量空白

    一.使用draw.io绘制好,然后导出为vsdx 1.我们可以在Visio中绘制图形(或者使用diagrams.net:Flowchart Maker & Online Diagram Sof ...

  9. word另存为pdf时带书签

    将word另存为pdf前 点击选项 然后勾选 这样保存后就有书签~

  10. aspose word转pdf 中文乱码

    aspose word.excel转pdfwindows正常  服务器中文乱码 原因:服务器缺少中文字库 # 刷新字体缓存 fc-cache # 查看所有字体 fc-list # 查看所有中文字体 f ...

最新文章

  1. 最新数据分析教程资源合集(案例、数据集、SQL教程、分析样板、面经、简历、PY教程... )...
  2. jQuery笔记之工具方法extend插件扩展
  3. 全球及中国超导磁铁探针台行业现状规模及“十四五”发展趋势预测报告2021-2027年版
  4. 《深入浅出数据分析》第九章——R语言
  5. vc mysql_vc6.0连接mysql数据库
  6. Echarts在手机端y轴数据过大,显示不全
  7. bootstracp实现树形列表_Java实现一致性哈希算法,并搭建环境测试其负载均衡特性...
  8. 动态切换数据源(spring+hibernate)
  9. VMware内虚拟机自适应及最大化窗口调整方式
  10. 再谈注意力机制 | 运用强化学习实现目标特征提取
  11. python连接sql server
  12. 偶极子天线的优缺点_关于偶极子天线的若干问题。
  13. 4个常用Linux开发环境工具,你最常用的是那个?
  14. 计算机显示不出桌面的文件夹,win10电脑保存文件路径不显示桌面怎么办?
  15. Pearson相关系数公式的四种形式及Python代码实现
  16. Python - 实现渐变色的RGB计算
  17. H5 集成微信自定义分享(兼容 ios android)
  18. 微信链接修改图片_微信链接修改图标
  19. 京东数科前端岗位面历
  20. 源码分析 There is no getter for property named '*' in 'class java.lang.String

热门文章

  1. java面试题--java基础--迈达斯篇
  2. android红米升级失败怎么办,红米刷机失败怎么办?解决红米刷机失败教程
  3. 万字长文!用文本挖掘深度剖析54万首诗歌
  4. Linux下卸载anaconda3
  5. 构建WebIM聊天程序
  6. ffmpeg处理——*.flv视频文件和*.ass字幕文件合并成mp4
  7. 最新CISP模拟考试题库及答案(二)
  8. Sentaurus Process Device
  9. Android基于在线地图的轨迹跟踪服务
  10. java常量池在哪里_java常量池在哪?有什么用处?