We are creating PDF’s using Aspose.Words 24.7.0. We have a few users claiming that they cannot open these files (PDF compliance 1.7). Our older version of this program used 20.9.0 with PDF compliance 1.5 and those files all work fine. The files are not encrypted. Is this seen by anyone else and if so is there a workaround?
It seems that some users are experiencing issues opening PDF files created with Aspose.Words version 24.7.0, while files generated with an older version (20.9.0) are functioning correctly. Since the files are not encrypted and are compliant with PDF 1.7, there are a few steps you can take to troubleshoot and potentially resolve this issue.
-
Check PDF Compliance Settings: Ensure that the PDF compliance settings in your code are correctly set. You might want to experiment with different compliance levels (e.g., PDF 1.5) to see if that resolves the issue for the affected users.
-
Font Embedding: Verify if all fonts used in the documents are being embedded correctly. You can set the
EmbedFullFonts
property in thePdfSaveOptions
to ensure that all fonts are included in the PDF. This can help avoid issues related to missing fonts on the users’ systems.PdfSaveOptions saveOptions = new PdfSaveOptions { EmbedFullFonts = true }; document.Save("output.pdf", saveOptions);
-
Test on Different PDF Readers: Sometimes, the issue may be related to the PDF reader being used. Encourage users to try opening the PDF files in different PDF readers (e.g., Adobe Acrobat Reader, Foxit Reader) to see if the problem persists.
-
Review Document Structure: Ensure that the document structure is correctly set up in the source document. Issues with headings, bookmarks, or other structural elements can sometimes lead to problems in the generated PDF.
-
Update to Latest Version: If possible, consider updating to the latest version of Aspose.Words, as newer versions may contain bug fixes and improvements that could resolve the issue.
If these steps do not resolve the problem, it may be helpful to gather more information from the affected users, such as the specific error messages they encounter or the PDF readers they are using. This information can assist in diagnosing the issue further.
If you continue to experience difficulties, please feel free to reach out for additional support.
Sources:
[1]: Working with PDF/A or PDF/UA|Aspose.Words for .NET
@thomas948 Could you please provide the problematic PDF documents and let us know in which PDF viewers the problem is reproducible? Probably there is a problem in the viewer app.
30_2497200_2024-12-04_csf_AZ-CWRFP_tao (5).pdf (160.3 KB)
This is one of the files. It opens fine for us using Adobe Acrobat 24.004, Chrome, or Firefox. I am not sure what our affected users are using as viewers but I will try to find out. Thank you for your help.
@thomas948 Thank you for additional information. I can reproduce the problem on my side. The problem is cased by empty bytes written after the EOF:
Could you please share the code you use to generate the document? Most likely there is something wrong in the way the file is written. We will check your code and provide you more information.
Thank you. This is code from a Razor Page. It uses Aspose to fill in bookmarks from a Word document using user input from the Razor Page. It then saves to PDF, returns the PDF to the browser, and saves a copy to AWS S3. I have trimmed a bunch of extra code, let me know if you want the whole page.
public async Task<IActionResult> OnPostWaiver()
{
var file = await CreateWaiver(Waiver);
FileContentResult result = new FileContentResult(file.Stream.GetBuffer(), file.ContentType)
{
FileDownloadName = file.FileName
};
return result;
}
public async Task<WaiverInfo> CreateWaiver(CsdDto waiver)
{
string fileName = waiver.ClientNum + "_" + waiver.ArsDocNum + "_" + DateTime.Now.Year + "-" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("dd") + "_csf_" + waiver.FormType + "_" + WebUser.Initials.ToLower();
MemoryStream dstStream = new();
WaiverInfo waiverInfo = new();
string s3path = "";
if (waiver.PdfOrDoc == "PDF") {
PdfSaveOptions saveOptions = new PdfSaveOptions();
PdfEncryptionDetails encryptionDetails =
new PdfEncryptionDetails(string.Empty, "password");
encryptionDetails.Permissions = PdfPermissions.DisallowAll;
encryptionDetails.Permissions = PdfPermissions.Printing;
encryptionDetails.Permissions = PdfPermissions.HighResolutionPrinting;
// saveOptions.EncryptionDetails = encryptionDetails;
saveOptions.Compliance = PdfCompliance.Pdf17;
BuiltInDocumentProperties properties = doc.BuiltInDocumentProperties;
properties.Author = "Company";
var state = await _geography.GetStateAsync(waiver.ProjectState);
properties.Title = state.FullName.ToUpper() + " " + mailerTitle;
properties.CreatedTime = DateTime.Now;
properties.LastPrinted = DateTime.Now;
properties.LastSavedTime = DateTime.Now;
s3path = "IW/" + DateTime.Now.Year + "/" + waiver.ClientNum +
"/" + fileName + ".pdf";
doc.Save(dstStream, saveOptions);
waiverInfo.ContentType = "application/pdf";
waiverInfo.Stream = dstStream;
waiverInfo.FileName = fileName + ".pdf";
}
var csd = new Csd
{
EntryDate = DateTime.Now,
EntryTime = DateTime.Now.ToString("HH:mm"),
MasterDbName = waiver.ClientNum,
ClientNum = Convert.ToDecimal(waiver.ClientNum),
RwsNum = Convert.ToDecimal(waiver.RwsNumber),
LastDocNum = waiver.ArsDocNum,
User = WebUser.Initials,
UserPhoneAc = Helpers.ParseAreaCode(WebUser.PhoneNumber),
UserPhone = Helpers.ParsePhoneNumber(WebUser.PhoneNumber),
UserEmailAddress = WebUser.Email,
IpAddress = Helpers.GetClientIPAddress(HttpContext),
FormType = waiver.FormType,
FormatRequested = waiver.PdfOrDoc,
IncludeMailer = Conversions.FromBool(waiver.IncludeMailer),
IncludePhoneEmail = Conversions.FromBool(waiver.IncludePhoneEmail),
IncludeProjAddress = Conversions.FromBool(waiver.IncludeStreet),
IncludeLegal = Conversions.FromBool(waiver.IncludeLegal),
Include1stSupDate = Conversions.FromBool(waiver.IncludeFirstSupplyDate),
IncludeAcknowledge = Conversions.FromBool(waiver.IncludeAcknowledge),
IncludeBarcode = Conversions.FromBool(waiver.IncludeBarcode),
IncludeJointPymt = Conversions.FromBool(waiver.IncludeJointPymt),
ProjectStreet = waiver.ProjectStreet,
ProjectCity = waiver.ProjectCity,
ProjectState = waiver.ProjectState,
ProjectZip = waiver.ProjectZip,
ProjectCounty = waiver.ProjectCounty,
ProjectName = waiver.ProjectNameFrm,
JobInvNum = waiver.JobInvNum,
ApnNum = waiver.ApnNum,
LegalDescrip = waiver.LegalDescrip,
};
var bucket = SsmParameters.GetSecureParameter($"/{_env.EnvironmentName}/Waivers");
_s3Service.UploadStream(waiverInfo.Stream, bucket, s3path, waiverInfo.ContentType);
await _waiverService.CreateWaiverAsync(csd, iwdir, lnm, logDoc);
return waiverInfo;
}
@thomas948 I think the problem is in file.Stream.GetBuffer()
. Please try using file.Stream.ToArray()
method instead.
Thank you very much for your help with this.