Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send pdf file in xml message [closed]

Tags:

java

xml

pdf

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?

like image 595
martin Avatar asked Dec 23 '10 09:12

martin


People also ask

How do I send a PDF in XML?

Four steps for converting your PDF to XML.Use the Select tool to mark the content you want to save. Right-click the highlighted text. Choose Export Selection As. Select XML, and slick Save.

How do I open an XML PDF?

Choose File > Open. Locate and select the XML file you want to use. Click Open.

How do I make an XML file readable?

XML files are encoded in plaintext, so you can open them in any text editor and be able to clearly read it. Right-click the XML file and select "Open With." This will display a list of programs to open the file in. Select "Notepad" (Windows) or "TextEdit" (Mac).

Does PDF use XML?

PDF is not XML. To generate PDF from XML, use XSLT to convert the XML to XSL:FO, which can then be rendered to PDF by an XSL-FO processor such as Apache FOP, Antenna House, or RenderX.


2 Answers

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)
like image 157
Christopher Klewes Avatar answered Oct 18 '22 07:10

Christopher Klewes


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.

like image 37
Vladimir Ivanov Avatar answered Oct 18 '22 06:10

Vladimir Ivanov