I used a trial license and was able to fill out an XFA form and save it. All was working well, so we purchased a license. After a couple of weeks, it looks like it stopped working. If I step through the code, I can see the XFA form fields are being assigned values and I can read them back after assigning them. But once I save the PDF, they’re not there in the output file. No errors or exceptions are thrown.
I’m wondering if the trial expired and the purchased license isn’t loading correctly? We’re using the streaming method to load the license from a SQL Server database. The file is stored in an “image” field. It’s being loaded like this in Global.asax.cs, during Application_Start. The application is a .NET Framework 4.8 web application.
The file is stored into the database using a byte array:
byte[] fileData = File.ReadAllBytes(filePath);
It is retrieved as a memory stream as set like this:
private void SetPdfLicenseFromStream()
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
MemoryStream licStream = PdfLicense.GetPdfLicenseStream();
if (licStream == null)
{
throw new InvalidOperationException("Aspose.PDF for .NET license not found.");
}
license.SetLicense(licStream);
}
Any thoughts on why this has stopped working?
@mark.jungman
This should work.
To check what’s wrong (I’m wondering if the trial expired and the purchased license isn’t loading correctly" or the way to download the license), the most reliable way is to run the example locally with the usual of the SetLicense license directly from the local file.
Check if the current license in the SQL Server database has been overwritten with a trial license?
I tried loading the license directly from the file, and it still has the same problem. I can set and read back the values for the form fields, but it doesn’t save them.
@mark.jungman
Are you sure this worked before?
Maybe you are using the same approach, but it doesn’t work for another document.
Please attach the code snippet and document used so that I can check how it works in our environment.
Yes, it definitely worked before. The PDF file is the same file as before. We always use the same PDF file. It’s a blank form that we fill out with new data and save under a new name. Here’s a simplified code snippet for the process and I’ve uploaded the PDF file. I’ve also noticed that even though the Save() method isn’t saving the data, it is modifying the PDF file somehow because the saved version has a different file size (smaller) than the original.
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult CreateSarPdf()
{
var data = formModel.GetForPdf(12, -1, trackerId, this.UserId());
if (data.Count > 0)
{
string pdfTemplateFilename = HttpContext.Server.MapPath("~/templates/SAR_PDF_Blank_v1.2.pdf");
var doc = new Document(pdfTemplateFilename);
FormModel formModel = new FormModel();
var data = formModel.GetForPdf(12, -1, trackerId, this.UserId());
foreach (var item in data)
{
val = item.Value;
doc.Form.XFA[item.Name] = val;
Debug.WriteLine($"set {val}");
Debug.WriteLine($"get {doc.Form.XFA[item.Name]});
}
var filename = $"SAR_PDF_Case_{trackerId}_-_{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}.pdf";
var savePath = $@"D:\{filename}";
doc.Save(savePath);
return File(savePath, "application/pdf", Server.UrlEncode(filename));
}
}
SAR_PDF_Blank_v1.2.pdf (2.4 MB)
@mark.jungman
It is necessary to describe in more detail for data (structure and data). Even better, of course, is to make a code snippet that does not use specific details.
Here is a simpler code snippet. The loop prints out all the field names from the form. Then it manually sets the values of two fields. These correspond to items 76 and 77 on page 2 of the PDF. This still doesn’t work for me, the fields are blank in the output PDF file.
var doc = new Document("SAR_PDF_Blank_v1.2.pdf");
foreach (var fn in doc.Form.XFA.FieldNames)
{
Debug.WriteLine($"found field {fn}");
}
doc.Form.XFA["BSAForm[0].FIContact[0].FilingInstitutionContact[0].FilerNameSub[0].filerName[0]"] = "John Smith";
doc.Form.XFA["BSAForm[0].FIContact[0].FilingInstitutionContact[0].tinSub[0].TIN[0]"] = "123121234";
var filename = $"SAR_PDF_Case_-_{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}.pdf";
doc.Save(filename, SaveFormat.Pdf);
@mark.jungman
Thank you for the corrected code snippet, I will check it in my environment and write to you.
@mark.jungman
This is a bug in the library (regression). In version 24.03 it works (I think it will work for you too), but in version 24.04 it no longer works. I’ll create a task for the development team.
Thanks again for the simpler code snippet with explanation.
Thank you, reverting back to v24.3 fixed the issue.
@mark.jungman
We can count (but not promise) that in this case the fix will happen soon.
@mark.jungman
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-57193
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as PDFNET-57193) have been fixed in Aspose.PDF for .NET 24.6.