[
https://issues.apache.org/jira/browse/PDFBOX-4437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16751295#comment-16751295
]
Tilman Hausherr commented on PDFBOX-4437:
-----------------------------------------
Yeah, I was wrong when I wrote "Your current code likely ignores the SMask
component" because when running it with the previous code the smask appeared,
sorry. Your new code is much better!
I also wrote code to parse the hex stuff, sorry for pointing you to the Hex
class. I'll commit it, until then here it is:
{code:java}
/**
* Decodes a hex String into a byte array.
*
* @param s A String with ASCII hex.
* @return decoded byte array.
* @throws IOException
*/
public byte[] decodeHex(String s) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < s.length() - 1; i += 2)
{
String hexByte = s.substring(i, i + 2);
try
{
baos.write(Integer.parseInt(hexByte, 16)); //
Byte.parseByte won't work
}
catch (NumberFormatException ex)
{
LOG.error("Can't parse " + hexByte + ", aborting decode",
ex);
break;
}
}
return baos.toByteArray();
}
{code}
And for base64 use this (call new String(result) or
ByteArrayInputStream(result) in your work); I need it a return a byte array for
another part of PDFBox. In theory, this should work for you on jdk6.
{code:java}
/**
* Decode a base64 String.
*
* @param base64Value a base64 encoded String.
*
* @return the decoded String as a byte array.
*
* @throws IllegalArgumentException if this isn't a base64 encoded string.
*/
public byte[] decodeBase64(String base64Value) throws
IllegalArgumentException
{
// https://stackoverflow.com/questions/469695/decode-base64-data-in-java
try
{
// jdk8 and higher? java.util.Base64.getDecoder().decode()
Class<?> b64Class = Class.forName("java.util.Base64");
Method getDecoderMethod = b64Class.getMethod("getDecoder");
Object base64Decoder = getDecoderMethod.invoke(b64Class);
Method decodeMethod = base64Decoder.getClass().getMethod("decode",
String.class);
return (byte[]) decodeMethod.invoke(base64Decoder,
base64Value.replaceAll("\\s", ""));
}
catch (ReflectiveOperationException ex)
{
LOG.debug(ex);
}
catch (SecurityException ex)
{
LOG.debug(ex);
}
try
{
// up to java7? javax.xml.bind.DatatypeConverter.parseBase64Binary()
Class<?> datatypeConverterClass =
Class.forName("javax.xml.bind.DatatypeConverter");
Method parseBase64BinaryMethod =
datatypeConverterClass.getMethod("parseBase64Binary", String.class);
return (byte[]) parseBase64BinaryMethod.invoke(null, base64Value);
}
catch (ReflectiveOperationException ex)
{
LOG.debug(ex);
}
catch (SecurityException ex)
{
LOG.debug(ex);
}
LOG.error("Can't decode base64 value, try adding
javax.xml.bind:jaxb-api to your build");
return new byte[0];
}
{code}
> Import XFDF stamp annotation loses appearance
> ---------------------------------------------
>
> Key: PDFBOX-4437
> URL: https://issues.apache.org/jira/browse/PDFBOX-4437
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 2.0.9, 2.0.10, 2.0.11, 2.0.12, 2.0.13
> Reporter: Andrew Hung
> Priority: Major
> Attachments: A1.01 - MYLES - 2ND-4TH FLOOR PLAN.pdf,
> FDFAnnotationStamp.java, FDFAnnotationStamp2.java,
> FDFAnnotationStampAppearance_final.java, FDFAnnotationStamp_final.java,
> Stamp_appearance_decoded.txt, ap.xml, example.zip, stamp_annotation.xfdf,
> xfdf stamp annotation to PDF.zip
>
>
> When loading an XFDF which has a stamp annotation which contains an
> appearance element after added to the PDF in place of the annotation is an
> box with an X.
> Reviewing the FDFAnnotationStamp class, it skips all internal elements. Is
> there any development being done to enhance this?
> I've attached "xfdf stamp annotation to PDF.zip" which has an example, if you
> open the stamp_annot.xfdf it will show on the PDF. While using PDFBox API
> the only piece missing is the appearance of the stamp.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]