Seite 1 von 1

xhtml2pdf kann Schrift nicht öffnen

Verfasst: Freitag 14. Oktober 2022, 09:43
von damaris89
Hallo,

Ich versuche seit längeren eine Schrift in das PDF einzubauen. Allerdings gelingt es einfach nicht. Ich bekomme immer folgende Meldung:

Code: Alles auswählen

TTFError
Exception Value:	Can't open file "C:\Users\damar\AppData\Local\Temp\tmpzdxz26a4.ttf"


Wie kann man das ändern: hier der Code im HTML

Code: Alles auswählen

	@font-face {
      font-family: 'rockwell';
      src: url('digit_trauerbild_app/static/fonts/rockwell.ttf') format("truetype");
    }
    
Weiß jemand wo der Fehler liegt?
Danke für Antworten

Re: xhtml2pdf kann Schrift nicht öffnen

Verfasst: Sonntag 16. Oktober 2022, 11:00
von __blackjack__
@damaris89: Funktionieren andere Schiftarten?

Da es eine temporäre Datei betrifft: Kann es sein, dass da ein Virenscanner zuschlägt und die Datei geöffnet hat, und damit verhindert, dass das Programm die benutzen kann?

Wie sieht der komplette Traceback aus?

Re: xhtml2pdf kann Schrift nicht öffnen

Verfasst: Freitag 21. Oktober 2022, 09:39
von damaris89
Danke, Es funktioniert leider mit keiner Schrift. Hab auch die unterschiedlichsten Pfade probiert. Dieser ist der einzige bei dem das Programm überhaupt eine Reaktion zeigt.

TTFError at /chinavirus/inserate_app/todesanzeigemodel/
Can't open file "C:\Users\damar\AppData\Local\Temp\tmp7nv3awe9.ttf"
Request Method: POST
Request URL: http://www.mysite.local:8000/chinavirus ... eigemodel/
Django Version: 3.2
Exception Type: TTFError
Exception Value:
Can't open file "C:\Users\damar\AppData\Local\Temp\tmp7nv3awe9.ttf"
Exception Location: C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 161, in TTFOpenFile
Python Executable: C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\Scripts\python.exe
Python Version: 3.8.0
Python Path:
['C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube',
'C:\\Users\\damar\\AppData\\Local\\Programs\\Python\\Python310\\python38.zip',
'C:\\Users\\damar\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
'C:\\Users\\damar\\AppData\\Local\\Programs\\Python\\Python310\\lib',
'C:\\Users\\damar\\AppData\\Local\\Programs\\Python\\Python310',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf',
'C:\\Users\\damar\\OneDrive\\Desktop\\stellanube\\stellanube\\myvenv\\lib\\site-packages\\odf']
Server time: Fri, 21 Oct 2022 10:36:15 +0200
Traceback Switch to copy-and-paste view
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 523, in open_for_read
return open_for_read_by_name(name,mode) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 463, in open_for_read_by_name
return open(name,mode) …
▶ Local vars
During handling of the above exception ([Errno 13] Permission denied: 'C:\\Users\\damar\\AppData\\Local\\Temp\\tmp7nv3awe9.ttf'), another exception occurred:
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 530, in open_for_read
return BytesIO((datareader if name[:5].lower()=='data:' else rlUrlRead)(name)) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 476, in rlUrlRead
return urlopen(name).read() …
▶ Local vars
C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\urllib\request.py, line 222, in urlopen
return opener.open(url, data, timeout) …
▶ Local vars
C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\urllib\request.py, line 525, in open
response = self._open(req, data) …
▶ Local vars
C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\urllib\request.py, line 547, in _open
return self._call_chain(self.handle_open, 'unknown', …
▶ Local vars
C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\urllib\request.py, line 502, in _call_chain
result = func(*args) …
▶ Local vars
C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\urllib\request.py, line 1388, in unknown_open
raise URLError('unknown url type: %s' % type) …
▶ Local vars
During handling of the above exception (<urlopen error unknown url type: c>), another exception occurred:
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 151, in TTFOpenFile
f = open_for_read(fn,'rb') …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 534, in open_for_read
return open_for_read(name,mode) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\lib\utils.py, line 532, in open_for_read
raise IOError('Cannot open resource "%s"' % name) …
▶ Local vars
During handling of the above exception (Cannot open resource "C:\Users\damar\AppData\Local\Temp\tmp7nv3awe9.ttf"), another exception occurred:
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\core\handlers\exception.py, line 47, in inner
response = get_response(request) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\contrib\admin\options.py, line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\utils\decorators.py, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\views\decorators\cache.py, line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\contrib\admin\sites.py, line 232, in inner
return view(request, *args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\utils\decorators.py, line 43, in _wrapper
return bound_method(*args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\utils\decorators.py, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\contrib\admin\options.py, line 1721, in changelist_view
response = self.response_action(request, queryset=cl.get_queryset(request)) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\django\contrib\admin\options.py, line 1406, in response_action
response = func(self, request, queryset) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\inserate_app\admin.py, line 24, in inserat_pdf_erzeugen
element.generate_pdf_inserat() …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\inserate_app\models.py, line 191, in generate_pdf_inserat
pdf = render_to_pdf('digit_trauerbild_app/pdf/inserat_pdf_template.html', {'obj':self,'media_root':media_root, …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\inserate_app\models.py, line 35, in render_to_pdf
pdf = pisa.pisaDocument(html.encode("UTF-8"), result ,encoding='UTF-8') …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\document.py, line 116, in pisaDocument
context = pisaStory(src, path, link_callback, debug, default_css, xhtml, …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\document.py, line 68, in pisaStory
pisaParser(src, context, default_css, xhtml, encoding, xml_output) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\parser.py, line 794, in pisaParser
context.parseCSS() …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\context.py, line 481, in parseCSS
self.css = self.cssParser.parse(self.cssText) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\w3c\cssParser.py, line 443, in parse
src, stylesheet = self._parseStylesheet(src) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\w3c\cssParser.py, line 545, in _parseStylesheet
src, atResults = self._parseAtKeyword(src) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\w3c\cssParser.py, line 667, in _parseAtKeyword
src, result = self._parseAtFontFace(src) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\w3c\cssParser.py, line 843, in _parseAtFontFace
result = [self.cssBuilder.atFontFace(properties)] …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\context.py, line 176, in atFontFace
self.c.loadFont(names, src, …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\xhtml2pdf\context.py, line 853, in loadFont
file = TTFont(fullFontName, filename) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 1178, in __init__
self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 1072, in __init__
TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 439, in __init__
TTFontParser.__init__(self, file, validate=validate,subfontIndex=subfontIndex) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 175, in __init__
self.readFile(file) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 251, in readFile
self.filename, f = TTFOpenFile(f) …
▶ Local vars
C:\Users\damar\OneDrive\Desktop\stellanube\stellanube\myvenv\lib\site-packages\reportlab\pdfbase\ttfonts.py, line 161, in TTFOpenFile
raise TTFError('Can\'t open file "%s"' % fn) …
▶ Local vars