We are using spirePDF in a spring boot application in version : 3.2.2
The latest SpirePDF version we use is version: 10.1.5
One of the service we use allows us to digitally sign our pdfs :
- Code: Select all
@Override
public PdfDto signPdf(PdfDto pdfDto, LogDto logDto) throws IOException, PdfException {
log.info("PdfServiceImpl signPdf() called");
List<DataDto> dataDtos = new ArrayList<>();
pdfDto.getData().forEach(dataDto -> {
LogDto logDtoUpdate = logDto;
ByteArrayOutputStream signedPdf = new ByteArrayOutputStream();
InputStream certificateStream = Utils.base64DecodeFromString(dataDto.getCertificate());
PdfDocument doc = null;
try {
doc = loadPdf(dataDto.getPdf(), logDtoUpdate);
PdfCertificate cert = new PdfCertificate(IOUtils.toByteArray(certificateStream), dataDto.getPassword());
if ((dataDto.getSignatureName() == null) || dataDto.getSignatureName().isEmpty()) {
dataDto.setSignatureName("Signature");
}
PdfSignature pdfSign = new PdfSignature(doc,
doc.getPages().get(doc.getPages().getCount() - 1),
cert,
dataDto.getSignatureName());
pdfSign.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
pdfSign.setDocumentPermissions(PdfCertificationFlags.Allow_Form_Fill);
pdfSign.setLocationInfo(dataDto.getLocation());
pdfSign.setReason(dataDto.getReason());
doc.saveToStream(signedPdf);
String pdf64Signed = new Base64().encodeAsString(signedPdf.toByteArray());
dataDtos.add(DataDto.builder().pdf(pdf64Signed).build());
} catch (PdfException | IOException e) {
throw new PdfException(e.getMessage(), logDtoUpdate);
}
});
return PdfDto.builder()
.data(dataDtos)
.build();
}
Our issue is the following:
- depending on the original PDF size, signature can take a long time or not occur... We tried it with pdf with different sizes: 5Mo, 10Mo, 20Mo... after this, it becomes very long.
Is there any limitation on pdf size ? and to handle very big files what would be the solution ? Do we need more memory resources ?