Extended Features lost

I'm trying to open a PDF, replace some text and then save the document. The problem is that when I do this the extended features are disabled.

public static void CreateProfile(SurveyProfile userProfile, string userProfilePath, string templatePath)
{
using (FileStream fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.ReadWrite))
{
Document profileDocument = new Document(fileStream);
ReplaceTokens(profileDocument, userProfile.FirstName, userProfile.LastName);
profileDocument.Save(userProfilePath,SaveFormat.Pdf);
}
}

public static void ReplaceTokens(Document profileDocument, string firstName, string lastName)
{
Aspose.Pdf.Facades.PdfContentEditor pdfContentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
pdfContentEditor.BindPdf(profileDocument);
pdfContentEditor.ReplaceTextStrategy.ReplaceScope = Aspose.Pdf.Facades.ReplaceTextStrategy.Scope.REPLACE_ALL;

pdfContentEditor.ReplaceText("FirstName", firstName);
pdfContentEditor.ReplaceText("LastName", lastName);
}

The error I get when I open the document is attached.

Hi Bobby,


Thanks for your inquiry. You need to use incremental approach for preserving the extended rights. Open the document using stream, perform the required operation and use Save() overload without any parameter. Please check following documentation link for details, it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

It’s funny because I tried that and got the same results but today it worked for me. Perhaps I had something cached causing an issue.


Here is the adjusted code for closure on the thread.

public static void CreateProfile(SurveyProfile userProfile, string userProfilePath, string templatePath)
{
File.Copy(templatePath, userProfilePath);

using (FileStream fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.ReadWrite))
{
Document profileDocument = new Document(fileStream);

ReplaceTokens(profileDocument, userProfile.FirstName, userProfile.LastName);
InsertResellerLogo(profileDocument, userProfile.logoPath);

profileDocument.Save();
}
}

Hi Bobby,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirements. As per initial post, you were using Save() method with parameters so getting extend rights error. You need to use Save() method without any parameter.

Please feel free to contact us for any further assistance.

Best Regards,


This issue is back.


public static void CreateProfile(SurveyProfile userProfile, string userProfilePath, string templatePath)
{
File.Copy(templatePath, userProfilePath);

using (FileStream fileStream = new FileStream(userProfilePath, FileMode.Open, FileAccess.ReadWrite))
{
Document profileDocument = new Document(fileStream);

ReplaceTokens(profileDocument, userProfile.FirstName, userProfile.LastName);
InsertResellerLogo(profileDocument, userProfile.logoPath);

profileDocument.Save();
}
}

public static void ReplaceTokens(Document profileDocument, string firstName, string lastName)
{
Aspose.Pdf.Facades.PdfContentEditor pdfContentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
pdfContentEditor.BindPdf(profileDocument);
pdfContentEditor.ReplaceTextStrategy.ReplaceScope = Aspose.Pdf.Facades.ReplaceTextStrategy.Scope.REPLACE_ALL;

pdfContentEditor.ReplaceText(“FirstName”, firstName);
pdfContentEditor.ReplaceText(“LastName”, lastName);
}

public static void InsertResellerLogo(Document profileDocument, string logoPath)
{
string fullLogoPath = HttpContext.Current.Request.PhysicalApplicationPath + @"\CustomLayout" + logoPath;

if (File.Exists(fullLogoPath))
{
ImageStamp imageStamp = new ImageStamp(fullLogoPath);
imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Center;
imageStamp.TopMargin = 150;
imageStamp.Background = true;
profileDocument.Pages[1].AddStamp(imageStamp);

}
}

Hi Bobby,

Thanks for sharing the details.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-38727. We will investigate this issue in detail and will keep you updated on the status of a correction.

We apologize for your inconvenience.

Well I’m glad to know that I’m not crazy but I’m concerned about it being logged as an issue and not having an immediate resolution. The entire purpose of the component is to be able to edit a PDF document and all I’m doing is some text replacement and stamping an image.


Is there a previous version of the component that doesn’t have this issue because we have been working on this for some time and just now encountered the issue when we made the purchase and got it ready for production.

I’m also open to alternate solutions other than the code I posted.

My requirement is to open a PDF document with extended features enabled (for text, checkboxes, and radio buttons that the user can fill in and save), replace text throughout the document based on predefined tokens, and insert an image on a given page.

I have the ability to change the PDF document and/or the code.

I was about to give up and refund the component but figured I’d try and remove the extended rights and it actually solved the issue.


I’ve noticed several other threads with similar issue so you might want to add this fix/hack to your ticket for your development team.

public static void CreateProfile(SurveyProfile userProfile, string userProfilePath, string templatePath)
{
File.Copy(templatePath, userProfilePath);
using (FileStream fileStream = new FileStream(userProfilePath, FileMode.Open, FileAccess.ReadWrite))
{
Document profileDocument = new Document(fileStream);

ReplaceTokens(profileDocument, userProfile.FirstName, userProfile.LastName);
InsertResellerLogo(profileDocument, userProfile.logoPath);

PdfFileSignature sign = new PdfFileSignature();
sign.BindPdf(profileDocument);
sign.RemoveUsageRights();

profileDocument.Save();
}
}

Result is that the document edits are made and the extended rights are preserved.


orgplus:
Well I'm glad to know that I'm not crazy but I'm concerned about it being logged as an issue and not having an immediate resolution. The entire purpose of the component is to be able to edit a PDF document and all I'm doing is some text replacement and stamping an image.
Hi Bobby,

As a stand operating procedure, once the scenario is initially analyzed and if there is any issue, its logged in our issue tracking system so that development team can further investigate the problem and figure out the actual reasons causing such problem. Similar approach has been followed in your case and an issue has been logged in our issue tracking system, so that development team can further analyze this problem. As soon as we have definite updates regarding its resolution, we will let you know.
orgplus:
I was about to give up and refund the component but figured I'd try and remove the extended rights and it actually solved the issue.

I've noticed several other threads with similar issue so you might want to add this fix/hack to your ticket for your development team.

public static void CreateProfile(SurveyProfile userProfile, string userProfilePath, string templatePath)
{
File.Copy(templatePath, userProfilePath);
using (FileStream fileStream = new FileStream(userProfilePath, FileMode.Open, FileAccess.ReadWrite))
{
Document profileDocument = new Document(fileStream);

ReplaceTokens(profileDocument, userProfile.FirstName, userProfile.LastName);
InsertResellerLogo(profileDocument, userProfile.logoPath);

PdfFileSignature sign = new PdfFileSignature();
sign.BindPdf(profileDocument);
sign.RemoveUsageRights();

profileDocument.Save();
}
}

Result is that the document edits are made and the extended rights are preserved.


Hi Bobby,

Thanks for sharing the feedback. The information has been associated with earlier reported issue so that development team considers this information during the resolution of this problem.

The issue logged under the ticket ID PDFNET-38727 has been resolved in Aspose.PDF for .NET 25.12.

You can please download the latest release from:

If you have any further questions, please let us know.