Reputation: 15
How to convert PDDocument (the pdf document contains words and images, if it is possible) to a Base64 string?
Upvotes: 0
Views: 4048
Reputation: 18851
The answer assumes that you are using jdk8 or higher, if not, please see here.
import java.util.Base64;
...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos);
String base64String = Base64.getEncoder().encodeToString(baos.toByteArray());
doc.close(); // don't forget to close your document
Upvotes: 6