Aspose.word保存PDF时进行授权访问设置
- public void ConvertDocToPDF(string docPath,string savePdfPath)
- {
- Aspose.Words.Document wordDocument = new Aspose.Words.Document(docPath);
- InsertWatermarkText(wordDocument, "内部资料 注意保密\r\n XX公司 ");
- wordDocument.Save("D:\\abc.doc");
- Aspose.Words.Saving.PdfSaveOptions saveOption = new Aspose.Words.Saving.PdfSaveOptions();
- saveOption.SaveFormat = Aspose.Words.SaveFormat.Pdf;
- //user pass 设置了打开时,需要密码
- //owner pass 控件编辑等权限
- PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "PasswordHere", PdfEncryptionAlgorithm.RC4_128);
- encryptionDetails.Permissions = PdfPermissions.DisallowAll;
- saveOption.EncryptionDetails = encryptionDetails;
- wordDocument.Save(savePdfPath, saveOption);
- }
- private static void InsertWatermarkText(Aspose.Words.Document doc, string watermarkText)
- {
- // Create a watermark shape. This will be a WordArt shape.
- // You are free to try other shape types as watermarks.
- Aspose.Words.Drawing.Shape watermark = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);
- // Set up the text of the watermark.
- watermark.TextPath.Text = watermarkText;
- watermark.TextPath.FontFamily = "宋体";
- watermark.Width = 500;
- watermark.Height = 100;
- // Text will be directed from the bottom-left to the top-right corner.
- watermark.Rotation = -40;
- // Remove the following two lines if you need a solid black text.
- watermark.Fill.Color = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
- watermark.StrokeColor = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
- // Place the watermark in the page center.
- watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
- watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
- watermark.WrapType = WrapType.None;
- watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
- watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
- // Create a new paragraph and append the watermark to this paragraph.
- Aspose.Words.Paragraph watermarkPara = new Aspose.Words.Paragraph(doc);
- watermarkPara.AppendChild(watermark);
- foreach (Section sect in doc.Sections)
- {
- // There could be up to three different headers in each section, since we want
- // the watermark to appear on all pages, insert into all headers.
- InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
- InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
- InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);
- }
- }
- private static void InsertWatermarkIntoHeader(Aspose.Words.Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
- {
- Aspose.Words.HeaderFooter header = sect.HeadersFooters[headerType];
- if (header == null)
- {
- // There is no header of the specified type in the current section, create it.
- header = new Aspose.Words.HeaderFooter(sect.Document, headerType);
- sect.HeadersFooters.Add(header);
- }
- // Insert a clone of the watermark into the header.
- header.AppendChild(watermarkPara.Clone(true));
- }
Aspose.word保存PDF时进行授权访问设置相关推荐
- 解决 linux(centos7)word转换pdf时,pdf乱码问题
本文解决当word转换为pdf时,pdf文档中的中文字体全部都是乱码(方框)的问题. 先简单的写一下word转换pdf的代码,这个网上有很多(最下方有引用一遍博客详细的讲解了如何转换) /**** @ ...
- word转pdf时图片质量下降的解决方案__亲测有效
写论文时经常需要将word文档转成pdf文档,通常的做法是word另存为pdf文档,这样很简洁很方面,可是最大的问题是图片质量会大大下降.究其原因,"另存为"选项会压缩图片,以降低 ...
- word转pdf时,图片错位,乱跑
参考:word转pdf时,图片错位 问题: 在word通过另存为转换pdf时,经常出现图片错误的现象,如何解决呢? 方法: 点word-文件-打印-adobe pdf-另存为-桌面,通过这方法打印出的 ...
- Word另存为PDF时出现“错误!未找到引用源”的解决
Word另存为PDF时,交叉引用的位置有时会出问题,导致排版混乱,比如交叉引用位置出现"错误!未找到引用源".可以通过锁定域更新解决. 如果要对某个域锁定,方法为:单击选定此域,然 ...
- WORD保存文件时,内存不足,是否存为挽救文档
今天碰到这种问题,保存WORD文档时.提示"WORD保存文件时,内存不足,是否存为挽救文档" 解决的办法,就是在windows下找riched20.dll这个文件,覆盖到C:\Pr ...
- Linux系统下Java 转换Word到PDF时,结果文档内容乱码的解决方法
本文分享在Linux系统下,通过Java 程序代码将Word转为PDF文档时,结果文档内容出现乱码该如何解决.具体可参考如下内容: 1.问题出现的背景 在Windows系统中,使用Spire.Doc ...
- java使用Aspose.word保存word更新目录页码报错以及样式错乱解决
保存文件之前,使用aspose.word中的这个方法: Document.updateFields() 更新域时会更新目录,但是页码可能会有偏差,原因是无法保证域的更新顺序,目录可能不是最后一个更新的 ...
- word中存储矢量图,word转为PDF时矢量图不失真。以及Visio图片放入word后有大量空白
一.使用draw.io绘制好,然后导出为vsdx 1.我们可以在Visio中绘制图形(或者使用diagrams.net:Flowchart Maker & Online Diagram Sof ...
- word另存为pdf时带书签
将word另存为pdf前 点击选项 然后勾选 这样保存后就有书签~
- aspose word转pdf 中文乱码
aspose word.excel转pdfwindows正常 服务器中文乱码 原因:服务器缺少中文字库 # 刷新字体缓存 fc-cache # 查看所有字体 fc-list # 查看所有中文字体 f ...
最新文章
- s-systemtap工具使用图谱(持续更新)
- 周报_2012第51周(2012/12/16-2012/12/22)
- 【Transformer】CSWin Transformer: A General Vision Transformer Backbone with Cross-Shaped Windows
- 记2018年技术人一次短暂的创业
- mysql查看服务器版本sql_警告:您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解使用n的正确语法...
- 落谷 P3375 【模板】KMP字符串匹配
- MAPinfo学习笔记
- 还在低头采石油? BP、壳牌、道达尔、中石化早已涌入可再生能源
- 有关深度学习领域的几点想法
- Niushop 砸金蛋营销活动
- POJ 3080 Blue Jeans(KMP + 暴力)
- Python异步并发机制详解,让你的代码运行效率就像搭上了火箭!!!
- 区块链隐私保护文献 An Efficient NIZK Scheme for Privacy-Preserving Transactions over Account-Model Blockchain
- 【HTML】HTML特殊符号全集
- 计算机起源于发展论文,关于计算机起源及发展的论文
- 解决Oracle报错ORA-01653: 表xx无法通过 8192 (在表空间 xx_data 中) 扩展
- matlab生成n阶O型方阵,matlab教程 06
- Zephyr-WEST工具
- API+段子+美图+未来的视频+关注+python
- SEO中巧用个人博客优化关键字
热门文章
- Whiteboard for mac(mac画图软件)
- 汇编实验 用Radasm设计生成一个对话框,实现如图1.1所示的四则运算计算器
- 科学表明世界上最令人感觉舒服的10种颜色(色码及RGB)
- 小米8刷官方欧版rom并从国内版rom提取安装MiPay、门卡模拟
- php 版onvif 客户端,onvif协议网络摄像机(IPC)客户端程序
- 红米6pro刷Android原生,红米6 Pro 魔趣OS 安卓9 MagiskV21版 完美ROOT 纯净完美 原生极简 纯净推荐...
- 大数据培训(第三季)——Linux基础-徐培成-专题视频课程
- cad被管理员阻止_CAD注册机无法以管理员身份输入的解决方案
- Socket协议脚本编写
- cad2016中选择全图字体怎么操作_CAD2016(精简版)安装教程