How to send the PDF output to browser print option (CTRL+P) - printing

I am using TCPDF library to generate some reports, and i want to send the PDF file to print option of browser as simple we press CTRL+P, I need this because it is slip.
I used all parameter for Output but it is downloading the file directly.
$pdf->Output('slip.pdf', 'I');
I also placed the F,D,S,E,FI and FD instate of I but it doesn't work. And I also used header
header('Content-Type: application/pdf');
$pdf->Output('example_001.pdf', 'FD');
but again it doesn't work. Any solution? Please!

Add
$pdf->IncludeJS("print();");
just before $pdf->Output...

You need something like the example below. You would need to intercept print request (print automatically on page load, print button click, etc.) and then call printTrigger function.
<html>
<head>
<title>Print PDF</title>
<script>
function printTrigger(elementId) {
var getMyFrame = document.getElementById(elementId);
getMyFrame.focus();
getMyFrame.contentWindow.print();
}
</script>
</head>
<body>
<iframe id="iFramePdf" src="http://pdfurl.com/sample.pdf"></iframe>
...
</body>
</html>

What you are trying to do is not within the specification of the TCPDF API.
http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1
I believe you would need to use JavaScript to implement this feature the way you are proposing.

Add $pdf->IncludeJS("print();"); just before $pdf->Output...
It's working for me.

Related

Problem in printing a webpage containing SVG images in Chromium

I have a html file with the following content:
<html>
<body>
<object data="https://upload.wikimedia.org/wikipedia/commons/0/09/America_Online_logo.svg" type="image/svg+xml"></object>
</body>
</html>
As you can check, you can open it with chrome and print it.
But if I use Chromium.Print method, it print empty pages.
Note that this is only a sample. All SVG images had the same problem.
I use Delphi 10.3.2 and CEF4Delphi.
Can any one guide me?
This is very likely caused by the CEF issue #3297 and the workaround described in that report works.
Add this code line before the GlobalCEFApp.StartMainProcess call :
GlobalCEFApp.DisableSiteIsolationTrials := True;
I tested this workaround with the latest CEF4Delphi version which uses CEF 100.0.14 and the MiniBrowser demo. Your sample HTML is printed correctly with TChromiumCore.Print and TChromiumCore.PrintToPdf.

invokescriptasync HRESULT: 0x80020101' script runs fine in chrome and IE

I'm still trying to make the invokescriptasync work. I'm trying the following test on facebook.com and it fails with a HRESULT: 0x80020101' which normally means the script has an error in it, but I tried running the simple javascript in Chrome and IE without any problem.
private async void WebView_OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
await _webView.InvokeScriptAsync("eval", new[]
{
"document.getElementById('blueBarDOMInspector').innerHTML = '';"
});
}
Thanks
I have tested your code and the error is thrown only in case the blueBarDOMInspector is not found. I used the following simple HTML:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<p id="blueBarDOMInspector"></p>
</body>
</html>
You can confirm that the script works as expected with this HTML. So I suspect the problem is rather on HTML side than on side of UWP.
As for ScriptNotify not working - the website must be HTTPS and be added as trusted to appxmanifest. Better solution is web allowed object. A great example was posted in a question yesterday on SO or here as a sample project. Basically you have to create a Windows Runtime Component with a class marked as [WebAllowed] and then inject it in the WebView using AddWebAllowedObject method.
For your invoking JavaScript code issue,I've checked your code, it's simple, the possible issue might be the 'blueBarDOMInspector' object, please make sure that you could get the 'blueBarDOMInspector' object successfully when the OnNavigationCompleted is fired.
For your second question:
I can invoke the script : "window.external.notify('something');" but it doesn't raise the event ScriptNotify which is another problem :-(
Please check the document:
To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's Uniform Resource Identifier (URI) in the ApplicationContentUriRules section of the app manifest.

jsPDF downloading blank pdf

