简体   繁体   中英

Make 1 layer pdf with use Aspose.Pdf library

I'm using Aspose.Pdf for .NET.

What I'm trying to do is:

Make pdf with 1 layer (best solution would be if before generate pdf all used text and bacground image would be as picture and then generated pdf) I need it for prohibit changing content in my pdf simple secure pdf file isn't enough, because even online pdf to doc converters enable to change content.

So is there a way to do this now? Or is there any way for make image from content before put it on site of pdf?

I was able to generate pdf but with multiple layers (2 in my scenario).

I've use dll version 5.0.0 for .net 4.0 Client.

Thanks in advance:)

Using Aspose.Pdf, you can set several privileges on the PDF documents to control their use. Specify the security options as follows using Aspose.Pdf and the Pdf document you have generated will behave as a readonly document which could not be edited:

//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");

As far as creating the whole content of PDF as an embedded image, it is not directly supported in Aspose.Pdf. You can however use some way around or some other component to generate image with your content and then can use this image to create Pdf file using Aspose.Pdf as follows:

  • Generate PDF with your content (A multi layer PDF as you have created earlier)
  • Export the PDF to image as described in " Working with Images " section of Aspose.Pdf documentation.
  • Use exported image to create PDF as described in " Working with Images(Generator) " and distribute your document.

My name is Iqbal and I am developer evangelist at Aspose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM