use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class TrueTypeFont method readStandardString.
/**
* Reads a <CODE>String</CODE> from the font file as bytes using the Cp1252
* encoding.
* @param length the length of bytes to read
* @return the <CODE>String</CODE> read
* @throws IOException the font file could not be read
*/
protected String readStandardString(int length) throws IOException {
byte[] buf = new byte[length];
rf.readFully(buf);
try {
return new String(buf, WINANSI);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class TrueTypeFontSubSet method readStandardString.
/**
* Reads a <CODE>String</CODE> from the font file as bytes using the Cp1252
* encoding.
* @param length the length of bytes to read
* @return the <CODE>String</CODE> read
* @throws IOException the font file could not be read
*/
protected String readStandardString(int length) throws IOException {
byte[] buf = new byte[length];
rf.readFully(buf);
try {
return new String(buf, BaseFont.WINANSI);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfSigGenericPKCS method setSignInfo.
/**
* Sets the crypto information to sign.
* @param privKey the private key
* @param certChain the certificate chain
* @param crlList the certificate revocation list. It can be <CODE>null</CODE>
*/
public void setSignInfo(PrivateKey privKey, Certificate[] certChain, CRL[] crlList) {
try {
pkcs = new PdfPKCS7(privKey, certChain, crlList, hashAlgorithm, provider, PdfName.ADBE_PKCS7_SHA1.equals(get(PdfName.SUBFILTER)));
pkcs.setExternalDigest(externalDigest, externalRSAdata, digestEncryptionAlgorithm);
if (PdfName.ADBE_X509_RSA_SHA1.equals(get(PdfName.SUBFILTER))) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
for (int k = 0; k < certChain.length; ++k) {
bout.write(certChain[k].getEncoded());
}
bout.close();
setCert(bout.toByteArray());
setContents(pkcs.getEncodedPKCS1());
} else
setContents(pkcs.getEncodedPKCS7());
name = PdfPKCS7.getSubjectFields(pkcs.getSigningCertificate()).getField("CN");
if (name != null)
put(PdfName.NAME, new PdfString(name, PdfObject.TEXT_UNICODE));
pkcs = new PdfPKCS7(privKey, certChain, crlList, hashAlgorithm, provider, PdfName.ADBE_PKCS7_SHA1.equals(get(PdfName.SUBFILTER)));
pkcs.setExternalDigest(externalDigest, externalRSAdata, digestEncryptionAlgorithm);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfStamper method close.
/* ssteward omit:
private String getNewSigName() {
AcroFields af = getAcroFields();
String name = "Signature";
int step = 0;
boolean found = false;
while (!found) {
++step;
String n1 = name + step;
if (af.getFieldItem(n1) != null)
continue;
n1 += ".";
found = true;
for (Iterator it = af.getFields().keySet().iterator(); it.hasNext();) {
String fn = (String)it.next();
if (fn.startsWith(n1)) {
found = false;
break;
}
}
}
name += step;
return name;
}
*/
/**
* Closes the document. No more content can be written after the
* document is closed.
* <p>
* If closing a signed document with an external signature the closing must be done
* in the <CODE>PdfSignatureAppearance</CODE> instance.
* @throws DocumentException on error
* @throws IOException on error
*/
public void close() throws DocumentException, IOException {
if (!hasSignature) {
stamper.close(moreInfo);
return;
}
sigApp.preClose();
PdfSigGenericPKCS sig = sigApp.getSigStandard();
PdfLiteral lit = (PdfLiteral) sig.get(PdfName.CONTENTS);
int totalBuf = (lit.getPosLength() - 2) / 2;
byte[] buf = new byte[8192];
int n;
InputStream inp = sigApp.getRangeStream();
try {
while ((n = inp.read(buf)) > 0) {
sig.getSigner().update(buf, 0, n);
}
} catch (SignatureException se) {
throw new ExceptionConverter(se);
}
buf = new byte[totalBuf];
byte[] bsig = sig.getSignerContents();
System.arraycopy(bsig, 0, buf, 0, bsig.length);
PdfString str = new PdfString(buf);
str.setHexWriting(true);
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.CONTENTS, str);
sigApp.close(dic);
stamper.reader.close();
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfWriter method addSimplePattern.
PdfName addSimplePattern(PdfPatternPainter painter) {
PdfName name = (PdfName) documentPatterns.get(painter);
try {
if (name == null) {
name = new PdfName("P" + patternNumber);
++patternNumber;
documentPatterns.put(painter, name);
}
} catch (Exception e) {
throw new ExceptionConverter(e);
}
return name;
}
Aggregations