Aspose.word保存PDF时进行授权访问设置
来源:互联网 发布:lte双流占比优化 编辑:程序博客网 时间:2024/05/21 19:50
- 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));
- }
以上代码,主要实现添加水印及生成PDF时加上安全设置
0 0
- Aspose.word保存PDF时进行授权访问设置
- Aspose.word保存PDF时进行授权访问设置
- Aspose.word设置页眉
- Aspose word导出word/pdf文件
- 使用Aspose.Pdf设置PDF文件信息
- word,txt转PDF 利用Aspose.Words
- word保存PDF
- 使用Aspose.word生成.pdf和.doc(word)报告文件
- 正文内容 Aspose.Words进行Word替换
- 使用Aspose.Pdf为FreeTextAnnotation设置格式
- 用Jsp输出Word,PDF等文件时进行的设置
- JAVA 使用Aspose.Words组件生产Word或PDF文件
- 使用Aspose组件将WORD、PDF、PPT转为图片
- JAVA-Aspose将WORD和Excel转成PDF
- 使用Aspose组件将WORD、PDF、PPT转为图片
- JAVA-Aspose将WORD和Excel转成PDF
- word保存为pdf文件
- Aspose.Words 替换word值和保存打印
- 图片数据&大文本数据存储
- Xcode真机测试could not find developer disk image解决方法
- OCP-1Z0-051-2015-61题
- Java中equals和==的区别
- linux平台几个压力,网络流量的工具
- Aspose.word保存PDF时进行授权访问设置
- 利用Nginx做负载均衡
- Xcode Archive时卡住(hangle/stuck)问题
- [设计模式学习笔记]CHAIN OF RESPONSIBILITY(职责链)
- AngularJS的工作机制
- git生成多个ssh key
- iOS Core Animation分析与详解
- vs 启动慢的排查方案
- Linux 基础 —— YUM入门