// Save diagram as PNG
val options = ImageSaveOptions(SaveFileFormat.PNG)
options.pageIndex = 0
previewFile.outputStream().use { outputStream ->
document.save(outputStream, options)
}
But on Linux I get this error:
ERROR 2019-01-24 10:15:35,864 [.p6diagram.web.shims.CallableFactoryImpl: 107] | Thread-3 | {} | Error generating diagram
java.lang.IllegalStateException: Cannot find resource {0}.
at com.aspose.diagram.a.c.q.a(Unknown Source)
at com.aspose.diagram.a.d.ba.i(Unknown Source)
at com.aspose.diagram.a.d.ba.g(Unknown Source)
at com.aspose.diagram.a.d.ba.d(Unknown Source)
at com.aspose.diagram.a.d.bc.a(Unknown Source)
at com.aspose.diagram.a.d.bc.a(Unknown Source)
at com.aspose.diagram.a.d.bc.a(Unknown Source)
at com.aspose.diagram.mb.(Unknown Source)
at com.aspose.diagram.fn.a(Unknown Source)
at com.aspose.diagram.fn.b(Unknown Source)
at com.aspose.diagram.fn.a(Unknown Source)
at com.aspose.diagram.fn.a(Unknown Source)
at com.aspose.diagram.om.a(Unknown Source)
at com.aspose.diagram.om.a(Unknown Source)
at com.aspose.diagram.Diagram.a(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at com.emerald_associates.p6diagram.engine.diagram_writer.visio.aspose.AsposeEngine.savePngPreviewFile(AsposeEngine.kt:142)
at com.emerald_associates.p6diagram.engine.diagram_writer.visio.aspose.AsposeEngine.savePngPreviewFile(AsposeEngine.kt:41)
at com.emerald_associates.p6diagram.engine.diagram_writer.visio.engines.gantt.GanttChartDiagramEngine.generateDiagram(GanttChartDiagramEngine.kt:59
)
at com.emerald_associates.p6diagram.engine.DiagramGeneratorShim.generateDiagram(DiagramGeneratorShim.kt:89)
at com.emerald_associates.p6diagram.web.shims.CallableFactoryImpl$CloudApiToVisio.call(CallableFactoryImpl.kt:90)
at com.emerald_associates.p6diagram.web.shims.CallableFactoryImpl$CloudApiToVisio.call(CallableFactoryImpl.kt:71)
at com.emerald_associates.async_tasks.TaskEntry.call(TaskEntry.java:144)
at com.emerald_associates.async_tasks.TaskManagerImpl.runTask(TaskManagerImpl.java:196)
at com.emerald_associates.async_tasks.TaskManagerImpl.access$500(TaskManagerImpl.java:34)
at com.emerald_associates.async_tasks.TaskManagerImpl$ExecutorThread.run(TaskManagerImpl.java:231)
public static void main( String[] args ) throws Exception
{
final License license = new License();
final File licenseFile = new File( "user-data/visio-files/Aspose.Diagram.lic" );
try( final InputStream is = new FileInputStream( licenseFile ) ) {
license.setLicense( is );
}
final Diagram diagram;
final File diagramFile = new File( "user-data/aspose-tickets/preview.vsdx" );
try( final InputStream is = new FileInputStream( diagramFile ) ) {
diagram = new Diagram( is );
}
final File pictureFile = new File( "user-data/aspose-tickets/preview.png" );
// Save diagram as PNG
final ImageSaveOptions ops = new ImageSaveOptions( SaveFileFormat.PNG );
ops.setPageIndex( 0 );
try( final OutputStream os = new FileOutputStream( pictureFile ) ) {
diagram.save( os, ops );
}
}
Please remember that this must be executed on a Linux server and that the DISPLAY environment variable must be set to NULL, and that no display should be available. If there is a DISPLAY available I suspect the code will work. The file referenced from the ticket is this: preview.zip (35.1 KB)
We have tested the scenario in Linux environment (Ubuntu 15.04) and were unable to notice the exception which you have shared. Would you kindly share a sample application and detailed steps to reproduce the issue you are experiencing. We will again test the scenario in our environment and address it accordingly.
An investigation ticket as DIAGRAMJAVA-50653 has been logged in our issue tracking system for further investigation over this issue. We have associated it with your post so that you will receive notification once significant updates are available regarding its resolution. Please spare us little time.