Skip to content

Commit e67cecf

Browse files
author
Célian Haydont
committed
Add functions to export a wiki article as a PDF
1 parent f9fb988 commit e67cecf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

dataikuapi/dss/wiki.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,31 @@ def get_uploaded_file(self, upload_id):
247247
"""
248248
return self.client._perform_raw("GET", "/projects/%s/wiki/%s/uploads/%s" % (self.project_key, self.article_id, upload_id))
249249

250+
def get_export_stream(self, paperSize="A4", exportChildren=False):
251+
"""
252+
Download an article in PDF format as a binary stream.
253+
Warning: this stream will monopolize the DSSClient until closed.
254+
"""
255+
body = {
256+
"paperSize": paperSize,
257+
"exportChildren": exportChildren
258+
}
259+
return self.client._perform_raw("POST", "/projects/%s/wiki/%s/actions/export" % (self.project_key, self.article_id), body=body)
260+
261+
def export_to_file(self, path, paperSize="A4", exportChildren=False):
262+
"""
263+
Download an article in PDF format into the given output file.
264+
"""
265+
stream = self.export(paperSize=paperSize, exportChildren=exportChildren)
266+
267+
with open(path, 'wb') as f:
268+
for chunk in stream.iter_content(chunk_size=10000):
269+
if chunk:
270+
f.write(chunk)
271+
f.flush()
272+
stream.close()
273+
274+
250275
def delete(self):
251276
"""
252277
Delete the article

0 commit comments

Comments
 (0)