0

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.

Ankur
  • 5,086
  • 19
  • 37
  • 62

1 Answers1

0

Figured it out that the generated file was not pdf at all , but prn file, intermediate files that a printer is storing before converting to final output. The after creating the prn files a conversion to the desired format is needed, in my case to pdf.

Hope this will help somebody also. Cheers.