在新标签中打开FPDF[英] Open FPDF in new tab

本文是小编为大家收集整理的关于在新标签中打开FPDF的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

i从帖子表格中生成了PDF(FPDF).我希望PDF在新的选项卡和/或窗口中打开,以提示用户保存PDF.我猜我需要将输出保存到字符串

$data=$pdf->Output("OfficeForm.pdf", "S");

但是,我可以用这个字符串做些什么才能使其在新窗口中打开.我尝试过这样的事情,但它不起作用.我是在正确的轨道上还是窗口.打开我需要的?

echo "<script type=\"text/javascript\">      
window.open('$data', '_blank')    
</script>";

推荐答案

如果您使用表格,可以通过在-tag中指定target ='_ blank'(旁边应该提交='sosity')

来执行此操作.

示例:

这将在提交中打开一个新的选项卡(显示任何" makepdf.php").

希望它正确回答问题

其他推荐答案

我只是将target =" _ blank"添加到我的表单打开标签中,并使用$ _SESSION [];将我的表格传递到FPDF代码:

<?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>

然后,当提交表单时,我收集我的表单项目,将它们放入数组中,创建一个会话,并使用标题("位置:testcode.php")将其重定向到我的FPDF代码所在的位置.

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");
}

,不要忘记您的FPDF代码文件(在我的情况下在TestCode.php)中获取具有数组的会话.

<?php
    session_start();
    $pdfArray = $_SESSION['pdfArray'];

     ... your FPDF code

    $pdf->Output('I');
?>

其他推荐答案

来源: https://www.thesitewizard.com/html-tutorial/open-links-in-new-new-window-or-tab.shtml

使用 target =" _ blank" 在您的 a 标签中,将其打开到新标签

本文地址:https://www.itbaoku.cn/post/2090898.html

问题描述

I have a pdf generated (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'm guessing I need to save the output to a string

$data=$pdf->Output("OfficeForm.pdf", "S");

but what exactly can I do with this string to get it to open in a new window. I've attempted something like this but it's not working. Am I on the right track or is window.open not what I need?

echo "<script type=\"text/javascript\">      
window.open('$data', '_blank')    
</script>";

推荐答案

If you use a form you can do it by specifying target='_blank' in the -tag (next to where you should have submit='something')

Example:

This will open a new Tab (showing whatever "makepdf.php" produces) on submit.

Hope it answers the question correctly

其他推荐答案

I simply added target="_blank" to my form opening tag and used $_SESSION[]; to pass my form to the 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 gather my form items, put them in an array, create a session the array goes into and use a header("Location: testcode.php") to redirect to where my FPDF code is.

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 that has the array.

<?php
    session_start();
    $pdfArray = $_SESSION['pdfArray'];

     ... your FPDF code

    $pdf->Output('I');
?>

其他推荐答案

source: https://www.thesitewizard.com/html-tutorial/open-links-in-new-window-or-tab.shtml

use target="_blank" in your a tag to open it to new tab