Hi,
Thanks for the code segment and details.
I have tested your scenario/ case using the following sample code with a simple template Excel file and it works fine. I first get the Excel file into byte array first. The output PDF file is fine tuned.
e.g
Sample code:
byte[] data = FileUtils.readFileToByteArray(new File("f:\files\Book_new1.xlsx"));
ByteArrayInputStream inStream = new ByteArrayInputStream(data);
final Workbook doc = new Workbook(inStream);
// Save the modified document into out stream
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.PDF);
//You can then get the PDF document back into the InputStream as follows
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
inputStream.close();
// Use this to convert the stream to a .pdf file
final OutputStream outputStream = new FileOutputStream("f:/files/out1" + ".pdf");
IOUtils.copy(inputStream, outputStream);
outputStream.close();
The template Excel file and output PDF files are attached.
Thank you.
When I import your .xlsx I still get the same problem and I can’t open the pdf. I am using the latest aspose cells version.
Hi,
Hi
This is the code I used:
final java.io.File f = new java.io.File(“c:\files\Book_new1.xlsx”);
final byte[] data2 = FileUtils.readFileToByteArray(f);
final ByteArrayInputStream inStream = new ByteArrayInputStream(data2);
final Workbook doc = new Workbook(inStream);
// Save the modified document into out stream
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.PDF);
// You can then get the PDF document back into the InputStream as follows
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
inputStream.close();
// Use this to convert the stream to a .pdf file
final OutputStream outputStream = new FileOutputStream(“c:/files/out1” + “.pdf”);
IOUtils.copy(inputStream, outputStream);
outputStream.close();
Still no result, I tried opening the pdf in another reader, same problem. When I change the extension to .xlsx it obviously works.
Hi,
That is really strange as I used the exact code (just changed the file path) as shown below and it works absolutely fine. Please find attached the output PDF file for your reference. Please open it into acrobat reader if you find any issue with the file.
e.g
Sample code:
final java.io.File f = new java.io.File(“f:\files\Book_new1.xlsx”);
final byte[] data2 = FileUtils.readFileToByteArray(f);
final ByteArrayInputStream inStream = new ByteArrayInputStream(data2);
final Workbook doc = new Workbook(inStream);
// Save the modified document into out stream
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.PDF);
// You can then get the PDF document back into the InputStream as follows
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
inputStream.close();
// Use this to convert the stream to a .pdf file
final OutputStream outputStream = new FileOutputStream("f:/files/out1" + ".pdf");
IOUtils.copy(inputStream, outputStream);
outputStream.close();
(Please note, for “IOUtils” class used in the code, I set its class path using Apache Commons IO 2.5 API i.e., “commons-io-2.5.jar” and have imported all the classes using the statement: “import org.apache.commons.io.*;” into my JAVA program at the start. )
Thank you.
jvra:Hi Can you attach the .java file you used and send it to me? I don't know if the imports and the io utils can be the problem.
Please find it attached.Thank you.