Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I installed the fpdf python package in a code env.
I created a python notebook and I run this code
import fpdf
from fpdf import FPDF
# Create instance of FPDF class
pdf = FPDF()
# Add a page
pdf.add_page()
# Set font
pdf.set_font("Arial", size = 15)
# Add a cell
pdf.cell(200, 10, txt = "Hello", ln = True, align = 'C')
# Save the pdf with name .pdf
pdf.output("report.pdf")
Where does report.pdf go?
Hi @DataAnalyst24 ,
By default, it will be the current working directory of the notebook e.g cwd
You can read it from the notebook using the relative path "report.pdf".
What you probably need to do is simply store this in a managed folder instead.
You can use upload_file for example:
folder_id = "FOLDER_ID"
folder = dataiku.Folder(folder_id)
# Get the current working directory
cwd = os.getcwd()
# Specify the filename of the PDF file
pdf_filename = "report.pdf"
local_file_path = os.path.join(cwd, pdf_filename)
destination_filename = "uploaded_report.pdf"
#upload the file to the Dataiku managed folder
folder.upload_file(destination_filename, local_file_path)
Hi @DataAnalyst24 ,
By default, it will be the current working directory of the notebook e.g cwd
You can read it from the notebook using the relative path "report.pdf".
What you probably need to do is simply store this in a managed folder instead.
You can use upload_file for example:
folder_id = "FOLDER_ID"
folder = dataiku.Folder(folder_id)
# Get the current working directory
cwd = os.getcwd()
# Specify the filename of the PDF file
pdf_filename = "report.pdf"
local_file_path = os.path.join(cwd, pdf_filename)
destination_filename = "uploaded_report.pdf"
#upload the file to the Dataiku managed folder
folder.upload_file(destination_filename, local_file_path)
When I run
cwd = os.getcwd()
I get this error
11 # folder.upload_file(destination_filename, local_file_path) ---> 12 cwd = os.getcwd() 13 display(cwd) NameError: name 'os' is not defined
How do I define os?
Hi,
You will need to add
import os
import dataiku
At the top of the script.
Thank you @AlexT !
Your solution works. I can see the PDF in the folder now.
Do you also know other alternatives where I can build a PDF and immediately see a preview of the PDF document I am creating?