diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 57b290bd..fe761904 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -9975,11 +9975,11 @@ class App(QtCore.QObject): flt = "All Files (*.*)" if obj.kind == 'gerber': - flt = "Gerber Files (*.GBR);;All Files (*.*)" + flt = "Gerber Files (*.GBR);;PDF Files (*.PDF);;All Files (*.*)" elif obj.kind == 'excellon': - flt = "Excellon Files (*.DRL);;All Files (*.*)" + flt = "Excellon Files (*.DRL);;PDF Files (*.PDF);;All Files (*.*)" elif obj.kind == 'cncjob': - "GCode Files (*.NC);;All Files (*.*)" + flt = "GCode Files (*.NC);;PDF Files (*.PDF);;All Files (*.*)" self.source_editor_tab = TextEditor(app=self, plain_text=True) diff --git a/README.md b/README.md index d8f09119..17043df2 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ CAD program, and create G-Code for Isolation routing. - maximum range for Cut Z is now zero to deal with the situation when using V-shape with tip-dia same value with cut width - modified QValidator in FCDoubleSpinner() GUI element to allow entering the minus sign when the range maximum is set as 0.0; also for positive numbers allowed entering the symbol plus - made sure that if in Gerber UI the isolation is made with a V-Shape tool then the tool type is automatically updated on the generated Geometry Object +- added ability to save the Source File as PDF (still have to adjust the page size) 16.12.2019 diff --git a/flatcamEditors/FlatCAMTextEditor.py b/flatcamEditors/FlatCAMTextEditor.py index 11113183..02c6ec19 100644 --- a/flatcamEditors/FlatCAMTextEditor.py +++ b/flatcamEditors/FlatCAMTextEditor.py @@ -217,9 +217,42 @@ class TextEditor(QtWidgets.QWidget): else: try: my_gcode = self.code_editor.toPlainText() - with open(filename, 'w') as f: - for line in my_gcode: - f.write(line) + if filename.rpartition('.')[2].lower() == 'pdf': + from reportlab.platypus import SimpleDocTemplate, Paragraph + from reportlab.lib.styles import getSampleStyleSheet + from reportlab.lib.units import inch + + if self.app.defaults['units'].upper() == 'MM': + dims = self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']] + else: + dims = ( + self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][0] / 25.4, + self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][1] / 25.4 + ) + + styles = getSampleStyleSheet() + styleN = styles['Normal'] + styleH = styles['Heading1'] + story = [] + + doc = SimpleDocTemplate( + filename, + pagesize=dims, + bottomMargin=0.4 * 72, + topMargin=0.6 * 72, + rightMargin=0.8 * 72, + leftMargin=0.8 * 72) + + P = Paragraph(my_gcode, styleN) + story.append(P) + + doc.build( + story, + ) + else: + with open(filename, 'w') as f: + for line in my_gcode: + f.write(line) except FileNotFoundError: self.app.inform.emit('[WARNING] %s' % _("No such file or directory")) return