How to view a pdf file generated in databricks

4.4k views Asked by At

I tried generating a sample pdf file using the below code. I believe a pdf has been generated, but I can't view it. How can I view this pdf and how to export it. I am new to databricks. Please help to find a solution. Thanks

from fpdf import FPDF

class PDF(FPDF):    
  pass

pdf = PDF()          
pdf.add_page()            
pdf.output('test.pdf','F')          
pdf_w=210       
pdf_h=297      

class PDF(FPDF):          
    def lines(self):         
        self.rect(5.0, 5.0, 200.0,287.0)

 
1

There are 1 answers

0
Alex Ott On

When you using such commands the file will be created on the local filesystem, and will be destroyed when you terminate the cluster. To prevent that, you can put the file onto the Databricks File System (DBFS), for example, as /dbfs/mnt/..../file.pdf - after that file could be retrieved using databricks-cli, or something like this. (The /dbfs/ mount doesn't work on community edition with DBR 7.+!)

Another way to dbutils.fs.cp command to copy local file to DBFS, like:

dbutils.fs.cp("file:/path/to/file.pdf", "dbfs:/my.file.pdf")