
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert PDF to Byte Array in Java
You can read data from a PDF file using the read() method of the FileInputStream class this method requires a byte array as a parameter.
Example
import java.io.File; import java.io.FileInputStream; import java.io.ByteArrayOutputStream; public class PdfToByteArray { public static void main(String args[]) throws Exception { File file = new File("sample.pdf"); FileInputStream fis = new FileInputStream(file); byte [] data = new byte[(int)file.length()]; fis.read(data); ByteArrayOutputStream bos = new ByteArrayOutputStream(); data = bos.toByteArray(); } }
Sample.pdf
Advertisements