Automatic printing PDF programmatically in IE6 - javascript

I would like to be able to print a PDF document automatically when a user clicks on a print button. Currently what the way I am doing it is I render the PDF and save to the server disk and have it appear in an iframe then I tried to print the content of the iframe using javascript:print(). however what is printed is an empty html page.
I am doing this because using the norm HTML print is wrecking the layout of the webpage i am trying to print. so i'm rendering the page to a pdf format to print the webpage. i don't want the users to be able to save the pdf hence i am trying to slient print the pdf page. hence i am loading it in an iframe by changing the src in the code behind and re-rendering the page and then triggering the js script.
function printPDF(){
document.iframe_printArea.focus();
document.iframe_printArea.print();
}
I am wondering if it is possible to print a pdf document loaded in an iframe using print() or whether this is even possible. I have extensively googled on this and have yet to come up with any solutions that works for a web application. Most of the resources are devoted to C# windows app. The platform I am using is .NET C#.

First of all I'm very sorry for whom that have to deal with IE6.
There is an non-standard DOM event developed by Microsoft that fire before print. It's onbeforeprint event (docs). What you can do is hiding everything but the iframe and shrink the iframe to the window size before print. and after print reverse the document to normal statues with onafterprint event.
function window.onbeforeprint()
{
// hide other elements and shrink the iframe
}
function window.onafterprint()
{
// unde what heppened onbeforeprint
}

Related

Print PDF.JS without print btn

I can see a pdf.js document in a digital viewer. Is it possible to print it without seeing a print button or the hotkey?
If I print with the browser function of printing, its just that one page, that I see.
I need it without the whole border stuff, just like the pdf and every page, not just what I see.
If I could have access to the original pdf somehow, this would be fine too.
Extension in FFox enabled right click again and then I could print the iframe to pdf

Load External Custom Page and Execute Custom CSS or Javascript on The page

i'm building an online document portal that supports all Microsoft Office formats.
Instead of building my own module, i'm utilizing Google Docs Online Viewer since it already handles
this task properly, my only problem is it loads the header toolbar, which i dont want.
take for example This custom pdf-URL(i just googled for any pdf document), The navigation toolbar at the foot, but the header toobar, i want it hidden - all within the iFrame.
https://docs.google.com/viewer?url=http://www.scorpioncomputerservices.com/Press%20Coverage/Billgates.doc&embedded=false&controls=false
After Inspecting the Element on Chrome, i found the section of code controlling the element, problem is, how to hide this element on page load, by forcing a script/style to be executed on the page, while loading.
i would like to know if there's a way i could force-delete or hide the element controlling the toolbar within the iFrame, or better still if there are any alternatives to what i intend to do. my code would have looked like this
var obj = iframe.document.querySelectorAll('[role="toolbar"]');
obj.parentNode.removeElement(obj);
// or - i'm not sure anyof this would work.. and since it is loaded inside an iframe
// how do i execute this.
obj.remove();
i dont want my audience to be able to download the document, obviously curious developers might find a way, but thats going to be less than 2% - 5% of the total users.
how do i go about this please using javascript/CSS/or any library.
If you change the GET variable embedded to true the viewer won't display the top bar, however there's no way to edit the page inside the iFrame as Google has enabled cross site protection so the browser will prevent you from running any javascript to modify the content of the iFrame.
The only way to use the google document viewer is to get your site to load it in the background (not using an iFrame) and modify it before serving the page to the user.
Or alternitively I reccommend using an open source JS PDF viewer such as ViewerJS

JavaScript Print PDF using Adobe toolbar

I am trying to print a PDF in an iFrame. I have a print button for the user to click. I am finding it hard to write JavaScript to print the PDF that will work across IE, Chrome, Firefox. It's been really hard to print PDF, in an Iframe, in particular on IE.
While working on this, I noticed a toolbar for saving and printing the PDF when hovered over the PDF. I think these features are offered by Adobe.
I would like to know if there is a way to access these Adobe PDF controls through JavaScript.
How can I fire them using the print button?

Javascript: printing the contents of iframe on page load not working

background: i have a page in my web app with an iframe in it that displays a pdf file.
I require a browser's print preview window to appear as soon as this page in my web app loads. The print preview window will contain the contents of the iframe and print it.
Currently, i bind a function on the iframe's load event as follows:
$('#iframe').load(function () {
$("#iframe").get(0).contentWindow.print();
});
This works fine when i debug locally. However when i upload to server, the print preview screen will not automatically popup. In fact i have to first click on a button or element for it appear. Is there a way around this?
Thanks in advance..
Try this,
window.frames['#iframe'].focus();
window.frames['#iframe'].print();
Numerous methods using either jQuery or plain javascript did not fix the issue. However, after i set a 1 second delay to the print function, it worked!
setTimeout(function () {
$("#iframe").get(0).contentWindow.print();
}, 1000);
I suppose it has something to do with the server. It probably needs extra time to process the pdf in the iframe

Trigger click on embedded PDF

I have a PDF embedded in a web page using the following code:
<object id="pdfviewer" data='test_full.pdf#page=1&toolbar=0&statusbar=0&messages=0&navpanes=0'
type='application/pdf'
width='500px'
height='350px'>
The PDF itself is set to open in full screen mode which shows no controls. The user can advance the slides by clicking on the view.
What I'd like to have is some way to trigger that click so that I can advance 2 similar PDF:s side-by-side (one for the actual slideshow and one for the speaker notes). Is this possible to do in javascript and/or jQuery? I have tried using the click()-method but it doesn't get through to the embedded PDF.
Update: Can't find any info on it, so I guess I'm out of luck and have to try a workaround. Am currently juggling 3 embeds of the same pdf (current page, next page and previous page), hiding and showing them and loading more pages as the user clicks around.
I doubt it. Allowing web page scripts to pass input events to the PDF viewer could be a security risk (since the viewer generally has access to system file dialogues via things like Save As).

Categories