I'm trying to display by jquery load() a dynamically generated PDF created by PHP with FPDFlib on a div but what I get is a jam of chars. Is there a way to resolve it?
thanks in advance
I've tried to correct my code in this way but continue to display jam
$.post("./php/stampa_login.php",
{piatta:'<? echo $_POST["piatta"] ?>'},
function(data){
$("#stampa_content").load("./temp/login.pdf")
});
ciao
h.
That seems to be correct. jQuery's load() fetches an URL through AJAX; if that URL is PDF, it appears as "jam of chars" to the browser, as PDF and HTML aren't compatible at all, the formats are completely different.
What you probably want is to open the PDF as an <object>, but then you're hoping that the user has some PDF plugin installed in their browser. Let's take a step back: what are you trying to achieve here, by displaying a PDF?
You can create a blank embed tag and give src attribute as link. in your call back function. This will load the pdf file perfectly.
$("#embed_tag_id").attr("src", "./temp/login.pdf");
Instead of using $("#whatever").load();
You'll want something like this:
$("#stampa_content").html ($("<object>", {
data : "./temp/login.pdf",
type : "application/pdf",
width : 800,
height : 600
}));
What that will do is instead of trying to load the contents of the PDF into a DIV, it will create an <object> block that will start up your PDF reader (such as Adobe Reader) which will then load the PDF itself and display it.
ya, seems to be an output issue. Have you tried header function to output it correctly ? try for proper output or instead of opening the pdf in div, just update the pdf's link there
Related
I want to create a pdf page from html file in Laravel but I do not know how to do it. You can help me
https://github.com/barryvdh/laravel-dompdf
// Import in top of controller file
use Barryvdh\DomPDF\Facade as PDF;
// use below code to generate and download pdf file
$pdf = PDF::loadView('bladefilename', ['arrayname' => $array]);
return $pdf->download('filename.pdf');
Write Above code in the controller file
In Blade file (HTML file) set array data.
Show Below Link : https://github.com/barryvdh/laravel-dompdf/issues/126
I know I am a little bit late but hopefully this will help someone.
There are 2 ways:
Create HTML page and use jspdf to print this page. The best way is to use html2pdf: https://github.com/eKoopmans/html2pdf.js
You can use this one to convert html to canvas and print to pdf. All css will be kept but you have to change the page to fix the space between pages as there may be some bad cut at the end of each page.
Print the page using latex. You have to use laravel latex compiler: https://github.com/fvhockney/latexcompiler
It is a little bit harder to styling the page but there is no problem with paging.
I need to read a text file on a server and display its content in a blog post on Blogger. The text file is a result of a simple download counter and contains a number. The problem is the Blogger does not support PHP codes in a post. My current solution is to use OBJECT tag to call PHP script that displays the text file content with ECHO. It works. But the result is displayed inside a small frame and I can't apply CSS style to it or align it properly with the existing text. Is there another way? I understand it can be done with AJAX call but my scripting knowledge is basic and I wouldn't know where to begin. Help would be appreciated.
To display the result in the blog I used this code:
<p>File test.zip downloaded
<object type="text/plain"
data="http://example.com/statistics.php?dname=test"
width="30" height="30"></object> times</p>
EDIT: I have tried to follow #Toni suggestion but it only leads to more questions. Looks like Ajax call is way beyond my current level of knowledge. Sorry and thank you again.
Here is what I'm currently trying. I have moved the text that goes with the counter inside PHP file so the script now returns a string like "file has been downloaded 8 times" instead of just number "8". Also instead of OBJECT tag I'm using IFRAME.
<iframe src="http://example.com/mystats.php?dname=test"
frameborder="0" border="0" cells pacing="0" height="30"></iframe>
The iframe seems to be easier to style. If I can't figure out how to find which CSS is applied to a blog post and how to apply it to iframe, I can at the minimum mimic the style by using similar font.
You can use javascript with your blogger web-site.
Using javascript on your web-page, you can invoke a GET request to your PHP code and get the data you want, to display it on your web-page.
Below, there are links, to help you with this task:
How to invoke GET request in vanilla JavaScript
Invoking GET with jQuery
Use JavaScript to alter text dynamically
I made it work with JavaScript! Here is how. Server side PHP script reads and echoes a text file inside document.write().
<?php
$varcontent = #file_get_contents('yourtextfile.txt');
echo 'document.write("'.$varcontent.'")';
?>
The resulting string looks like this:
document.write("your text file content here")
Inside the Blogger post add the JavaScript code with the PHP script file as a source:
<script type="text/javascript"
src="http://example.com/yourfile.php">
</script>
Done! The content of your text file is displayed and styled with your current CSS.
Is there any way i can load PDF file (its contents) in a div or iFrame?
I have a bunch of PDF files on a server and, ideally, i need to have a button 'Show file' on a page, clicking on which will load the contents of selected file in a div(iFrame).
You can also use google pdf view by using iframe on your page :
<iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
Instead of this in above code :
http://infolab.stanford.edu/pub/papers/google.pdf
Use your own PDF file path.
You can view the demo here.
http://googlesystem.blogspot.in/2009/09/embeddable-google-document-viewer.html
It's just a suggestion. No downvotes please.
Google's gview is sometimes unresponsive and given 204 status. Here is the best free alternative.
https://stackoverflow.com/a/66548544/2078462
I have large pdf files on my website and i would like to display a "the pdf file is loading" page while the pdf is loading. And once it's loaded redirect automaticaly to the pdf file.
Is there a way to do it?
If anyone has an idea on how to do this it would be great.
With Ajax http://api.jquery.com/jQuery.ajax/
Also you use this method:
First show the element(for ex. <div class="loading"></div>) where written ("PDF loading"). and then when your PDF is loaded you hide that element.
$("pdf container").load(function(){
$(".loading").hide();
});
I want to build a page that will automatically print a pdf document. For example I can call mypage.html?doc=my.pdf and it will print my.pdf file.
How I can do it using javascript or php?
Vladimir
The closest you can get to what you want is to embed an iframe containing the PDF in an HTML page, then call window.print when the iframe has loaded.
...
<iframe src="path/to/file.pdf" onload="window.print()"></iframe>
...
This will open the standard print dialog on most browsers.