I'm using jsPDF to generate a pdf from the current HTML, the code works fine if I paste it on the console and downloads a PDF with the current HTML, but when I put it on a JS file it downloads a blank PDF:
This is the code:
<script>
function descargar_pdf(){
var pdf = new jsPDF();
pdf.addHTML(document.body,function() {});
pdf.save('Estadodecuenta.pdf');
};
</script>
The function is called from a button:
<button class="descargar_pdf" id="ignorePDF" onclick="descargar_pdf();"> Descarga tu estado de cuenta</button>
The second argument in the addHTML function is a callback function which gets called after the HTML is rendered.
pdf.addHTML(document.body, function() {
pdf.save('*.pdf');
});
The last correctly working version of html2canvas is RC1. Downgrade to that one and it should work as expected.
This may sound stupid but there's a lot of security plugins that see JSPDF as an "unsafe" js and just block it , i had the same problem as you did but after testing it out on incognito mode (no extensions) it worked fine.
This may not the solution to your problem but its a advice you should keep in mind

Can the document.location.protocol value be changed in a WinRT webview?

I'm currently having an issue with the WebView control used in a Universal WinRT app (Windows 8.1/Windows Phone 8.1).
I currently load the following piece of JavaScript into the WebView using the NatigateToString method:
<html>
<head>
<base href='MY_BASE_URL'>
</head>
<body>
<script>
var idcomments_acct = 'MY_ACC_ID';
var idcomments_post_id='POST_ID';
var idcomments_post_url='POST_URL';
</script>
<span id='IDCommentsPostTitle' style='display:none'></span>
<script type='text/javascript' src='http://www.intensedebate.com/js/genericCommentWrapperV2.js'></script>
</body>
</html>
This is the piece of code for the IntenseDebate generic install that can be found here.
The issue is with this line of code in the referenced IntenseDebate code:
load_js(document.location.protocol+"//connect.facebook.net/en_US/all.js")
This piece of code fails because document.location.protocol is set to about: in the WebView, leading to a 404 error on this call.
On the Android/iOS webviews simply setting the base URI to a http: or https: based address using their loadDataWithBaseUrl methods worked fine, but the WinRT WebView is missing a similar method. And setting the Base url in the HTML itself (like shown in the piece of code above) does work for resolving image url's and sortlike, but this method doens't change the document.location values.
Since I can't modify the referenced JS file and putting the above piece of HTML on a server isn't an option in this apps usecase, is there any way you can force the document.location.protocol to be a certain value in the WinRT webview? Or is there any other way to get this bit of HTML to work in a webview?
There isn't a direct way to do this. WebView doesn't provide any interface to override the document.location . If branching off of the protocol is a common pattern then this may be a good feature to request on http://wpdev.uservoice.com .
I'm not familiar enough with HTML/JavaScript best practices to say for sure, but most of the references I find searching for document.location.protocol warn against assuming that the protocol will always be http: or https. This may be something that IntenseDebate should fix.
That said, you may be able to get past this by injecting code into your page which finds the problem location in the DOM and changing it live. You can't change just the protocol, but you may be able to find where it is referenced and change that there. I assume it gets loaded into the commentScript.src from genericCommentWrapper2.php referenced in genericCommentWrapper2.cs and then added to the document's head.

Video upload paperclip ffmepg

ffmepg and qtfaststart to process my video uploads. The converting is working fine and the video gets uploaded. My problem is that i can't display it. When I first tried <%= video_tag(#post.file.url) %> I just get a blank area. I've also tried jplayer, got the installation and all working and when i tried to call my video path it doesn't work.
Here is the js code when I tried with jplayer.
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
m4v: "<%= video_tag(#post.file.url) %>"
});
},
swfPath: "/",
supplied: "m4v",
solution: "flash, html"
});
});
</script>
I don't know how to call the uploaded video and display it, Please really need some help!
please always read the documentation. otherwise you will get comments a la RTFM.
when you use video_tag it inserts an html5 video element into the page. read about it here: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-video_tag
<video src="/trailers/hd.avi" width="16" height="16" />
this is probably not what you want for your jPlayer. when you inspect the html source, this should be obvious. i did never use jPlayer, but i assume that it would like to be pointed to the streaming source, which i guess is #post.file.url in your case.

Resources