开发者

send pdf file in xml message [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Upd开发者_StackOverflow社区ate the question so it focuses on one problem only by editing this post.

Closed 2 years ago.

Improve this question

I want to send a pdf file within a xml message. How do I do that in java? What data type do I use in the schema?


You can transform the PDF file to Base64 Binary and wrap this into a container Element with type xs:base64Binary. For example you could use this schema definition to place your PDF file in the xml message.

<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>

You can use org.apache.commons.codec.binary.Base64 for this approach if you already have commons-codec in your project. It support use of chunked data and strings. For example:

// 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)


I suggest you to use bytes array in some tag. For example:

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

You can use JAXB to create the xml file automatically from the object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