Java
Chilkat2 Java
Extract PDF from JSON
See more JSON Examples
Demonstrates how to extract a PDF file contained within JSON. The file is represented as a base64 string within the JSON. Note: This example can extract any type of file, not just a PDF file.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
JsonObject json = new JsonObject();
// Load the JSON.
try {
json.loadFile("qa_data/json/JSR5U.json");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
StringBuilder sb = new StringBuilder();
json.stringOfSb("data.content", sb);
BinData bd = new BinData();
bd.appendEncodedSb(sb, "base64");
bd.writeFile("qa_output/a0015.pdf");
}
}