I have been banging my head against a wall on this all day. I have a PDF file that we generate. The PDF file looks fine in Acrobat.
I need to encode the file in base64. Using Apache codec library I do this:
String base64buf = Base64.encodeBase64String( m_reportText.getBytes( "UTF-8" ) );
As a test I write base64buf out to a file:
Files.write( new File( "report.b64" ).toPath(), base64buf.getBytes( "UTF-8") );
Then I convert it back, just to see if it is working:
String encodedName = "report.b64";
String decodedName = "report.pdf";
// Read original file.
byte[] encodedBuffer = Files.readAllBytes( new File( encodedName ).toPath() );
// Decode
byte[] decodedBuffer = Base64.decodeBase64( encodedBuffer );
// Write out decodedBuffer.
FileOutputStream outputStream = new FileOutputStream( decodedName );
outputStream.write( decodedBuffer );
outputStream.close();
I open report.pdf in Acrobat and it is a blank document. It has the correct number of pages (all are blank).
What am I missing here?