Sending your output through a FileWriter is corrupting it because the data is bytes, and FileWriters are for writing characters. All you need is:

OutputStream out = new FileOutputStream("out.pdf");
out.write(bArray);
out.close();
Answer from Jason Orendorff on Stack Overflow
Discussions

Write Byte array into PDF file by java program - Free Support Forum - aspose.com
Hi, I am facing problem whil writing byte data into PDF file. Requirement:- I am reading Byte array from text file and then I want to create pdf file and write the bytes data on same file. The PDF file is created but no data is stored inside file. So, could you please help me how can I solve ... More on forum.aspose.com
🌐 forum.aspose.com
1
0
October 30, 2013
Display byte array back to pdf and display in IE
I get Base64 encoded String for a PDF file. I convert that String to character array. Then I decode it back to byte array. Now, I need to use the byte array to display pdf. I am using a Servlet to display byte array of PDF into IE browser. Correct number of bytes are returned from existing... More on thecodingforums.com
🌐 thecodingforums.com
6
October 20, 2005
convert Byte Array data into pdf file - Oracle Forums
Hello, Can anyone plz tell me how to convert a byte array into pdf file. I have a byte array which contains data, and now I want those data in pdf file. It will be great if anyone can tell me the ste... More on forums.oracle.com
🌐 forums.oracle.com
June 27, 2007
Converting byte Array to PDF - Storage & SAN - Spiceworks Community
Hi, I need to display a report in PDF format.This is how I am doing it I am not sure this is the right way.Please let me know if I am doing something silly. I am running a report through SDK and the outputformat is of type PDF.I am writting the resulting bytes to a file. More on community.spiceworks.com
🌐 community.spiceworks.com
0
November 8, 2006
People also ask

