Ich nutze FPDF https://code.google.com/p/pyfpdf/ zum erstellen eines PDF Dokumentes mit Python.
jetzt will ich ein logo einfügen was das folgenden Fehler Produziert
das Logo ist eine PNG Datei und kann auch mit GIMP normal geöffnet und angesehen werden.Traceback (most recent call last):
File "Z:\ProgrammEntwicklung\Python3.3\tk_fraese\pdf_bestellung_offen.py", line 33, in <module>
pdf.image('logo.png',20,20,33,33)
File "Z:\ProgrammEntwicklung\Python3.3\tk_fraese\fpdf\fpdf.py", line 896, in image
info=self._parsepng(name)
File "Z:\ProgrammEntwicklung\Python3.3\tk_fraese\fpdf\fpdf.py", line 1642, in _parsepng
self.error('Not a PNG file: '+name)
File "Z:\ProgrammEntwicklung\Python3.3\tk_fraese\fpdf\fpdf.py", line 221, in error
raise RuntimeError('FPDF error: '+msg)
RuntimeError: FPDF error: Not a PNG file: logo.png
hier der Programm Code
Code: Alles auswählen
from fpdf import FPDF
import time
import os
class PDF(FPDF):
def header(this):
this.image('logo.png',20,20,33,33) # Logo einfügen
this.set_font('Courier','B',16)
this.text(15,15,'Bestellung ' + time.strftime("%d.%m.%Y"))
this.set_author('Verwaltung')
this.set_title('Bestellung')
# Tabellen Spalten Überschriften setzen
this.set_font('Courier','B',10)
this.text(10,30,"Menge")
this.text(25,30,"Ein.")
this.text(40,30,"Bezeichnung")
this.text(110,30,"Artikel")
this.text(110,35,"Bestell")
this.text(175,30,"Hersteller")
this.text(175,35,"Lieferant")
this.text(250,30,"Kostenstelle")
this.line(10,36,292,36) # Zeile Begin,Linke Höhe,Zeile ende,Rechte Höhe
def footer(this):
this.set_font('Courier','',8)
this.text(15,200,'Verwaltung Fräse - Free FPDF für Python')
this.text(250,200,time.strftime("%d.%m.%Y %H:%M:%S"))
pdf=PDF('L','mm','A4')
pdf.compress=False
pdf.add_page()
pdf.set_font('Courier','',13)
pdf.output('bestellung.pdf')
os.startfile('bestellung.pdf')verwendet wird Python 3.3.2 und FPDF 1.7
PDf erstellung ohne "Image" funktioniert ohne Probleme
Danke im Voraus
Peter
