Constructors

If I want to make a modification to an existing PDF, most of the constructors like SaveableFacade take a Document for their parameter.

After I make my changes which Save method do I call, the Facade's or the Document's, or both?

All of the examples in the documentation seem to be for creating a brand new PDF. I could find no documentation in the Programmers guide for general rules for modifying existing documents.

Hi Dwight,

Thanks for using our products.

Aspose.Pdf.Document class provides the capability to create as well as manipulate existing PDF files. Whereas Aspose.Pdf.Facades namespace only provides the capability to manipulate/edit existing PDF files. Now concerning to constructors of classes present inside Facades namespace, you may either load PDF file by providing explicit file path or load the document first into Aspose.Pdf.Document object and then pass the same object as an argument to classes/constructors of Aspose.Pdf.Facades.

When you are using Facades namespace to manipulate PDF files, you only need to call the save method of that particular class and it’s not necessary to call Save method of Document class. Please visit the following sections of documentation for information on manipulating/updating existing PDF files. In case you still encounter any issue, please share the resource file and the code snippet which you are using so that we can test the scenario at our end. We apologize for this inconvenience.

PS, Aspose.Pdf.Generator namespace only provides the feature to create PDF files from scratch.

In this example I'm opening a PDF to make multiple changes. If I call the save for either the stamp or the security I get runtime errors. Since I'm making multiple changes I should call the save for the Document object? Is this documented?

Dwight

Aspose.Pdf.Document PDFDoc = new Aspose.Pdf.Document(InPDFPath);

PdfFileStamp PDFStamper = new PdfFileStamp(PDFDoc);

FormattedText FText = new FormattedText(s.ToString(), new FontColor(0, 0, 0), FontStyle.TimesRoman, EncodingType.Winansi, false, 6);
PDFStamper.AddFooter(FText, 6, 20, 10);

// Save here?
//PDFStamper.Save(OutPDFPath);

// allow printing and stuff
PdfFileSecurity Security = new PdfFileSecurity(PDFDoc);
DocumentPrivilege DP = DocumentPrivilege.AllowAll;
DP.AllowModifyContents = false;
DP.AllowModifyAnnotations = false;
Security.SetPrivilege(DP);

// Save here?
//Security.Save(OutPDFPath);

PDFDoc.PageLayout = Aspose.Pdf.PageLayout.SinglePage;

// Save here?
//PDFDoc.Save(OutPDFPath);

Hi,


When performing multiple operations over single PDF file, you may consider applying changes and save the intermediate output in Steam object and pass the same object to other class. Once all the required changes/manipulations are performed, you may save the final output. Something similar to

[C#]

PdfFileStamp PDFStamper = new PdfFileStamp();<o:p></o:p>

PDFStamper.BindPdf("c:/pdftest/RadioButtonSelected.pdf");

FormattedText FText = new FormattedText("Hello World..", new FontColor(0, 0, 0), Aspose.Pdf.Facades.FontStyle.TimesRoman, EncodingType.Winansi, false, 6);

PDFStamper.AddFooter(FText, 6, 20, 10);

MemoryStream ms = new MemoryStream();

PDFStamper.Save(ms);

// Save here?

//PDFStamper.Save(OutPDFPath);

// allow printing and stuff

PdfFileSecurity Security = new PdfFileSecurity();

Security.BindPdf(ms);

DocumentPrivilege DP = DocumentPrivilege.AllowAll;

DP.AllowModifyContents = false;

DP.AllowModifyAnnotations = false;

Security.SetPrivilege(DP);

// Save here?

//Security.Save(OutPDFPath);

Security.Save("c:/pdftest/UpdatedPDFDocument.pdf");

//PDFDoc.PageLayout = Aspose.Pdf.PageLayout.SinglePage;

ms.Close();



However when loading the PDF file in Document object, changes are performed to referenced document same object is passed to other classes for further operations (as you have shared in your above code snippet). In the event of any further query, please feel free to contact.

So by what you say in your last line...If all the changes are performed to the referenced document object I could just do the save for the document object and that would save all my changes.

That way I'll be able to modify the PageLayout too.

Aspose.Pdf.Document PDFDoc = new Aspose.Pdf.Document(InPDFPath);

PdfFileStamp PDFStamper = new PdfFileStamp(PDFDoc);

FormattedText FText = new FormattedText(s.ToString(), new FontColor(0, 0, 0), FontStyle.TimesRoman, EncodingType.Winansi, false, 6);
PDFStamper.AddFooter(FText, 6, 20, 10);

// allow printing and stuff
PdfFileSecurity Security = new PdfFileSecurity(PDFDoc);
DocumentPrivilege DP = DocumentPrivilege.AllowAll;
DP.AllowModifyContents = false;
DP.AllowModifyAnnotations = false;
Security.SetPrivilege(DP);

PDFDoc.PageLayout = Aspose.Pdf.PageLayout.SinglePage;

PDFDoc.Save(OutPDFPath); // This will save all the changes.

Hi,


Yes you are correct. When loading the PDF file using Document object and passing same object as argument to PdfFileStamp, PdfFileSecurity classes and specifying the PageLayout against Document object, the manipulations/updates are performed over the input PDF document. Once all operations are performed, please call PDFDoc.Save(“c:/UpdatedPDFfile.pdf”); so that changes are saved.

In the event of any further query, please feel free to contact.