I’ve worked a simple Unit Test to convert a very simple Xlsx document to PDF. The test seams to work ok, but when I try to open the generated document, I get the following message (Mac Preview):
The file “converted.pdf” could not be opened.
It may be damaged or use a file format that Preview doesn’t recognize.
The Unit Test is as follows:
public void doIt() throws FileNotFoundException, FileFormatException
<span style=“font-family: “Courier New”;”>{
String file = “/sampledocs/contracts.xlsx”;
String converted = “testoutputs/converted.pdf”;
InputStream in = this.getClass().getResourceAsStream(file);
OutputStream out = new FileOutputStream(converted);
xlsxToPdf(in, out);
<span style=“font-family: “Courier New”;”>}
public void xlsxToPdf(InputStream inputStream, OutputStream outputStream) throws FileFormatException
{
try
{
Workbook wb = new Workbook(inputStream);
wb.save(outputStream, SaveFormat.PDF);
}
catch (Exception e)
{
throw new FileFormatException(“Failed to convert file from XLSX to PDF (using Aspose)”, e);
}
}
Like stated, no error messages are displayed, and all seams to be working fine.
Some enviroment info:
Using Java API v16.12.0
From Maven
Running on OSX El Capitan
In file (simplest.xlsx) and out (converted.pdf) annexed in issue
Thanks