Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a pdf from file
#1
I have been working on getting my program to make a PDF of all the data in various widgets. I have been able to get the data and it does create a PDF file however the formatting is not correct. I need to learn know how to make the lines of the populated widget but the PDF made has a line of data for each widget and the widgets that have a larger amount of data is posted one a single line.

As an example, this code should look like below:
  ;======================================
  ;-Program: GOJHL v2.1
  ; Language: Pure Basic
  ; Written by: John Jr.
  ; Date: April 08, 2016
  ; Copyright 2014-2016
But it saves in the PDF as:
;====================================== ;-Program: GOJHL v2.1 ; Language: Pure Basic ; Written by: John Coones Jr. ; Date: April 08, 2016 ; Copyright 2014-2016

Here is my current PDF code:
def makePDF():
    try:
        pdf=FPDF(orientation='P', unit='mm', format='A3')
        pdf.add_page()
        pdf.set_font("Arial", size = 10)
        pdf.cell(200, 10, txt = "PBSnippet",
                 ln = 1, align = 'L')

        f = (Code_Type.get(), Snippet_Name.get(), Code_Snippet.get('1.0', END), Description.get('1.0',END), Date.get(), Author.get(), Version.get())

        for x in f:
            pdf.cell(200, 10, txt = x, ln = 1, align = 'L')

        pdf.output("PBSnippet.pdf")

    except:
        messagebox.showerror('PBSnippet', 'Failed to create the PDF!')
The data from Description and Code_Snippet are multiple lines and are displaying as a single line as shown above.
A little help to get the data to save in PDF as it shows in the widget would be appreciated.

Thanks again.
"Often stumped... But never defeated."
Reply
#2
Hi, I tried this code on my computer:
from fpdf import FPDF
    
pdf = FPDF(orientation='P', unit='mm', format='A3')
pdf.add_page()
pdf.set_font("Arial", size = 10)
pdf.cell(200, 10, txt = "PBSnippet",ln = 1, align = 'L')
 
f = (";======================================", ";-Program: GOJHL v2.1", "; Language: Pure Basic", "; Written by: John Jr.", "; Date: April 08, 2016", "; Copyright 2014-2016")
for x in f:
    pdf.cell(200, 10, txt = x, ln = 1, align = 'L')
 
pdf.output("PBSnippet.pdf")
and output:
Quote:PBSnippet
;======================================
;-Program: GOJHL v2.1
; Language: Pure Basic
; Written by: John Jr.
; Date: April 08, 2016
; Copyright 2014-2016


Are you sure that you execute exactly code witn ln=1?
Which version of fpdf do you have? 1.7.2 ?
Reply
#3
I believe it is version 1.7.2, I installed it last evening.

The problem is that I am getting the data using the ".get()" method from the widgets and not typing it into the "f =" directly.
Even if I use only 1 of the widget and make the PDF it then puts 1 letter per line instead of a single row of text for each
.get()
"Often stumped... But never defeated."
Reply
#4
Quote:The data from Description and Code_Snippet are multiple lines and are displaying as a single line as shown above
Please provide example for multiple lines.

What kind of widgets they are? Tkinter? WxWidgets? I tried to mix f content with empty '', something with '\n' inside and everytime have output line after line. It's interesting :)
Reply
#5
I am writing it with tkinter and they at Listbox.
The data is coming from 7 widgets in total.
5 Entry widgets - (Date, Author, Snippet_Name, Version, Code_Type)
2 Listbox widgets - (Code_Snippet, Description)
"Often stumped... But never defeated."
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,384 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Creating csv files from Excel file azizrasul 40 5,721 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Creating file with images BobSmoss 1 1,398 Jan-08-2022, 08:46 PM
Last Post: snippsat
  Creating csv file from another file pisike 0 1,612 Nov-24-2020, 02:02 PM
Last Post: pisike
  Creating Conda env from requirments.txt file ErnestTBass 7 15,759 Apr-23-2020, 06:57 PM
Last Post: snippsat
  Internal Server Error 500 on creating .py file patrickluethi 0 1,764 Aug-02-2019, 01:57 PM
Last Post: patrickluethi
  Creating Dictionary form LOG /text file DG1234 7 5,494 Feb-13-2019, 08:08 PM
Last Post: DG1234
  error creating new object after loading pickled objects from file arogers 2 3,462 Feb-02-2019, 10:43 AM
Last Post: Larz60+
  File creating with question mark quffix pythonbabe 2 2,847 Nov-23-2018, 12:05 PM
Last Post: pythonbabe
  Creating a delimited file from DB Table anubhav2020 9 7,135 Sep-19-2018, 05:22 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020