这是我的代码
<script>
var body = "dddddd"
var script = "<script>window.print();</scr'+'ipt>";
var newWin = $("#printf")[0].contentWindow.document;
newWin.open();
newWin.close();
$("body",newWin).append(body+script);
</script>
<iframe id="printf"></iframe>
Run Code Online (Sandbox Code Playgroud)
这可以,但它打印父页面,我如何让它只打印iframe?
如何使用JavaScript将PDF文件直接发送到打印机?
我在论坛中找到了两个答案:
<embed src="vehinvc.pdf" id = "Pdf1" name="Pdf1" hidden>
<a onClick="document.getElementById('Pdf1').printWithDialog()" style="cursor:hand;">Print file</a>
Run Code Online (Sandbox Code Playgroud)
和
<OBJECT id = "Pdf2" name="Pdf2" CLASSID="clsid:CA8A9780-280D-11CF-A24D-444553540000" WIDTH="364" HEIGHT="290">
<PARAM NAME='SRC' VALUE="file.pdf">
</OBJECT>
<a onClick="document.Pdf2.printWithDialog()">Print file</a>
Run Code Online (Sandbox Code Playgroud)
但我的问题是它只适用于IE,并且在Firefox或Chrome中无效.
这有什么解决方案吗?
在Web应用程序中,是否可以强制在客户端上打印PDF文件?如果浏览器配置为在窗口内打开PDF,我想调用window.print()会起作用,但是某些浏览器(比如我的)被配置为在外部打开PDF.
我有一个"打印"按钮,可以调用以下JavaScript
window.frames.myPdfFrame.print();
Run Code Online (Sandbox Code Playgroud)
其中"myPdfFrame"指的是带有src的PDF的iframe.
在Chrome和Firefox 18(及以下版本)中,这会按预期打开打印对话框,但从Firefox 19开始,我收到以下错误
Error: Permission denied to access property 'print'
Run Code Online (Sandbox Code Playgroud)
我认为这与使用Firefox 19而不是Adobe插件发布的嵌入式PDF查看器有关.使用PDF插件工具栏中的打印图标按预期工作.
有没有办法从Javascript调用Firefox 19中的内联PDF中的打印对话框?
我目前正在浏览器的新选项卡中打开pdf文件,但我需要知道如何在按下commandButton后打开打印机对话框来打印pdf jasper报告
这是在新选项卡中打开pdf的方法:
public void printJasper() {
JasperReport compiledTemplate = null;
JRExporter exporter = null;
ByteArrayOutputStream out = null;
ByteArrayInputStream input = null;
BufferedOutputStream output = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
try {
List<String> sampleList = new ArrayList<String>();
sampleList.add("Fist sample string");
sampleList.add("Second sample string");
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(sampleList);
Map<String, Object> reportValues = new HashMap<String, Object>();
reportValues.put("anyTestValue", "test value");
facesContext = FacesContext.getCurrentInstance();
externalContext = facesContext.getExternalContext();
response = (HttpServletResponse) externalContext.getResponse();
FileInputStream file …Run Code Online (Sandbox Code Playgroud)