I'm trying to print a pdf using the built in that chrome uses.
I have a aspx that inherits from Page, on it's Page_Load event, I grab the pdf content as string (then convert it to bytes), and set the Response as follows:
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Buffer = bufferOutputStream
Response.BufferOutput = bufferOutputStream
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", pdfBytes.Length.ToString)
Response.AddHeader("content-disposition", "inline; filename=" & fileName & ".pdf")
Response.CacheControl = "no-cache"
Response.Expires = -1
Response.BinaryWrite(pdfBytes)
Response.Flush()
When I press the print button I have the following error:
I tried to use print(); on the Top (Extension) in the console, but it wants to print a capture of the window instead of the content of the pdf.
I tried IE, Edge, Chrome Version 90, Firefox, Brave, both normal and Incognito, without any extensions and cache/nav history cleared and they work. Strangely enough, Brave uses The same Chromium version (Version 1.35.103 Chromium: 98.0.4758.102 (Official Build) (64-bit)).
Related
My code to print an image using html2canvas is working on all browsers except Chrome. It even works on Chrome incognito mode but not in the normal Chrome browser.
Also for new users not using the print feature, it seems to be working on their normal Chrome browsers but older users using the feature are suddenly seeing a blank page. Is it some kind of cache issue?
After debugging I found that the canvas generated by html2canvas is capturing image of wrong dimension even when the entire DOM is loaded for my component.
here is my piece of code :
html2canvas(inputEl, {useCORS: true, allowTaint: false}).then(canvas => {
const [canvasHeight , canvasWidth] = [canvas.height, canvas.width];
const imgData = canvas.toDataURL("image/png");
let canvasImage = new Image();
canvasImage.onload = onCanvasLoad.bind(this, canvasImage, {...canvasOptions, pdfDocument, canvasHeight, canvasWidth});
canvasImage.src = imgData;
});
Settings CORs to true is also didn't help.
Even the example on the main site is not working - checked with https://html2canvas.hertzen.com/ -> bottom right corner - photo - capture.
The question also posted here - https://github.com/niklasvh/html2canvas/issues/2804
Please provide some pointers here.
Specifications:
html2canvas version tested with: 1.0.0-rc.7
Browser & version: Chrome - 97.0.4692.71 (Official Build) (x86_64)
The issue been resolved. Please follow the same thread - Click here
Adding the following changes helped me solve the issue:
function fnIgnoreElements(el) {
if (typeof el.shadowRoot == 'object' && el.shadowRoot !== null)
return true
}
html2canvas(document.querySelector("#capture"), { ignoreElements:
fnIgnoreElements }).then(canvas => {
document.body.appendChild(canvas)
});
I am facing one issue since my chrome browser is updated to version 77.
Initially window.print() is working fine, but once I open a page where it includes embedded PDF using <embed> tag, window.print() stopped working. Using Ctrl+P shortcut it opens the print popup but when I execute window.print() in javascript it doesn't work.
I have executed window.print() command in console, it directly returns undefined.
There might be a some changes in Chrome 77 release as per this thread https://support.google.com/chrome/thread/14107571?hl=en
Does any one have face this issue ?
Please help.
Looks like this is related to Chrome settings issues, because turning off chrome://flags/#mime-handler-view-in-cross-process-frame fixing that issue.
For someone that did not know how to turn off that, please do this:
Open new tab on chrome, and type chrome://flags/
You will have Experiments page opened.
Then type: Mime on the search bar on that page.
That will show you: MimeHandlerView in cross-process frame
Change that value from: Default to: Disabled, then it will ask you to relaunch the chrome.
After the chrome restarted, the printing function will work fine.
I am facing some what similar issue - once the pdf file is rendered, by the chrome pdf viewer, the window.print() starts returning undefined.
More detailed description - A pdf file is rendered into the tab, user hits back and then print() stops working. It is important that all is executed in the same tab.
$(document).ready(function () {
var URL;
$('#Print').click(function () {
$('#embed').remove();
URL= 'url';
setTimeout(cPrint, 100);
});
function cPrint() {
window.print();
$('#div').append('<embed id="embed" src="' + URL + '" />');
}
});
IText generated PDF document is not being displayed in Chrome browser
The generated document is being written to the HttpServletResponse object and contentType set to application/pdf but the Chrome browser does not appear to recognize it, no Preview dialog is appearing however, if I run the same application in Firefox browser it works fine
I would expect the Preview to be available in Chrome
The problem has was found to be in the printJS package, this is a known problem applicable only to Chrome and is being investigated
For an online pdf I can simply add #page=10 after the url to open the pdf on the page 10.
But this doesn't work for local pdf. [2020 edit: this is now working for local pdf also cf. the selected answer]
Let's say I open this url file:///C:/Users/Me/Desktop/My%20Documents/textbook.pdf in chrome.
If I add #page=10 at the end of the link (the pdf has more than 50 pages), then chrome returns this error:
Your file was not found It may have been moved or deleted.
ERR_FILE_NOT_FOUNDthis url
Also Chrome change the url (cf My%2520Documents): file:///C:/Users/Me/Desktop/My%2520Documents/textbook.pdf%23page=10
For my Chrome(Version 83.0.4103.116 (Official Build) (64-bit))
It works with #page=number, if I open a new tab and paste the link:
file:///D:/test.pdf#page=5
Chrome will open the pdf at page 5.
Recently we migrated to latest version of application which allows the user to open application in any browser.
Earlier it use to support Only IE browsers.
After migration many users still open the application in old browser.
Since the application is very slow in IE browser.We are looking for a solution that will automatically open the URL/Login Page in Chrome browser when user opens in IE browser.
i.e., when a user open URL in IE browser it automatically open the same URL in Google chrome browser.
Google Chrome Legacy Browser support allows this. Under the "Hosts to open in Alternative Browser" policy, put in an entry for the site you want to force to open in Chrome, preceding it with an "!". Example:
!https://www.somesitetoopeninChromeonly.com.
If i understand it correctly, the users open a page in IE and when they click an url on that page, it will open that URL in Chrome.
I guess, you can't do this. You can use target="_blank" to open a new tab in the same browser.
If you want to open a link from an application in chrome and not in IE, you can change the default browser to chrome. Click on Start, type the "default app settings" and change the default browser to chrome.
I think the best solution is to let the user open Google Chrome manually by informing about it.
It is possible however, to make a document called "chrome.hta" for example, with the contents shown below, and then link to it on another page. (This will only work in Internet Explorer, not Edge)
<script type="text/javascript" language="javascript">
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var website = "http://example.com/";
oShell.ShellExecute(commandtoRun, website, "", "open", "1");
window.close();
</script>
The user now has to press "open" and "allow" after they click the link referring to the .hta file.
Now, on the page where you link to the .hta document, you can make the page detect the browser and adjust the link accordingly:
<a id="link" href="example.com">My Application</a>
<script>
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
document.getElementById("link").href = "example.com/chrome.hta";
</script>
A bit late, but we have two different solutions for this:
We use a javascript: link to use ShellExecute to run a small exe helper application that checks if Chrome is installed, and if it is, open Chrome to the URL parameter, optionally with switches (e.g. --use-system-default-printer and on shared logon PCs, --incognito). This requires configuring special permissions for the site in Internet Options|Security.
Now we can also use the microsoft-edge: protocol to open sites in Edge.
You could also install your own protocol for opening sites in Chrome but you would need a helper application to re-write the URL. I have one written to add microsoft-edge-private: to open links in Edge in InPrivate mode.
To open the webpage in Microsoft Edge you can try the below code.
TEST