I have implemented a direct printing to files of some GMF diagrams. The diagrams are opened, printed to file and the diagrams then closed. The issue I am facing is withing the following point:
private static void printDiagrams(IEditorPart editorPart,org.eclipse.gmf.runtime.diagram.ui.printing.internal.util.SWTDiagramPrinter
diagramPrinter,String diagName) {
PrinterData printData = new PrinterData("winspool","PDFCreator");
if(printData!=null)
{
printData.printToFile = true;
printData.fileName = "D:\\"+diagName+".pdf";
printData.scope= 0;
final Printer printer = new Printer(printData);
diagramPrinter.setPrinter(printer);
diagramPrinter.setDisplayDPI(Display.getDefault().getDPI());
diagramPrinter.setFitToPage(true);
DiagramEditPart dgrmEP = ((DiagramEditor) editorPart).getDiagramEditPart();
assert dgrmEP != null;
diagramPrinter.setDiagrams(Collections.singletonList(((DiagramEditor) editorPart).getDiagram()));
diagramPrinter.run();
printer.dispose();
}
The issue is that with the above code I receive error during opening of pdf file. " Acrobat Reader could not open ... .pdf because it is either not supported file type or because the file has been damaged"
Tried also to put a sleep to be sure that printing is finished before disposing the printer. Same error in the end occured.
Any hint is helpful.