使用 Aspose.Cells for Java 版本 25.9 将 Excel 文件转换为带有 PdfSecurityOptions 的 PDF 时抛出了异常。

We are a distributor, and our end-user information is as follows:

Product Name: Aspose.Total Product Family
Authorization: Developer OEM with Standard Support
Email: hc@huachuang.com.cn
Order Completion Time: 2024-12-10

When using Aspose.Cells for Java version 25.9 to convert an Excel file to a PDF with PdfSecurityOptions, the following exception is thrown: com.aspose.cells.CellsException: UnauthorizedAccess_MemStreamBuffer.

PdfSaveOptions saveOption = new PdfSaveOptions();
PdfSecurityOptions pdfSecurityOptions = new PdfSecurityOptions();
pdfSecurityOptions.setPrintPermission(allowPrint);
pdfSecurityOptions.setFullQualityPrintPermission(allowPrint);
pdfSecurityOptions.setModifyDocumentPermission(false);
saveOption.setSecurityOptions(pdfSecurityOptions);

        FileOutputStream fileOS = new FileOutputStream(new File("e:\\aa.pdf")); 
        workbook.save(fileOS, saveOption);

test.zip (5.2 KB)

How should this be resolved?

@xingyu11

Summary
When converting an Excel workbook to PDF with PdfSecurityOptions in Aspose.Cells for Java 25.9, the operation throws com.aspose.cells.CellsException: UnauthorizedAccess_MemStreamBuffer.

Why it happens
The exception is raised when the library cannot create or access the internal memory‑stream buffer that is used for PDF encryption. This can occur if the security options are not fully configured (for example, required passwords are missing) or if the output stream/file cannot be written to because of file‑system permissions or a restrictive Java SecurityManager.

What to do next

  1. Verify the security configuration – when using PdfSecurityOptions, make sure all required properties (such as user/owner passwords) are set according to the API documentation. If you do not need PDF protection, try saving without setting PdfSecurityOptions.
  2. Simplify the save call – instead of using a custom FileOutputStream, you can save directly to a file path, e.g.:
workbook.save("e:\\aa.pdf", saveOption);

This reduces the chance of stream‑related permission issues.
3. Check file‑system permissions – ensure the Java process has write access to the target folder (e.g., e:\). If a SecurityManager is active, confirm it grants the necessary java.io.FilePermission for the output file.
4. Test with a minimal workbook – create a small Excel file and apply the same options to see if the problem is data‑specific.
5. Contact Aspose support – if the issue persists after the above steps, provide the full stack trace, Java runtime version, OS details, and a reproducible sample to Aspose support for further investigation.

Following these steps should help identify and resolve the UnauthorizedAccess_MemStreamBuffer exception during Excel‑to‑PDF conversion with security options.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

@xingyu11
By testing with sample files and code on the latest version v25.11, we can reproduce the issue. CellsException occurs when saving file to pdf.

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): CELLSJAVA-46573

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.