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?
Related
Im in a situation where users can click a download button in a pop up. When they click "download", a request is made to my php script. The php script generates the PDF, echoes a script tag to close the modal and then downloads the PDF. I dont want to do a setTimeout to close the modal because of the timing differences for the PDF to be generated, which is why im echoing the script tag to close the modal. I've tried using ob_start/ob_end_flush but it still wont work. help! Thanks :)
The file gets downloaded, but the script tags wont get echoed. If I comment out the header & readfile, the script tags get echoed, so I know its just because output stops or something.
ob_start();
echo('<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>');
echo('<script>jQuery("body", window.parent.document).find("#pdfModal").addClass("out").removeClass("in")</script>');
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='results.pdf'");
readfile('../wp-content/plugins/ajaxpostfromfront/' . $token . '/results.pdf');
ob_end_flush();
How to render a popup in YII controller action?
i want to open new window for some actions...please help me with this...
(i want this when i call a action not when i click a link)
Ex. when i go to view action in invoice controller it should open in a new window...
is there any way to render a popup...
This is my action which generate pdf using MPDF... It should open in a new window.
public function actionReport() {
$date=Yii::app()->Date->onlyNow();
$name="ITEM Reprt(".$date.")";
$mPDF1 = Yii::app()->ePdf->mpdf('L', 'A5');
$mPDF1->WriteHTML($this->renderPartial('test', array(), true));
$mPDF1->Output($name,'I');
}
THANKS...!
Why popups? Simply create link with target="_blank", browser will open new window or new tab - per user preferences.
Print PDF!
You can even embed pdf or use pdfobject etc.
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
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
I need your quick help.
In my web site I have a list of clients with links to their user details.
I used
window.open();return false;
and this opens each profile in new window.
now in the new opening window I have link, which I want to open in another new window/
I tried
window.opener.open();return false;
but it opened in this same window.
How can it be opened in another new window(FF,explorer)??.
I want also to use the above code with Ajax, in my search page.
The problem is, that it also not opening the new window because the link located in the Ajax. how can i open links from Ajax in new window??
Any ideas?
Thanks!!!
Well you can access window.parent from your window object and call a function that will open another window
Use Window.open() in the opened window.
So you have : (1) Page with a link -> (2) opens a popup with a link -> (3) opens another popup
Every link which has to open a popup will call the javascript function window.open. As #Sushil pointed out, if the new window has to look like a regular popup, set width and height to it.
If you want to implement the popups using AJax, use jQuery. Here is a very good example for a simple popup implementation.
Providing height and width to open. this will make sure that new window always open as popup.
window.open(url, 'name', "height=500,width=700"); return false;