You can convert the PDF file to Base64 Binary and wrap it in a container element of type xs:base64Binary
. For example, you can use this schema definition to put your PDF file in an 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 supports the use of fragmented data and rows. 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)
codevour
source share