I'm using wicked_pdf
to render a PDF-File. The Web-App runs in chrome with kiosk-mode (--kiosk --kiosk-printing). The problem is that i have to open the print-dialog when the PDF is rendered, so that the PDF is printed automatically via kiosk.
I tried this with the Javascript-function window.print();
in my PDF-/HTML-Template. But the function is not executed and no print-dialog is opened.
Here my controller-method (materials_stocks_controller.rb):
def create
@material = Manufacturer::MaterialsStock.new(params[:manufacturer_materials_stock])
respond_to do |wants|
if @material.save
@materials = Manufacturer::MaterialsStock.ordered_collection
wants.js { render :layout => false }
wants.pdf {
render :pdf => "Material-Barcode",
:template => 'manufacturer/material_info',
:show_as_html => !params[:debug].blank?,
:page_height => 62,
:page_width => 110,
:margin => {
:top => 3,
:bottom => 3,
:left => 0,
:right => 3
},
:use_xserver => false,
:print_media_type => true,
"load-error-handling"=> "ignore"
}
else
raise "Unable to create material in stock"
end
end
end
The view (material_info.pdf.erb):
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script>
function printing_dialog() {
window.print();
}
</script>
</head>
<body onload="printing_dialog()">
<!-- stuff ... -->
</body>
</html>
Has anyone an idea how to open the print-dialog?
Thanks!! :)
Update:
I replaced the template-code completely with the page-number-JS-Code from the wicked_pdf-Docu and the JS is not running was well:
new Code in material_info.pdf.erb (for testing):
<html>
<head>
<script>
function number_pages() {
var vars={};
var x=document.location.search.substring(1).split('&');
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
for(var i in x) {
var y = document.getElementsByClassName(x[i]);
for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script>
</head>
<body onload="number_pages()">
Page <span class="page"></span> of <span class="topage"></span>
</body>
</html>