[SOLVED]Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

[SOLVED]Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by Kunda1 »

issue #0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground
Opening thread to generate discussion
Last edited by Kunda1 on Wed May 10, 2017 6:21 pm, edited 1 time in total.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by Kunda1 »

wandererfan wrote:....
@wandererfan do u mind weighing in on this when u have a moment?
Kunda1 wrote:issue #0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground
Opening thread to generate discussion
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by wmayer »

obj = FreeCAD.ActiveDocument.getObject("Page001")
FreeCADGui.export([obj], u"/tmp/Page001.pdf")
FreeCADGui.export is part of the core system and thus doesn't know anything about objects of extension modules. This function gets the object to check which document it is part of and then simply uses the active view of this document and export that as pdf. See https://github.com/FreeCAD/FreeCAD/blob ... y.cpp#L528

So to achieve what you want there are some alternatives how to realize it:
* add a function to the Py interface of TechDrawGui that accepts a DrawPage object and path name. Inside this function can access the correct mdi page via the view provider and export the content as pdf
* another way could be to implement a specialized Python wrapper for the view provider that offers the needed interface for export
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by yorik »

Implementing a TechDraw-specific PDF export might not be too hard... Something in the same mold as the current SVG export: https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L556 but that uses a QPrinter instead of the QSvgGenerator, it seems to basically work the same way (paint in it with a QPainter).

http://stackoverflow.com/questions/1609 ... f#16095317
http://www.qtcentre.org/threads/47972-R ... export-PDF
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by sgrogan »

For reference the bug report evolved from this thread. https://forum.freecadweb.org/viewtopic.php?f=22&t=21384
"fight the good fight"
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Ticket 0002972: TechDraw PDF export from Python can only make PDFs of a Page in foreground

Post by wandererfan »

yorik wrote:Implementing a TechDraw-specific PDF export might not be too hard
Part of the solution is already there:

void MDIViewPage::printPdf();
(pops up a dialog to ask for a file. would need to add a parm for file path.)

- and -

MDIViewPage* ViewProviderPage::getMDIViewPage();

Will try to slide this into the next update.
Post Reply