2010-12-23 41 views

回答

12

THX您可以将PDF文件转换为Base64二进制与xs:base64Binary型包装成一个容器元素这一点。例如,您可以使用此架构定义将PDF文件放入xml消息中。

<xs:complexType name="documentType"> 
<xs:sequence> 
    <xs:element minOccurs="0" name="mimetype" type="xs:string" /> 
    <xs:element minOccurs="0" name="filename" type="xs:string" /> 
    <xs:element name="content" type="xs:base64Binary" /> 
</xs:sequence> 
</xs:complexType> 

您可以使用org.apache.commons.codec.binary.Base64这种方法,如果你已经在你的项目有commons-codec。它支持使用分块数据和字符串。例如:

// You can read in the PDF file with FileReader and get the bytes 
// Please obey that this solution must be improved for large pdf files 

Base64.encodeBase64(binaryData, true) 
+0

thx,正是我在找的! – martin 2010-12-23 09:23:10

1

我建议你在某些标签中使用字节数组。例如:

<file> 
    <name>Test.pdf</name> 
    <content>here are the bytes of the file</content> 
</file> 

您可以使用JAXB从对象中自动创建xml文件。