我有一个用例,我必须在pdf上显示动态图像。我正在使用PDF生成的FApacheFOP 2.1。我从API调用中获取图像行,然后将该图像转换为基本64格式。使用xslfo和FOP 2.1无法在PDF中看到base64图像
请找到Java COE转换图像:
String jpgFileName = ConfigManager.getImageFilePath() + "/jpgImage-"+System.currentTimeMillis()+".jpg";
Blob imageDataBlob = (Blob) faesRow.get("imageData");
FileUtil.writeToFile(imageDataBlob, jpgFileName);
String base64Result = Base64.getEncoder().encodeToString(FileUtil.readFromFile(jpgFileName).getBytes("utf-8"));
result = base64Result;
我正在使用XSLFO的base64数据类型上打印PDF格式的图像,请在下面找到XSLFO,这里$ signatureImage是发送的数据上面的java代码:
<xsl:param name="Name">data:image/jpg;base64,{$!signatureImage}</xsl:param>
<fo:block-container absolute-position="absolute" left="3.50in" top="9.25in" width="4.0in" height="2.0in">
<fo:block text-align="left">
<fo:external-graphic content-width="scale-to-fit"
content-height="100%"
width="100%"
scaling="uniform"
src="url({$Name})"/>
</fo:block>
</fo:block-container>
在模板渲染的输出中,我可以在xslfo文件中获取base64流。请找到下面的输出:
<xsl:param name="Name">data:image/jpg;base64,{77+977+977+977+9ABBK... }</xsl:param>
<fo:block-container absolute-position="absolute" left="3.50in" top="9.25in" width="4.0in" height="2.0in">
<fo:block text-align="left">
<fo:external-graphic content-width="scale-to-fit"
content-height="100%"
width="100%"
scaling="uniform"
src="url({$Name})"/>
</fo:block>
</fo:block-container>
现在的问题是,图像没有得到定价生成的PDF输出。 您可以帮我找到一种在这里打印图片的方法。
额外信息: 1.我没有得到任何错误生成PDF。 2. PDF能够打印静态图像和条形码。
内容类型不应该是image/jpeg而不是image/jpg?另外,b64字符串周围的{}看起来对我很可疑。 –
我尝试过使用jpeg并删除{}。但是没有运气,它没有显示图像。它看起来像问题是与base64转换,但不知道是什么问题。 –
当我做你的“base64”数据77 + 977 + 977 + 977 + 9ABB的base64解码...它以0xef 0xbf 0xbd 0xef开头......这似乎不是一个jpeg文件,它将以0xff 0xd8开头,可能接着是0xff 0xe0。看起来对我来说是错误的... –