We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

BinaryDocument to PDF Conversion

Hi,


I’m new to java .
I need to convert a binary document to PDF.
Attached is the Binary Document for reference.
Can some one tell me sample code for this conversion.
here is the sample code which i have written till now

File aFile = new File(“D:\binary/documentBinary.bin”);
byte[] buf = new byte[(int) aFile.length()];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Document pdfDocument = new Document();
FileInputStream inFile = null;
try {
inFile = new FileInputStream(aFile);
} catch (FileNotFoundException e) {
e.printStackTrace(System.err);
}
try {
for (int readNum; (readNum = inFile.read(buf)) != -1;)
{
bos.write(buf, 0, readNum); //no doubt here is 0
System.out.printf("%10d",readNum);
}
} catch (IOException ex) {
Logger.getLogger(genJpeg.class.getName()).log(Level.SEVERE, null, ex);
}
byte[] bytes = bos.toByteArray();
// Write to file
File someFile = new File(“D:\binary/test.pdf”);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(someFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}

try {
fos.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}

}
}
}

Thanks…

Hi,


Thank you for contacting support. Aspose.Pdf for Java API does not recognize the format of your input file (.bin). All supported file formats are listed on the product page: Aspose.Pdf for Java API. Please also refer to this help topic: Convert a file to PDF format

Hi,

We are not getting the source file as .bin but the pdf data is inserted into a table column as binary with the document name as abc.pdf
So how can we do this.

Hi,


Thank you for the details. You can retrieve the binary content from a file, and then insert into the table cells or you may embed a binary file into the PDF document. Kindly refer to these help topics: Working with Attachments and Add and Extract a Table

A single line of code to create a Java string from the content of a file:
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>String content = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> String(Files.readAllBytes(Paths.get(“d://test.txt”)));
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>

No what I meant to say is,I’m picking the binary document from a particular column in a table which has the document name as .PDF


Which I need to extract and convert into PDF and send it to the target.

Hi,


Thank you for the details. Kindly send us your source PDF and let us know which binary data you are looking to extract. We require complete details of your scenario (step by step). As per our understanding, we will then extract the binary data and convert it to the PDF format. Finally, you will send this output PDF to the target. Your response is awaited.