Save as pdf in print window javascript code - php

HELP.. how to Save as pdf in print window in javascript code
How to change this code ?
PDF
I need to make my link open the print window but automatically set the destination to "Save as pdf" instead of "print"?

You cannot do this via javascript.
You can do this:
PDF
In getpdf form pdf file via TCPDF or other

Related

Get Printers dialog when using mPDF instead of Save As dialog

I'm trying to find a way to open a "choose printer" dialog when the user push "print", in my PHP page, not the SaveAs window.
i read all posts here , couldn't find a reply that works.
also read this post :
mPDF auto print issue
but the following code opens the saveas window, not the "choose printer" window:
$pdf=new mPDF('en','A4','','DejaVuSansCondensed',$template->margin_left,$template->margin_right,$template->margin_top,$template->margin_bottom,$template->margin_header,$template->margin_footer);
$pdf->setAutoFont();
$pdf->SetHTMLHeader($header);
$pdf->SetHTMLFooter($footer);
$pdf->SetJS('this.print();');
$pdf->writeHTML($printable);
$pdf->Output();
can anyone help?
why do i still get the "save as" window?
To get a print dialog, you can simply use JS
window.onload = function() { window.print(); }
MPDF Functions:-
You can also use
<?php
// Saves file on the server as 'filename.pdf'
$mpdf=new mPDF();
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output('filename.pdf','F');
?>
OR
ADD 'D' parameter to download it
$mpdf->Output('filename.pdf', 'D');
Also REFER How to open print dialog after pdf generated?

open dompdf in new tab taken data from given page

I know that there are at least two other similar questions, but they do not help me.
I have textarea with tinymce where user writes his text. Then there is a button "PDF" that should create pdf and open it in new tab. The content of pdf is the content in tinymce.
When user click on button, the form is submitted to index.php action. Then index.php gathers information from $_POST variable and creates pdf.
I cannot get it to open in new tab as a normal link.
I tried it in different ways.
1) I can open PDF in the same tab, but this is not what I need. This line opens my pdf on the same tab:
$dompdf->stream('document.pdf',array('Attachment'=>0));
2) I can open it in new window, but then browser warns that this is pop-up. Client doesn't want it. Also another problem with this is that pdf is stored on server. I do not want it (pop-up warning is more important). Here is my code:
$output = $dompdf->output();
file_put_contents('document.pdf', $output); //save pdf on server
//opens generated pdf in new window, but this creates warning for popup
echo '<script type="text/javascript" language="javascript">
window.open("http://modeles-de-lettres.org/test/saved_pdf.pdf", "_blank");
</script>';
I have read those:
1) Open PDF in a new tab using dompdf
This suggests: "As far as opening in a new tab. That depends on how you are generating the PDF. But the simplest way it to provide a link with a target attribute." I think this means that I have
<a href="my.pdf" target="blank"
or
<a href="my.php" target="blank"
But this does not work for me, because I should POST my form to get data from pdf.
2) generate the pdf on newtab in dompdf
This is something that I have implemented before (I did it without sessions), but it creats warning about popups.
You can simply do the following:
<button type="submit" formtarget="_blank">Submit to a new window</button>
formtarget="_blank" attribute will open new tab.
Hope it will help you!
The problem is the order in which you're doing things. You should be opening the new window from a user event, like clicking a button. If a script on a page load event tries to open a window, the browser will presume it's an unwanted popup, since the user hasn't done anything besides navigating to the page.
What could work for you, is adding a target="somewhere_new" attribute to your form tag. This way, the browser would open a new tab since there's no frame/iframe with a name="somewhere_new" attribute, and you wouldn't have to do anything special in the server side, just process the data as you did before using $dompdf->stream('document.pdf',array('Attachment'=>0)); at the end

How to access an Image in PDF using JavaScript?

I added an image to PDF using $p->load_image (http://www.php.net/manual/en/function.pdf-fit-image.php). Now, I want to write JavaScript in it so that the user can manipulate image in the PDF. How can I get access to the image in PDF using Javascript?
Using PdfLib, add the following option to the load_image call:
"iconname=HelloImage" where HelloImage is the name of the image. The complete call would be,
$p->load_image('jpeg', 'C:/hello.jpg', "iconname=HelloImage");
In Javascript code, you can access it. For example,
var hello_image = this.getIcon("HelloImage");
Now hello_image points to the HelloImage.

Determine if uploaded PDF is editable using PHP?

Can we determine if PDF is editable or not using PHP?
I have a PDF form. If user uploads such a PDF then I have to force User to click on SUBMIT button of PDF.
To implement this functionality I have to determine if PDF is editable or not.
Thanks in advance for help and suggestions that you might have
A very simple way is to search for the text string <</AcroForm in the file:
<?php
$s = file_get_contents("test.pdf");
$has_form = preg_match('/<<\s*AcroForm\b/', $s);
?>

save a file generated by a php script in to a directory by save dialog form

I have a php script that generate a pdf file.
So I have an html page with jquery javascript that do an ajax call at this php script and retrieve the pdf file content.
I would that this file will be saved in a location choosed by a save file dialog.
How can I do it?
Thank you so much.
You don't need Ajax - just do a
location.href = "fileURL.php";
(or alternatively, have the user click on a link) and if the headers are set correctly, a download dialog will present itself.

Categories