使用Aspose.Pdf库创建1层pdf



我在。net中使用Aspose.Pdf。

我要做的是:

用1层制作pdf(最好的解决方案是在生成pdf之前,所有使用的文本和背景图像都将作为图片,然后生成pdf)我需要它来禁止在我的pdf中更改内容,简单的安全pdf文件是不够的,因为即使是在线pdf到文档转换器也可以更改内容。

那么现在有办法做到这一点吗?或者有没有办法在把内容放到pdf的网站之前制作图像?

我能够生成pdf,但有多个图层(在我的场景中是2层)。

我在。net 4.0客户端使用了5.0.0版本的dll。

提前感谢:)

使用Aspose.Pdf,您可以在PDF文档上设置几个特权来控制它们的使用。使用asposef .Pdf指定如下安全选项,您生成的Pdf文档将表现为只读文档,无法编辑:

//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Assign a security instance to Pdf object            
pdf1.Security = new Aspose.Pdf.Generator.Security();
//Restrict annotation modification
pdf1.Security.IsAnnotationsModifyingAllowed = false;
//Restrict contents modification
pdf1.Security.IsContentsModifyingAllowed = false;
//Restrict copying the data
pdf1.Security.IsCopyingAllowed = false;
//Allow to print the document
pdf1.Security.IsPrintingAllowed = true;
//Restrict form filling
pdf1.Security.IsFormFillingAllowed = false;
//Add a section in the Pdf
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
//Create a text paragraph and set top margin
Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1,"this is text content");
text1.Margin.Top = 30;
//Add image
Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image();
img.ImageInfo.File = "asposelogo.png";
img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
//Add the text paragraph and image to the section
sec1.Paragraphs.Add(text1);
sec1.Paragraphs.Add(img);
//Save the Pdf                            
pdf1.Save("test.pdf");

至于将PDF的整个内容创建为嵌入图像,Aspose.Pdf中不直接支持。然而,你可以使用一些方法或其他组件来生成带有内容的图像,然后可以使用Aspose.Pdf使用此图像创建Pdf文件,如下所示:

  • 用你的内容生成PDF(一个你之前创建的多层PDF)
  • 按照Aspose.Pdf文档中"使用图像"一节的描述将PDF导出为图像。
  • 使用导出的图像创建PDF,如"使用图像(生成器)"中所述,并分发您的文档。

我的名字是Iqbal,我是Aspose的开发者布道者。

最新更新