Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello experts,

I have a web form something like data entry website. A
After entering the data in the fields, if user clicks on Submit button, I want some function that should do below things

1) screen shot/ image / copy the web page as it is
2) display it second / new tab /new window
3) Work like print preview

I have working on quite sometime to get the PDF form fillable and printed.
Now that ASPX page should be print previewed , it seems difficult and confusing for me.

Could you please help me with this?
Posted
Comments
Afzaal Ahmad Zeeshan 27-Jul-15 16:46pm    
Why won't you simply let browser handle the window.print(); function?
sudevsu 27-Jul-15 17:00pm    
Nope. I knew that someone is gonna tell this. My Manager wants it like that. It should open same exact page like print preview. Can you help me please?
Afzaal Ahmad Zeeshan 27-Jul-15 17:01pm    
Then try to create a PDF of that on the server-side. Try using iTextSharp library for that. Stream that PDF down, and show it in a floating (position: absolute) container.
sudevsu 28-Jul-15 8:10am    
As said earlier, I already created the PDF on server side. But it opens on same page. Now I want a button to work exactly like a print preview on browser. Could you please tell me how
Sergey Alexandrovich Kryukov 27-Jul-15 17:07pm    
Each browser has "Print preview". Why not using it? You can use CSS @media rules to create print version of anything, which could be even totally different from the on-screen page.
By the way, this is a second case when you refer to your "manager". May I ask you: does this guy have any clue on what computers do? :-)
—SA

1 solution

I kind of got some solution...
But I am really not satisfied with it. Because the Style of the Preview is not proper.
How can I do a shrink fit to width in style and adapt that style in JavaScript function is my question now...

Can someone help me with that?

XML
function PrintPanel() {
        debugger;
        var panel = document.getElementById("<%=Upnl1.ClientID %>");
//        panel.style.visibility = "visible";
        panel.style = 'preview-message';
        var printWindow = window.open(panel, '', 'height=600,width=900');
        printWindow.document.styleSheets = 'preview-message';
        printWindow.document.write('<html><head><title>DIV Contents</title>');
        printWindow.document.write('</head><body >');
        printWindow.document.write(panel.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        setTimeout(function () {
            printWindow.print();
        }, 1000);
        return false;
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900