Can HTML content be converted to a PDF using a Java library?
Yes, IronPDF provides the functionality to convert HTML content to PDF documents. It also offers features like adding text and images to PDFs, creating and filling forms, and more.
🌐
ironpdf.com
ironpdf.com › ironpdf for java › ironpdf for java blog › using ironpdf for java › byte array to pdf java
Byte Array to PDF to in Java (Code Example Tutorial) | IronPDF ...
What is the role of a logger in a Java PDF library?
In IronPDF for Java, the SLF4J Simple logger logs status messages to the console, assisting developers in debugging and monitoring the application.
🌐
ironpdf.com
ironpdf.com › ironpdf for java › ironpdf for java blog › using ironpdf for java › byte array to pdf java
Byte Array to PDF to in Java (Code Example Tutorial) | IronPDF ...
Is there a free trial available for Java PDF libraries?
Yes, IronPDF offers a free trial version that allows developers to test its features, such as converting up to 20 pages of a PDF document, before committing to a purchase.
🌐
ironpdf.com
ironpdf.com › ironpdf for java › ironpdf for java blog › using ironpdf for java › byte array to pdf java
Byte Array to PDF to in Java (Code Example Tutorial) | IronPDF ...
🌐
Free Support Forum
forum.groupdocs.com › groupdocs.conversion product family
Byte array to PDF conversion in Java - Free Support Forum - groupdocs.com
November 11, 2019 - Hi Team, My requirement is that we have a byte[] (byte array) and i want it to convert pdf but io am not getting such code that fulfill my requirement. Please help to provide me sample code for byte array to pdf convers…
🌐
Mkyong
mkyong.com › home › java › java – how to convert file to byte[]
Java - How to convert File to byte[] - Mkyong.com
September 17, 2020 - Anyway, I am not able to make it work with a PDF file. The copied file is completely blank. Do you have a way to make this work ? With other file types is working fine. Thanks !!! 0 · Reply · Noor Hossain · 3 years ago · can I create bytes [] of database files, like mydb.db file · 0 · Reply · m asad · 3 years ago · hello , can you please help me I am converting bytes array to audio file but it is not working? 0 · Reply · Java – How to save byte[] to a file ·
🌐
Coderanch
coderanch.com › t › 363548 › java › converting-byte-array-pdf
converting byte array to pdf (Servlets forum at Coderanch)
October 26, 2006 - I want to show the pdf in web browser ... />SCJP 1.4 (100%)<br />SCWCD 1.4 (98%)<br />SCBCD 1.3 (Preparing) ... set the content type ("application/pdf") and content length headers and then just send the bytes....
🌐
Aspose
forum.aspose.com › aspose.total product family
Write Byte array into PDF file by java program - Free Support Forum - aspose.com
October 30, 2013 - Hi, I am facing problem whil writing byte data into PDF file. Requirement:- I am reading Byte array from text file and then I want to create pdf file and write the bytes data on same file. The PDF file is created but…
Find elsewhere
🌐
e-iceblue
e-iceblue.com › Tutorials › Java › Spire.PDF-for-Java › Program-Guide › Conversion › java-convert-byte-array-to-pdf.html
Java Convert Byte Array to PDF: Load & Create with Spire. ...
Learn how to convert byte arrays to PDF in Java using Spire.PDF. Covers loading PDF bytes, creating PDFs from text bytes, and common pitfalls.
🌐
The Coding Forums
thecodingforums.com › archive › archive › java
Display byte array back to pdf and display in IE | Java | Coding Forums
October 20, 2005 - Source src = new StreamSource(new StringReader(xmlSource)); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // NOTA: Al transformar a PDF, se me escribe en el ByteArrayOutputStream automaticamente // el contenido de la transformacion, asi que ya no es nulo, sino que es el array de Bytes del PDF.
🌐
Javathinking
javathinking.com › blog › convert-byte-array-to-pdf-in-java
Convert Byte Array to PDF in Java | JavaThinking.com
July 1, 2025 - To convert a byte array to a PDF, you need to write the contents of the byte array to a file with the .pdf extension. Java provides several ways to perform file I/O operations, such as using the FileOutputStream class.
🌐
Narkive
itext-questions.narkive.com › V4j6BEpA › reg-conversion-of-byte-array-into-pdf
[iText-questions] Reg: Conversion of byte array into PDF
I wrote java code using itext to generate pdf and convert it into byte array as follows: I took simple Hello world program to generate the pdf and convert it into byte array public byte[] createReportPdfGeneration()throws DocumentException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // step 1: creation of a document-object Document document = new Document(PageSize.A4); // step 2: CREATING WRITER // we'll create the file in memory PdfWriter writer = PdfWriter.getInstance(document, baos); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World!")); // step 5 document.close(); }catch (Exception e) { System.out.println("error="+e); e.printStackTrace(); } return baos.toByteArray(); } The output of this program is a byte array.
🌐
Blogger
myjavaprogramming.blogspot.com › 2011 › 09 › convert-byte-array-to-pdf-in-java.html
My Java Works: Convert Byte Array to PDF in java
September 27, 2011 - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; public class TestPDF { public static void main(String[] args) throws FileNotFoundException { Test obj = new Test(); boolean result = obj.savePDF(); System.out.println("Result of Saving PDF : "+result); obj.getPDF(); } public boolean savePDF() throws FileNotFoundException{ File file = new File("c:/Java/Input_File.pdf");
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-byte-array-to-file-using-java
Convert byte[] array to File using Java - GeeksforGeeks
July 11, 2025 - Java Collection · Last Updated ... order to convert a byte array to a file, we will be using a method named the getBytes() method of String class....
🌐
GitHub
gist.github.com › aliahmedbd › e53beea2ca71e207fecae848e46a14ae
How to download PDF from byte array or byte stream - Android · GitHub
How to download PDF from byte array or byte stream - Android · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Base64.Guru
base64.guru › home › developers › java › examples
Convert Base64 to PDF in Java | Examples | Java | Developers | Base64
To convert a Base64 string to PDF file in Java you have to use the Base64.Decoder class and any convenient way to write a byte array to file (it is important to note that Base64.getDecoder().decode() returns a byte array, not a string).
🌐
Coderanch
coderanch.com › t › 599219 › java › converting-byte-array-pdf-string
converting byte array of a pdf into a string (Java in General forum at Coderanch)
Unless what you are looking for is very simple (in which case, you will have to parse through the raw byte array), it may be a good idea to use a pdf parser. There are some java libraries out on the net.
🌐
Rustam Mehmandarov
mehmandarov.com › generating-pdf-files-using-java
Generating PDF Files Using Java | Rustam Mehmandarov
June 21, 2019 - Now you can either save the document ...ream.toByteArray(): // save and close document ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); document.save(byteArrayOutputStream); document.close(); // return document ...
🌐
Oracle
forums.oracle.com › ords › apexds › post › convert-byte-array-data-into-pdf-file-0972
convert Byte Array data into pdf file - Oracle Forums
June 27, 2007 - Hello, Can anyone plz tell me how to convert a byte array into pdf file. I have a byte array which contains data, and now I want those data in pdf file. It will be great if anyone can tell me the ste...
🌐
Spiceworks
community.spiceworks.com › hardware & infrastructure › storage & san
Converting byte Array to PDF - Storage & SAN - Spiceworks Community
November 8, 2006 - Hi, I need to display a report in PDF format.This is how I am doing it I am not sure this is the right way.Please let me know if I am doing something silly. I am running a report through SDK and the outputformat is of type PDF.I am writting the resulting bytes to a file.