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. s-systemtap工具使用图谱(持续更新)
  2. 周报_2012第51周(2012/12/16-2012/12/22)
  3. 【Transformer】CSWin Transformer: A General Vision Transformer Backbone with Cross-Shaped Windows
  4. 记2018年技术人一次短暂的创业
  5. mysql查看服务器版本sql_警告:您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解使用n的正确语法...
  6. 落谷 P3375 【模板】KMP字符串匹配
  7. MAPinfo学习笔记
  8. 还在低头采石油? BP、壳牌、道达尔、中石化早已涌入可再生能源
  9. 有关深度学习领域的几点想法
  10. Niushop 砸金蛋营销活动
  11. POJ 3080 Blue Jeans(KMP + 暴力)
  12. Python异步并发机制详解,让你的代码运行效率就像搭上了火箭!!!
  13. 区块链隐私保护文献 An Efficient NIZK Scheme for Privacy-Preserving Transactions over Account-Model Blockchain
  14. 【HTML】HTML特殊符号全集
  15. 计算机起源于发展论文,关于计算机起源及发展的论文
  16. 解决Oracle报错ORA-01653: 表xx无法通过 8192 (在表空间 xx_data 中) 扩展
  17. matlab生成n阶O型方阵,matlab教程 06
  18. Zephyr-WEST工具
  19. API+段子+美图+未来的视频+关注+python
  20. SEO中巧用个人博客优化关键字

热门文章

  1. Whiteboard for mac(mac画图软件)
  2. 汇编实验 用Radasm设计生成一个对话框,实现如图1.1所示的四则运算计算器
  3. 科学表明世界上最令人感觉舒服的10种颜色(色码及RGB)
  4. 小米8刷官方欧版rom并从国内版rom提取安装MiPay、门卡模拟
  5. php 版onvif 客户端,onvif协议网络摄像机(IPC)客户端程序
  6. 红米6pro刷Android原生,红米6 Pro 魔趣OS 安卓9 MagiskV21版 完美ROOT 纯净完美 原生极简 纯净推荐...
  7. 大数据培训(第三季)——Linux基础-徐培成-专题视频课程
  8. cad被管理员阻止_CAD注册机无法以管理员身份输入的解决方案
  9. Socket协议脚本编写
  10. cad2016中选择全图字体怎么操作_CAD2016(精简版)安装教程