A web application allows a user to print pdf documents using the browser's print dialog. The documents are streamed from a service with mimetype application/pdf. In the web client an iframe is created and appended to the document.body and for the source is set the uri of the service which returns the content.
The frame is as follows:
<iframe id="printPage" name="printPage" src="/remote/api/export/resource_name" style="position: absolute; top: -1000px; width: ${opts.frameWidth}px; height: ${opts.frameHeight}px;"></iframe>
The print execution part in javascript is like this
let iframe = $('the_iframe_html_above');
iframe.load(() => {
window.frames.printPage.focus();
window.frames.printPage.print();
});
$('body').append(iframe);
In this way the print dialog is opened as expected under Chrome and Safari browser only.
Under Firefox the dialog is opened but prints about:blank page because the iframe remains empty (there is no content in the body). This happens when pdfjs is disabled from about:config which obviously is OK. If it is not disabled, then FF gives error "Error: Permission denied to access property print" for which there is a 3years old bug reported in mozilla's bugtracker https://bugzilla.mozilla.org/show_bug.cgi?id=911444
IE and Edge just ignore the onload handler for which I know it is expected but even with an inline onload handler they don't manage to open the print dialog. Only IE gives the file for save/open but not print.
So my question is: If there is a crossbrowser way to perform print operation (open the browser's native print dialog) given these conditions?
Related
I am trying to add a yes/no message box to a google sheet that will display on an iPad. I have tried all the things below but none of them display the message. My goal is if the user changes a field the macro will change other fields if the user says it is ok. I can get this to work on a windows machine with no issues but when I try it on an ipad the message never appears. At this point I am just trying to get a message box to appear. This is what I have tried
1.
function onEdit(e) {
Browser.msgBox("test");
}
Result: The macros times out
2.
function onEdit(e) {
var html = HtmlService.createHtmlOutputFromFile('Page')
.setWidth(400)
.setHeight(300);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'My custom dialog');
}
Page.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />
</body>
</html>
I enabled the trigger for onEdit to get it to work and it works on the windows machine without issues but when run on the iPad I get:
Exception: You do not have permission to call Ui.showModalDialog. Required permissions: https://www.googleapis.com/auth/script.container.ui
So next I tried:
3.
function myFunction(){
Logger.log("myFun")
var html = HtmlService.createTemplateFromFile( 'Page' )
.evaluate()
.setWidth( 800 )
.setHeight( 400 );
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog( html, 'My page title' );
}
function onEdit(){
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(SpreadsheetApp.getActive())
.onEdit()
.create();
}
Using the same page.html, this time in executions it looks like it runs but no box appears on the ipad(it does work on windows). I also tried spreadsheetApp.getUi().alert and prompt, these had the same results.
And Yes I have to use the iPad, I can not use another type of tablet.
Issue:
"Exception: You do not have permission to call Ui.showModalDialog. Required permissions: googleapis.com/auth/script.container.ui"
Fix:
What you can do is installing the trigger instead of using a simple trigger. The image below shows the difference between an installed (above) and a simple (below) trigger using the same code.
Output:
Note:
Don't use reserved function names on installed triggers to avoid it being executed twice like what's shown above. Change onEdit to something like promptUI or something else.
If the above fix isn't enough to show the dialog box, then we need to confirm if the issue might just be on the safari browser (if you are using one) since it worked on your other devices which I assumed are not using safari. You can try using an alternative browser in your device such as Google Chrome and see if the same issue persists. I recommended doing this since i'm seeing a number of issues between showModalDialog and safari
EDIT:
I have seen these related posts pointing out that there are some limitations on mobile apps. See the references below.
Also, some answers suggests that you need to access the spreadsheet via browser (google chrome desktop mode) and then trigger the script there.
References:
Add a script trigger to Google Sheet that will work in Android mobile app
google speadsheet api onOpen does not work on mobile ios
Executing Google Apps Script Functions from Mobile App
How to get scripts to work with phones and tablets
I'm making a Thunderbird Extension through the WebExtension Api (with popup) and i've some difficulties running a Content script to get some elements (attachments list of the current mail for example) directly from Thunderbird interface.
I've made a popup.html , a popup.js and a contentScript.js that runs when the popup is opened. Apparently contentScript.js doesn't run in the main Thunderbird tab, but runs smoothly when i open a new tab (with url) through code.
$(document).ready(function(){
console.log('Try to execute contentScript');
// -- create new tab --
// browser.tabs.create({
// url: 'https://example.org'
// });
// -- execute script in current tab --
browser.tabs.executeScript({
file: 'scripts/contentScript.js'
});
});
// from contentScript.js
console.log('contentScript.js - Injected');
In console i expected "contentScript.js - Injected" but this only appens when i am not in the main Thunderbird tab.
When i am in the main tab it shows only "Try to execute contentScript" then nothing appens, no errors.
Thunderbird extension are evolving right now from the old legacy method (overlay of xul files) to the actual WebExtension Api used by most of the browsers, but there are some differences: in Firefox the extension works without any problem, so i supposed that the main tab of Thunderbird is somehow protected from content injection.
My objective here is to get the attachments list and other elements directly from the interface, but apparently i can't.
I want to open a webpage from a flash button. I'm using adobe flash CS6, action script2.
Below is the code i have tried:
on (release, releaseOutside ) {
getURL("http://www.google.com", "_self");
}
It works fine when i test it in (Test Movie -> in flash Professional).
But it doesn't work when i test using (Test Movie -> in Browser) and also doesn't work after exporting it.
This is due to security measures. Change '_self' to '_blank' within your AS or set 'allowScriptAccess' to 'always' within your html. Refer to this page for more info.
Currently, I have an issue with populating an iframe that I have with a PDF document, but this issue only occurs in IE.
Basic Layout:
I have a screen that contains a list of items (attachments), which can be images, text or pdf. When the user clicks on one of these items - it will make a call to a controller action [ViewAttachment] which will return the requested item and display it in the iframe.
This currently works for all data types with the exception of PDFs in IE. (Firefox, Chrome etc. all display the PDF in the iframe without issue.)
I previously was using Adobe Reader 9, and recently upgraded to 10 in hopes of solving this issue. I'll attach some code to see if anyone has any suggestions as to how to possibly resolve this.
Code to Populate iframe: (Moved to two lines for readability)
$(".viewattachment").live('click',function ()
{
$("iframe#test").attr("src","<%=Url.Action("ViewAttachment","Images") %>?
attachment=" + $(this).next().val());
});
ViewAttachment Controller Action:
public ActionResult ViewAttachment(string attachmentGuid)
{
Attachment attachment= imageAgent.GetAttachment(attachmentGuid);
Stream resultStream = new MemoryStream();
resultStream = StorageProviders[attachment.ProviderName]
.ReadFile(attachment.FileReference);
resultStream.Position = 0;
FileStreamResult result = new FileStreamResult(resultStream,
attachment.ContentType);
return result;
}
Notes:
I've attempted toggling the "Display PDF in Browser" in Adobe Reader without any success.
Currently testing this for IE8.
When clicking on a PDF to view - the iframe simply remains at it's previous content and doesn't change at all.
After several different methods and iterations of testing - I determined that it was a conflict between IE8-9 and versions of Adobe Reader 9-10. I added the following meta tag to the window containing the iframe and it resolved all of the issues:
<meta http-equiv="X-UA-Compatible" content="IE=7" />
This should at least work until an update / fix is made.
Have you tried hitting the pdf url directly? If it loads within the browser, then you can narrow down the problem to the iframe. If Adobe Reader pops up, then you know its a problem with the IE Plugin.
I had the same problem working with spring mvc. I releazed that if I put the Iframe inside some tag, like 'util:panel', the iframe does not load de pdf content in IE 8. When I put the iFrame out of the tag, all work fine.
I'm trying to save the full content of the current static web page, using the code from Show IE "Save As" dialog using Watin
So here it is:
IE ie = new IE("http://localhost");
// more code
//I expect out.html is the output file
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("out.html");
//I expect this line to popup the save as dialog box, but nothing happens
ie.AddDialogHandler(fileDownloadHandler);
//the program is blocked at this line, as it can't click anywhere
ie.Link("startDownloadLinkId").Click();
fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(15);
fileDownloadHandler.WaitUntilDownloadCompleted(200);
I also tried the code below, but it doesn't save all the page:
System.IO.StreamWriter file = new System.IO.StreamWriter("output.html");
file.Write(ie.Html);
Again, I need to save the webpage from Watin, and the result to be the same as saving it manually.
Thanks!
Here is how I do it:
File.WriteAllText("myfile.html",
(myIE.InternetExplorer as SHDocVw.InternetExplorer).Document.documentElement.outerHtml);
Assumes myIE is a WatiN IE element, of course.
If you're ever having difficulty finding how to do something with WatiN, I often find it helpful to google how to do it with an "Internet Explorer COM object". WatiN wraps the object, but it is exposed and able to be accessed!
Cheers!
Try to parse the html with html agility pack and save it, there are additional abilities that you can use...
using HtmlAgilityPack;
var htmldoc = new HtmlDocument();
htmldoc.LoadHtml(ie.Html);
htmldoc.Save(stream);
Link to agility pack