It is understandable that you may want to print a PDF file using code located directly within your web page. The alternative is to make your viewer download of the PDF file, open it and then print it from another program such as Adobe Acrobat. Open your word processor, as you are going to need to write some code.
So, if your PDF file has a different file name or path, change "document.
I am using the following function i found on another forum :. Before using that function, I tried " execCommand "Print" " but the results weren't good at all.
Instead of directly writing the DocumentContainer. Yes I am using this method that you suggested to print the inner HTML content of a DOJO grid, with some formatting and trying to find out what the inner html cells or cell style, you can control it completely. DOJO documentation is terrible, and there is currently no printing that I can find out from their generated widjits. The 'display' style directive in the print block will override any 'display' directive s in the common block.
All other directives in the common block that effect mydiv will be honoured in the print.
Printing the contents of a div, keeping styling
I think I'm right in saying that this includes any directives inherited by mydiv from hidden parent elements eg. This is certainly what I would expect, and most likely what you want.
If not, then add further directives for mydiv in the print block. More information here. If you need two or more Print buttons, each to print a particular div, then that's a different matter.
How can I achieve that? Thanks, Dana. Suppose there is 'testStyle' in 'test. Really so much thanks. Otherwise I would spoil valuable time Utpal Bhowmick. Getting Started: Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and adhere to our posting rules. Edit Preview. H1 H2. Post Reply. Insert Code Block.I have a page that has several div's the top one being the "title" of the page which would be a model. Middle div is just some info.
The third div is "specs". What I want to do is be able to have a print button on the bottom of the specs that prints the specs and then has the model at the top of the printed page. I have got the specs printing great just can't seem to get two divs to print.
Here is my code:. Right I want to be able to print two of the three divs but couldn't get the code to work. I will try your suggestion.
Best Answer. Are there no errors in Firebug at all? Popular Topics in Web Development. Which of the following retains the information it's storing when the system power is turned off? You said other two divs, but you're only printing one of them: Text. I just was going to reply and say that was the issue! Thanks so much for your help.
Artistan Oct 21, at UTC. If you want people to be able to print via ctrl-p, which I use all the time CSS HTML 8. This topic has been locked by an administrator and is no longer open for commenting.
Read these nextAre you looking to create a print friendly website with custom implementation instead of default browser behaviour? Do you want to allow your users to print specific parts of the web page, instead of being forced to print the complete page? Do you wish to add custom headers and footers and implement different CSS styles for the print version of the page? If so, then you have just struck gold with this article!
Using this plugin, one can:. It also allows you to include or exclude sections of the document while printing. It also supports printing your webpage with a specified stylesheet.
Simply provide the name of the stylesheet file and the plugin will use styles from that file when creating the print document.
Printpage is a jQuery plugin which allows you to print the web page without leaving the website.
This plugin was created to overcome the issues with the traditional method of printing, which reuires the use of the print stylesheet. The print stylesheet is a way to disable everything that is not relevant content. But working in this program gets messy and disabling various parts of the website can be tedious. PrintPage overcomes these issues by creating an iFrame and printing it directly instead of opening a popup.
The jQuery Print Preview plugin is designed to provide visitors with a preview of the print version of a website. Unlike traditional print previews this plugin brings in all content and print styles within a modal window.
From the modal window, there is an option to print the page and close the modal window. This plugin works in all the modern browsers. This plugin also offers various options to set transparency, rotation and offset parameters. PrintMe is a lightweight jQuery plugin for printing any html element. It is only dependent on jQuery library. This plugin also allows the user to add external style CSS and add a title to the document.
You can add multiple external style sheets to this plugin while calling it.The above code has been tested in the following browsers. Home Categories. HTML Markup. Hoping that you are enjoying my articles!
External CSS file.
Browser Compatibility. View Demo. Related Articles. Add Comments. Thank you for the feedback. The comment is now awaiting moderation. You will be notified via email when the author replies to your comment. You can add your comment about this article using the form below.
Make sure you provide a valid email address else you won't be notified when the author replies to your comment Please note that all comments are moderated and will be deleted if they are Not relavant to the article Spam Advertising campaigns or links to other sites Abusive content.
Please Share and Subscribe to support us. Disclaimer : The code samples and API available at www. You are free to use it for commercial as well as non-commercial use at your own risk, but you cannot use it for posting on blogs or other tutorial websites similar to www. All the code samples and API provided by the authors are solely their creation and neither the author nor the site are responsible if it does not work as intended.
I agree to the above terms. What our readers say. Error Details.
This will print something, but it will most likely be a disorganized scattering of the current web page across any number of pieces of paper. Wouldn't it be nice to have an easier and more reliable way to print selective content from the currently displayed web page?
I personally believe this technique should be present in many more web pages for the convenience of site visitors who may want a printed hard copy of selected content. View All. Douglas Miller Updated date, Mar 23 Next Recommended Article. Getting Started With.
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more. Asked 6 years, 4 months ago. Active 9 months ago. Viewed 51k times. I know it's simple, but I can't seem to get my head around this. Peter Mortensen Active Oldest Votes. Working code is here Write your script in body. Vipul Vaghasiya Vipul Vaghasiya 1 1 gold badge 5 5 silver badges 15 15 bronze badges.
Feedback on Q2 Community Roadmap. Technical site integration observational experiment live on Stack Overflow. Dark Mode Beta - help us root out low-contrast and un-converted bits. Linked