0

How to convert PDDocument (the pdf document contains words and images, if it is possible) to Base64 String? Is there any suggestion of code. Please.

1 Answers1

5

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
Tilman Hausherr
  • 16,148
  • 6
  • 57
  • 91