[
https://issues.apache.org/jira/browse/PDFBOX-2942?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14709742#comment-14709742
]
Diego Rodrigues Azevedo commented on PDFBOX-2942:
-------------------------------------------------
{code}
public class PdfBoxRunner {
private CryptoDevice contUsuario;
public PdfBoxRunner(CryptoDevice contUsuario) {
// TODO Auto-generated constructor stub
this.contUsuario = contUsuario;
}
public void sign(String pathIn, String pathOut) {
try {
PDDocument doc = PDDocument.load(new File(pathIn));
FileOutputStream fos = new FileOutputStream(new
File(pathOut));
// create signature dictionary
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName(contUsuario.getUserCertificates()[0].getCertificateChain()[0].getSubject().getFirst(X509Principal.COMMON_NAME));
signature.setLocation("Location");
signature.setReason("Reason");
// TODO extract the above details from the signing certificate?
Reason as a parameter?
// the signing date, needed for valid signature
signature.setSignDate(Calendar.getInstance());
// register signature dictionary and sign interface
doc.addSignature(signature, new SigningAux(contUsuario));
// write incremental (only for signing purpose)
//doc.saveIncremental(new FileInputStream(pathIn), fos);
doc.saveIncremental(fos);
//doc.save(new File(pathOut));
//doc.save(fos);
doc.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
{code}
I use a proprietary library to create the signed hash, and can't post their
code here =/
> Can't sign particular PDF
> -------------------------
>
> Key: PDFBOX-2942
> URL: https://issues.apache.org/jira/browse/PDFBOX-2942
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel, Signing
> Affects Versions: 2.0.0
> Environment: Java 1.8.0_51
> Maven 3.2.5
> PDFBox 2.0.0-SNAPSHOT
> Reporter: Diego Rodrigues Azevedo
> Attachments: report-poc-signed.pdf, report-poc.pdf
>
>
> I couldn't sign this particular PDF using pdfbox. I could sign bigger PDFs,
> so it's not about the size. Whenever I sign it, and try to open with adobe
> reader, it says "there was a problem opening this pdf", but it opens the
> unsigned version immediately. I'm using version 2.0.0-SNAPSHOT
> I think it's because the pdf does not have a xref table. That's the only
> difference I could find with other signable pdfs.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]