ok, it turned out to be a problem with our custom ResourceResolver...
...returning null in getOutputStream(...) wasn't a good idea. 😎
Best regards,
DaveLaw
On 17/03/2026 12:50, David Law wrote:
Hi there,
I'm trying to create a signed PDF with FOP v2.11 & JDK 17.
I am NOT using a Config file (i.e. fop.xconf).
Instead I'm supplying an instance of PDFSignParams.
-> FOP then internally creates an instance of PDFSignature.
-> I've checked the PDFSignature instance is able to read the Keystore
& sign content.
When creating the PDF from the FO, a *NullPointerException* is raised.
The only Method invoked on PDFSignature is add(final PDFPage page).
The message is:
Cannot invoke "java.io.OutputStream.write(byte[], int, int)" because
"this.out" is null
(I did something similar for encryption with an instance of
PDFEncryptionParams. That worked fine)
Before I take time to create a detailed example,
I thought I'd ask if anyone has had the same problem.
The generatePDFfromFO Method looks like this:
private static byte[] generatePDFfromFO(final byte[] bytesFO, final
TransformerFactory factory) throws Exception {
final var foUserAgent = FOP_FACTORY.newFOUserAgent();
; foUserAgent.setProducer("ap FOP");
; foUserAgent.setCreationDate(new Date());
; foUserAgent.setTargetResolution(300 /* dpi */);
final var foSignParms = new
PDFSignParams("path/fopTest.pkcs12", null, null, null, "fopTest");
@SuppressWarnings("unchecked")
final var foRendOpt = (Map<Object, Object>)
foUserAgent.getRendererOptions();
; foRendOpt.put("sign-params", foSignParms);
final var pdfBytesSizeGuess = bytesFO.length / 2;
final var pdfBytesBaos = new
ByteArrayOutputStream(pdfBytesSizeGuess);
try (pdfBytesBaos)
{
final var fop =
foUserAgent.newFop(MimeConstants.MIME_PDF, pdfBytesBaos);
final var saxResult = new
SAXResult(fop.getDefaultHandler());
final var xmlSource = getSource(bytesFO);
final var transformer = factory.newTransformer();
; transformer.transform(xmlSource, saxResult); // ->
*NullPointerException*
}
return pdfBytesBaos.toByteArray();
}
Any ideas, anyone?
Thanks in advance,
DaveLaw
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]