1818 my_report.visualize()
1919"""
2020import sys
21+ from typing import Optional
2122import webbrowser
2223
2324from ansys .dynamicreporting .core .adr_utils import in_ipynb
@@ -182,7 +183,7 @@ def get_iframe(self, width: int = 1000, height: int = 800):
182183 import ansys.dynamicreporting.core as adr
183184 adr_service = adr.Service(ansys_installation = r'C:\\ Program Files\\ ANSYS Inc\\ v232')
184185 ret = adr_service.connect()
185- my_report = adr_service.get_report(report_name = "My Top Report"
186+ my_report = adr_service.get_report(report_name = "My Top Report")
186187 report_iframe = my_report.get_iframe()
187188 """
188189 if "IPython.display" in sys .modules :
@@ -191,3 +192,126 @@ def get_iframe(self, width: int = 1000, height: int = 800):
191192 else :
192193 iframe = None
193194 return iframe
195+
196+ def export_pdf (
197+ self ,
198+ file_name : str = "" ,
199+ query : Optional [dict ] = None ,
200+ page : Optional [list ] = None ,
201+ delay : Optional [int ] = None ,
202+ ) -> bool :
203+ """
204+ Export report as PDF. Currently works only with a local ADR installation, and
205+ not a docker image.
206+
207+ Parameters
208+ ----------
209+ file_name : str
210+ Path and filename for the PDF file to export.
211+ query : dict, optional
212+ Dictionary for query parameters to apply to report template before export. Default: None
213+ page : list, optional
214+ List of integers that represents the size of the exported pdf. Default: None, which
215+ corresponds to A4 size
216+ delay : int, optional
217+ Seconds to delay the start of the pdf export operation. Default: None, which
218+ corresponds to no delay
219+
220+ Returns
221+ -------
222+ bool
223+ Success status of the PDF export: True if it worked, False otherwise
224+
225+ Examples
226+ --------
227+ ::
228+
229+ import ansys.dynamicreporting.core as adr
230+ adr_service = adr.Service(ansys_installation = r'C:\\ Program Files\\ ANSYS Inc\\ v232')
231+ ret = adr_service.connect()
232+ my_report = adr_service.get_report(report_name = "My Top Report")
233+ succ = my_report.export_pdf(file_name=r'D:\\ tmp\\ myreport.pdf')
234+ """
235+ success = False # pragma: no cover
236+ if self .service is None : # pragma: no cover
237+ self .service .logger .error ("No connection to any report" )
238+ return ""
239+ if self .service .serverobj is None : # pragma: no cover
240+ self .service .logger .error ("No connection to any server" )
241+ return ""
242+ try :
243+ if query is None :
244+ query = {}
245+ self .service .serverobj .export_report_as_pdf (
246+ report_guid = self .report .guid ,
247+ file_name = file_name ,
248+ query = query ,
249+ page = page ,
250+ parent = None ,
251+ delay = delay ,
252+ exec_basis = self .service ._ansys_installation ,
253+ ansys_version = self .service ._ansys_version ,
254+ )
255+ success = True
256+ except Exception as e : # pragma: no cover
257+ self .service .logger .error (f"Can not export pdf report: { str (e )} " )
258+ return success
259+
260+ def export_html (
261+ self ,
262+ directory_name : str = "" ,
263+ query : Optional [dict ] = None ,
264+ filename : Optional [str ] = "index.html" ,
265+ no_inline_files : Optional [bool ] = False ,
266+ ) -> bool :
267+ """
268+ Export report as static HTML.
269+
270+ Parameters
271+ ----------
272+ directory_name : str
273+ ....
274+ query : dict, optional
275+ Dictionary for query parameters to apply to report template before export. Default: None
276+ filename : str, optional
277+ Filename for the exported static HTML file. Default: index.html
278+ no_inline_files : bool, optional
279+ If True, the information is exported as stand alone files instead of in line content
280+ in the static HTML. Default: False
281+
282+ Returns
283+ -------
284+ bool
285+ Success status of the HTML export: True if it worked, False otherwise
286+
287+ Examples
288+ --------
289+ ::
290+
291+ import ansys.dynamicreporting.core as adr
292+ adr_service = adr.Service(ansys_installation = r'C:\\ Program Files\\ ANSYS Inc\\ v232')
293+ ret = adr_service.connect()
294+ my_report = adr_service.get_report(report_name = "My Top Report")
295+ succ = my_report.export_html(directory_name = r'D:\\ tmp')
296+ """
297+ success = False
298+ if self .service is None : # pragma: no cover
299+ self .service .logger .error ("No connection to any report" )
300+ return ""
301+ if self .service .serverobj is None : # pragma: no cover
302+ self .service .logger .error ("No connection to any server" )
303+ return ""
304+ try :
305+ if query is None :
306+ query = {}
307+ self .service .serverobj .export_report_as_html (
308+ report_guid = self .report .guid ,
309+ directory_name = directory_name ,
310+ query = query ,
311+ filename = filename ,
312+ no_inline_files = no_inline_files ,
313+ )
314+ success = True
315+ except Exception as e : # pragma: no cover
316+ self .service .logger .error (f"Can not export static HTML report: { str (e )} " )
317+ return success
0 commit comments