我正在尝试在谷歌应用引擎上使用 xhtml2pdf 生成 PDF。我已经完成了大部分工作,包括将图像嵌入到模板中。但是,这只适用于可公开访问的图像(xhtml2pdf 蚀刻图像以嵌入它们。)我需要能够将一些图像保密。因此,我希望能够使用 data uri 方案将一些图像直接嵌入到 html 中。可悲的是,当我这样做时出现错误:
有问题的html标签是:
<img src='data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACPAOYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4%2BTl5ufo6erx8vP09fb3%2BPn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3%2BPn6/9oADAMBAAIRAxEAPwD3%2BiiigAooooAKKKKACiiigAooooAKKKKACii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igAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP//Z' width='230' height='143' >
我得到的错误是:
Traceback (most recent call last):
File "/Users/hamish/dev/kp3/src/libs/xhtml2pdf/tags.py", line 332, in start
height=None)
File "/Users/hamish/dev/kp3/src/libs/xhtml2pdf/xhtml2pdf_reportlab.py", line 476, in __init__
img = self.getImage()
File "/Users/hamish/dev/kp3/src/libs/xhtml2pdf/xhtml2pdf_reportlab.py", line 497, in getImage
img = PmlImageReader(StringIO.StringIO(self._imgdata))
File "/Users/hamish/dev/kp3/src/libs/xhtml2pdf/xhtml2pdf_reportlab.py", line 343, in __init__
self._image = self._read_image(self.fp)
File "/Users/hamish/dev/kp3/src/libs/xhtml2pdf/xhtml2pdf_reportlab.py", line 373, in _read_image
return PILImage.open(fp)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file fileName=<StringIO.StringIO instance at 0x10503ca70>