So I would like to be able to have a print button for entries in our database so users can print an entry via a print friendly "form".
My thought was to create a separate page, add labels and have those labels pull the relevant information.
I know I can add the open widget information via this code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showPage(app.pages.TestPrint);
But I'm running into a few problems:
I can't get the page to open in a new window. Is this possible?
window.open(app.pages.TestPrint);
Just gives me a blank page. Does the browser lose the widget source once the new window opens?
I can't get the print option (either onClick or onDataLoad) to print JUST the image (or widget). I run
window.print();
And it includes headers + scroll bars. Do I need to be running a client side script instead?
Any help would be appreciated. Thank you!
To get exactly what you'd want you'd have to do a lot of work.
Here is my suggested, simpler answer:
Don't open up a new tab. If you use showPage like you mention, and provide a "back" button on the page to go back to where you were, you'll get pretty much everything you need. If you don't want the back to show up when you print, then you can setVisibility(false) on the button before you print, then print, then setVisibility(true).
I'll give a quick summary of how you could do this with a new tab, but it's pretty involved so I can't go into details without trying it myself. The basic idea, is you want to open the page with a full URL, just like a user was navigating to it.
You can use #TestPrint to indicate which page you want to load. You also need the URL of your application, which as far as I can remember is only available in a server-side script using the Apps Script method: ScriptApp.getService().getUrl(). On top of this, you'll probably need to pass in the key so that your page knows what data to load.
So given this, you need to assemble a url by calling a server script, then appending the key property to it. In the end you want a url something like:
https://www.script.google.com/yourappaddress#TestPage?key=keyOfYourModel.
Then on TestPage you need to read the key, and load data for that key. (You can read the key using google.script.url).
Alternatively, I think there are some tricks you can play by opening a blank window and then writing directly to its DOM, but I've never tried that, and since Apps Script runs inside an iframe I'm not sure if it's possible. If I get a chance I'll play with it and update this answer, but for your own reference you could look here: create html page and print to new tab in javascript
I'm imagining something like that, except that your page an write it's html content. Something like:
var winPrint = window.open('', '_blank', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write(app.pages.TestPage.getElement().innerHTML);
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close();
Hope one of those three options helps :)
So here is what I ended up doing. It isn't elegant, but it works.
I added a Print Button to a Page Fragment that pops up when a user edits a database entry.
Database Edit Button code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showDialog(app.pageFragments.FragmentName);
That Print Button goes to a different (full) Page and closes the Fragment.
Print Button Code:
app.datasources.ModelName.selectKey(widget.datasource.item._key);
app.showPage(app.pages.ModelName_Print);
app.closeDialog();
I made sure to make the new Print Page was small enough so that Chrome fits it properly into a 8.5 x 11" page (728x975).
I then created a Panel that fills the page and populated the page with Labels
#datasource.item.FieldName
I then put the following into the onDataLoad for the Panel
window.print();
So now when the user presses the Print Button in the Fragment they are taken to this new page and after the data loads they automatically get a print dialog.
The only downside is that after printing the user has to use a back button I added to return to the database page.
1.
As far as I know, you cannot combine window.open with app.pages.*, because
window.open would require url parameter at least, while app.pages.* is essentially an internal routing mechanism provided by App Maker, and it returns page object back, suitable for for switching between pages, or opening dialogs.
2.
You would probably need to style your page first, so like it includes things you would like to have printed out. To do so please use #media print
ex: We have a button on the page and would like to hide it from print page
#media print {
.app-NewPage-Button1 {
display : none;
}
}
Hope it helps.
1. Here is how it is done, in a pop up window, without messing up the current page (client script):
function print(widget, title){
var content=widget.getElement().innerHTML;
var win = window.open('', 'printWindow', 'height=600,width=800');
win.document.write('<head><title>'+title+'/title></head>');
win.document.write('<body>'+content+'</body>');
win.document.close();
win.focus();
win.print();
win.close();
}
and the onclick handler for the button is:
print(widget.root.descendants.PageFragment1, 'test');
In this example, PageFragment1 is a page fragment on the current page, hidden by adding a style with namehidden with definition .hidden{display:none;} (this is different than visible which in App Maker seems to remove the item from the DOM). Works perfectly...
2. You cannot open pages from the app in another tab. In principle something like this would do it:
var w=window.parent.parent;
w.open(w.location.protocol+'//'+w.location.host+w.location.pathname+'#PrintPage', '_blank');
But since the app is running in frame nested two deep from the launching page, and with a different origin, you will not be able to access the url that you need (the above code results in a cross origin frame access error). So you would have to hard code the URL, which changes at deployment, so it gets ugly very fast. Not that you want to anyway, the load time of an app should discourage you from wanting to do that anyway.
I'm having difficulty figuring out why a certain value isn't appearing in my template's data context. How can I examine it from the console?
Inspired by #richsilv's comment I created a bookmarklet that makes this task quite easy. Once you've added the bookmarklet to your bookmarks, you can click it on any meteor page, then hover over the item whose data context you'd like to see, and click. The data context will then be printed to the console.
Stackoverflow doesn't allow me to insert the bookmarklet as a link, so you'll have to copy and paste the snippet below into a bookmark URL.
javascript:document.onmouseover=function(e){var evt=e||window.event;var elem=evt.target||evt.srcElement;elem.style.outline='2px solid gray';};document.onmouseout=function(e){var evt=e||window.event;var elem=evt.target||evt.srcElement;elem.style.outline='';};document.onclick=function(e){var evt=e||window.event;var elem=evt.target||evt.srcElement;var par=elem.parentNode;if(par.nodeName=='A'){par.onclick=function(e){e.returnValue=false;return false;};par.setAttribute('href','');};console.log(Blaze.getData(elem));if(evt.preventDefault)evt.preventDefault();evt.returnValue=false;document.onclick=null;document.onmouseover=null;};void 0;
I have a large pdf with 50-60 pages. I converted the pdf into web page using ConvertApi web2pdf online api and then added some input controls on the pages wherever required.
When user filled all the required input and submit I rendered the entire page and show the preview to the user to check whether user has filled the inputs correctly. After that when User click submit then it stores into database and generate the pdf of the same.
I used convertApi.dll and wrote the following code to generate pdf.
MemoryStream outStream = new MemoryStream();
Web2Pdf convertApi;
convertApi = new Web2Pdf();
convertApi.SetPageSize("A4");
convertApi.SetPageWidth("100%");
convertApi.ConvertHtml(HtmlText, outStream);
My problem is when we generate the pdf it does not take all the styles used in the page. And pdf look different. I need to provide the very similar pdf which client provided. Can any one suggest me to do it in better way.
Thanks.
I created one web page, its in there one grid view control(see attached image) in that grid view one link button(Download) . if i click download button file will download . downloading time is little far so i need to show progressing (like still downloading ...) .
I used update panel, update progress controls its not working for me, and i used image control also that one also doesn't help me.
Give me some tips to show progressing msg.. please .
Here is one of the options you can take:
write ashx generic handler that will monitor byte to byte procesing
Inside this handler save current procesing position. Call this ashx to download file.
write server side function that will return current procesing position saved by the ashx handler
This function must be awailable to javascript
on client side just call this javascript function that calls server side function
This is the whole concept. Please let me know if I need to explain you something in details.
http://www.dreamincode.net/forums/topic/115491-download-file-asynchronously-with-progressbar/
Enviroment: ASP.NET Framework 2.0
Is it possible to accomplish something like this:
I have this link <a href='printBarcode.aspx?code=HF54A'>Print Bar-code</a> and I want to print the response that the server sends for that link. Is that even possible? The response is text but it's not HTML, is some text that a special printer recognizes for printing bar-codes.
The idea is this: the user clicks on the link then the browser receives the response for that link and prompts to print it's content.
I'm happy to receive all suggestions and comments if you think you know of a better way to do this.
No, a browser has no functions for printing anything other than the content of a window. You can't take a response that is returned and send directly to a printer, the closest possible is to display the response in an iframe and ask for a printout of the iframe content. If the browser doesn't know how to visualize and print the response, you can't use the printing capability in the browser to print it.
If you want to send the response directly to a printer, you would have to run a component (flash/silverlight/Java) in the browser that could access the printer directly.
You could put the text from the response into a [div id="textToPrint"] and call a javascript print(). If you can use a popup to open the link [a href='printBarcode.aspx?code=HF54A'] you can have a poopup page like:
[html]
[body onLoad="print();"]
[div id="textToPrint"] YOUR TEXT FROM RESPONSE [/div]
[/body]
[/html]
in this case the printer will print only your text...
You could return a page that is just the barcode text and auto popup the print dialog.
<script type="text/javascript">
window.print();
</script>
But I don't think this will work. I assume the browser will not send it to the printer in the correct format.
The problem is ASP.NET can't access a local printer in the server side code. To do some custom printing you would probably have to rely on Flash or Silverlight, if a plain print of the page doesn't work.