简体   繁体   English

在 Salesforce 中呈现为 PDF 的 Visualforce 页面中未显示的 HTML 元素

[英]HTML elements not displaying in the Visualforce Page rendered as PDF in Salesforce

In Salesforce: I have printed a Barcode using the SVG tag in the Visualforce Page.在 Salesforce 中:我在 Visualforce 页面中使用 SVG 标签打印了一个条码。 But, when the Visualforce Page is rendered as a pdf using the 'renderAs' attribute of the component, the Barcode doesn't show up!但是,当 Visualforce 页面使用组件的“renderAs”属性呈现为 pdf 时,条形码不会显示!

 <apex:page renderAs="pdf" sidebar="false" showHeader="false" applyBodyTag="false"> <head> <script src="http://cdn.jsdelivr.net/jsbarcode/3.6.0/JsBarcode.all.min.js"></script> <script></script> </head> <body> <svg id="barcodesvg" >Hello World!</svg> <!-- style="width:80px; height:25px;" --> </body> <script> JsBarcode("#barcodesvg", "Hey World!"); console.log(JsBarcode("#barcodesvg", "Hey World!")); </script> </apex:page>

Been a week working over it.经过一周的努力。 Any help would be greatly appreciated!任何帮助将不胜感激!

Visualforce's render to PDF uses (or at least used to) Java library called Flying Saucer . Visualforce 的 PDF 渲染使用(或至少习惯于)称为Flying Saucer 的Java 库。 There's no browser as such, no JavaScript engine to run your code.没有这样的浏览器,没有 JavaScript 引擎来运行您的代码。

You'd have to generate the barcode different way.您必须以不同的方式生成条形码。 Look for JavaScript libraries able to prerender your image & save it as PNG attachment for example, then use it in VF.寻找能够预渲染图像并将其保存为 PNG 附件的 JavaScript 库,例如,然后在 VF 中使用它。 Or if it's a relatively simple barcode you could maybe do the calculations in Apex and display it in pure html as series of black & white <span> s (should be easy to find sample implementations for Java or .NET that have syntax not too different from Apex... or even use that JavaScript's source code as inspiration).或者,如果它是一个相对简单的条形码,您可以在 Apex 中进行计算并以纯 html 显示它作为一系列黑白<span> s(应该很容易找到语法不太不同的 Java 或 .NET 示例实现来自 Apex ......或者甚至使用 JavaScript 的源代码作为灵感)。 Or maybe call another server that can generate images, maybe put your own instance of https://github.com/zxing/zxing somewhere (Heroku?) and call that for images.或者也许调用另一个可以生成图像的服务器,也许将你自己的https://github.com/zxing/zxing实例放在某个地方(Heroku?)并调用它来获取图像。

If you can live without the real Visualforce renderAs="pdf" (forget about using this in email templates, atatchments, any kind of server code that for example generates file in SF and uploads somewhere) then it can stay JavaScript.如果您可以没有真正的 Visualforce renderAs="pdf"(忘记在电子邮件模板、附件、任何类型的服务器代码中使用它,例如在 SF 中生成文件并上传到某处),那么它可以保留 JavaScript。 Instruct users how to print the page to PDF or maybe you'll have luck with https://github.com/MrRio/jsPDF指导用户如何将页面打印为 PDF 或者你可能会幸运地使用https://github.com/MrRio/jsPDF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM