Elderl23 / pyfpdf

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

"ouput" has default/hard-coded fonts location - throws I/O exception when different location used #76

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am using pyinstaller (www.pyinstaller.org/‎) to convert my python script to 
an EXE file. The EXE works on the computer where it was generated (which had 
fpdf) but when I try running this EXE file on a different computer, the 
pdf.output() function keeps throwing an I/O exception - error code 2 - and says 
"No such file or directory: 
C:\\Python27\\lib\\site-packages\\fpdf\\font\\DejaVuSans-Bold.ttf". This is in 
line 906 of fpdf.py, in output. "font" is the folder (same location as my main 
Python script) which contains the font-files when I execute my script in Python.

What is the expected output? What do you see instead?
Expected to see PDF file printing on all computers that the EXE is run on. 
What is seen: I/O exception -error 2 - no such file or directory - when 
pdf.output() is called.

What version of the product are you using? On what operating system?
Windows 7, PyFPDF 1.7.1

Please provide any additional information below.
Code snippet and traceback attached.

"font" is the folder where I stored the font I needed. "fonts" is the folder 
within fpdf.

add_font and set_font don't seem to throw an error. Only output seems to have 
the path for fonts set by default to fpdf/fonts/

Original issue reported on code.google.com by venmathi...@gmail.com on 23 Apr 2014 at 12:11

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
traceback

Original comment by venmathi...@gmail.com on 23 Apr 2014 at 12:18

Attachments:

GoogleCodeExporter commented 8 years ago
First, remove any .pkl file hanging around that can have your development path 
hardcoded in the cache temporary files where font metrics are stored.

If the problem persist, you could use a function like get_install_dir() that 
returns the base path of your app:

https://code.google.com/p/pyafipws/source/browse/utils.py#751

Then you can try:

app_path = get_install_dir()
font_path = os.path.join(app_path, 'font')
pdf.add_font('DejaVuB','', os.path.join(font_path, 
'DejaVuSans-Bold.ttf'),uni=True)

Make sure you're packaging the font folder with the ttf files)

Original comment by reingart@gmail.com on 25 Apr 2014 at 9:47

GoogleCodeExporter commented 8 years ago
btw, fpdf already has options for pkl managing, for example in portable or 
readonly installations you can disable font caching.
More deatails here https://code.google.com/p/pyfpdf/wiki/AddFont

Original comment by romiq...@gmail.com on 7 Jan 2015 at 12:12