I'm trying to create pdf documents on the fly in an application, i.e. a user clicks a link and a pdf document is displayed to them with some text and some images.
I'm currently using FPDF v1.6 (http://www.fpdf.org/) which supports 24bit (true colour) png's but the problem I have is that this is a legacy application and there's 1000's of png's that are of 16bit colour depth which FPDF does not support and I can't simply convert due to other parts of the application using these images.
The only solutions I see are:
- convert the 16bit png image on the fly and embed that into the pdf.
- find a开发者_Go百科 new class pdf class that will accept 16bit colour depth png's.
Anyone have any ideas?
Maybe you could try using TCPDF (never used it with 16bit PNGs but it should be easy to test it).
Fixed with this in python:
def fix_16_bit_depth_not_supported(raw_image_path):
"""
fix
RuntimeError: FPDF error: 16-bit depth not supported: test.png
"""
new_file, filename = tempfile.mkstemp(suffix='.png')
os.close(new_file)
i = cv2.imread(raw_image_path, cv2.IMREAD_UNCHANGED)
img = np.array(i, dtype=np.float32)
convert = img / 255.
cv2.imwrite(filename, convert)
return filename
精彩评论