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.

user7327905
  • 15
  • 1
  • 5

1 Answers1

6

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
  • 17,731
  • 7
  • 58
  • 97