Box java sdk - download converted file

Go to solution
New Contributor

Box java sdk - download converted file


Here is the flow I am trying to achieve. I am using BOX Java SDK in my application to invoke BOX API.

  1. A bunch of files get uploaded to a folder (monitored by webhook)
  2. Application receives webhook trigger for each FILE (metadata )
  3. If FILE is a non-PDF (RTF, XLS) then convert to PDF
  4. Upload the converted file to BOX to a different folder

My draft implementation is centered around downloading file to local server on which application is running and then use itext/POI to convert non-PDF to PDF and upload PDF version to BOX.

Is there a simpler approach or a solution this ?


Box Employee

Re: Box java sdk - download converted file

Hey @srip,


Apologies for the late reply! The good new is that there is a convenient way to achieve this via the Box API without downloading to local server and converting and re-uploading.


Once a file is uploaded to Box you can fetch different representations of the file you uploaded. You can absolutely retrieve a PDF representation of the file you uploaded. The flow would go roughly as follows:


  1. Upload your file to Box
  2. Make a call to the /representations endpoint with the pdf file type in the x-reps-hint header field.
  3. Get back the pdf representation of your file uploaded.

For step by step on how to do this please refer to our API Reference for Get Representations


This functionality is also implemented in the Box Java SDK. For code example please refer to docs here.

Please note that this is a two part process. Sometimes representations are not available immediately after a file is uploaded. If you are running your script at a later time after you upload then this should not be a problem. However, if you are running your script directly after uploading then you will need to call the `getInfoWithRepresentations(...)` method and check the status for pdf representation, then call `getRepresentationContent(...)` to return an output stream of your pdf file.


If you have any issues please do not hesitate to reach out!

New Contributor

Re: Box java sdk - download converted file

Thanks, carycheng77.
Certainly a much better option than the way I was trying to implement. Will look into it.