Open FPDF in a new tab
I have a generated pdf (fpdf) from a post form. I would like the PDF to open in a new tab and / or window, prompting the user to save the PDF. I am assuming that I need to store the output to a string
$data=$pdf->Output("OfficeForm.pdf", "S");
but what exactly can I do with this line to open it in a new window. I tried something like this but it doesn't work. Am I on the right track or is window.open not what I need?
echo "<script type=\"text/javascript\">
window.open('$data', '_blank')
</script>";
source to share
I just added target = "_ blank" to my form open tag and used $ _SESSION []; pass my form to FPDF code:
<?php session_start(); ?>
<form id ="buildPDFform" name="buildPDFform" target="_blank" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
...some code for my form
<input type="submit" name="buildPDf" id="buildPDf" class="buildPDFbutton" value="Build the PDF">
</form>
Then, when the form is submitted, I collect my form elements, put them in an array, create a session that contains the array, and use the header ("Location: testcode.php") to redirect to where my FPDF code is located.
if (isset($_POST['buildPDf'])) {
$pdfArray = array();
foreach ($_POST as $key => $value) {
...gather your form items into your array
}
$_SESSION['pdfArray'] = $pdfArray;
header("Location: testcode.php");
}
And don't forget in your FPDF code file (testcode.php in my case) to grab your session with an array.
<?php
session_start();
$pdfArray = $_SESSION['pdfArray'];
... your FPDF code
$pdf->Output('I');
?>
source to share