在我的 LOCALHOST 上,我有一个创建 FDF 文件的表单...此外,在该文件中它还包含一个“完整路径”-> 'http://localhost/example/example.pdf'...所以当我'点击在浏览器中打开 FDF 文件的链接,它会加载 PDF,并将 FDF 数据插入到正确的位置。
当我在 Linux 服务器(非本地)上执行此操作时,当我单击 FDF 文件将其打开时,它只是打开文件,并将文本(fdf 文件)呈现到屏幕上,而不是“打开”fdf 文件。
想知道是否有人可以帮助我完成这个过程...我想打开 FDF 文件,因此它也打开 PDF 文件。
这是我已经完成的一些代码,但我已经注释掉了“标头”...因为我认为“打开”文件时不需要标头,而不是将其渲染到屏幕上?
$fdf = new fdf();
//$response = $fdf->fdfMerge(APP_ROOT."/forms/test/FormTest.pdf", $_POST);
$response = $fdf->renderFDF(DOMAIN."forms/test/FormTest.pdf", $_POST, $_POST['userId'], $_POST['contactId']);
//var_dump($response);
// Link DIRECTLY to the FDF file...
echo "Internal: <a href='". $response['internalPath'] ."'>". $response['internalPath'] ."</a><br />";
echo "External: <a href='". $response['externalPath'] ."'>". $response['externalPath'] ."</a><br />";
/*
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-Type: application/x-download");
header("Content-Disposition: attachment; filename=".$response['fdfFile'].";" );
header("Content-Length: ".$filesize($response['fdfFile'])."");
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
fopen($response['fullPath']);
*/
--- 来自 LINUX 框的浏览器响应 ---
%FDF-1.2
%âãÃÓ
1 0 obj
<<
/FDF << /Fields [ <</T(formId)/V(111)>><</T(userId)/V(23)>><</T(contactId)/V(2950)>><</T(firstName)/V(Justin)>><</T(lastName)/V(Geezer)>><</T(email)/V([email protected])>>]
/F (https://www.example.com/forms/test/FormTest.pdf) /ID [ <bd71513804f75900e899f3be924b69ef>
] >>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
这是我使用“HEADER”响应时的屏幕截图。
编辑:如果我从服务器下载 FDF 文件,并且“双-单击“打开文件”,它会从网络下载 PDF 文件并正常打开。
On my LOCALHOST, I have a form that creates and FDF file... Also in that file it includes a 'full-path' -> 'http://localhost/example/example.pdf'.... So when I 'click the link' to open the FDF file within the browser, it loads the PDF with the FDF data inserted in the proper locations.
When I do this on my Linux Server (not local), when I click the FDF file to open it, it just OPENS the file, and renders text (fdf file) to the screen instead of 'opening' the fdf file.
Wondering if anyone can help me out with this process... I want to open the FDF file and so it opens the PDF file as well.
This is some code that I have done, but i have commented out the 'headers'... as I didn't think I needed headers when 'opening' a file, rather than rendering one to screen?
$fdf = new fdf();
//$response = $fdf->fdfMerge(APP_ROOT."/forms/test/FormTest.pdf", $_POST);
$response = $fdf->renderFDF(DOMAIN."forms/test/FormTest.pdf", $_POST, $_POST['userId'], $_POST['contactId']);
//var_dump($response);
// Link DIRECTLY to the FDF file...
echo "Internal: <a href='". $response['internalPath'] ."'>". $response['internalPath'] ."</a><br />";
echo "External: <a href='". $response['externalPath'] ."'>". $response['externalPath'] ."</a><br />";
/*
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-Type: application/x-download");
header("Content-Disposition: attachment; filename=".$response['fdfFile'].";" );
header("Content-Length: ".$filesize($response['fdfFile'])."");
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
fopen($response['fullPath']);
*/
--- BROWSER RESPONSE FROM LINUX BOX ---
%FDF-1.2
%âãÃÓ
1 0 obj
<<
/FDF << /Fields [ <</T(formId)/V(111)>><</T(userId)/V(23)>><</T(contactId)/V(2950)>><</T(firstName)/V(Justin)>><</T(lastName)/V(Geezer)>><</T(email)/V([email protected])>>]
/F (https://www.example.com/forms/test/FormTest.pdf) /ID [ <bd71513804f75900e899f3be924b69ef>
] >>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
Here is a ScreenShot, when I use the "HEADER" responses.
Edit: If I download the FDF file from the server, and 'double-click' to open the file, it downloads the PDF file from the web and opens it fine.
发布评论
评论(1)
最好的猜测是 fpdf 无法写入 tmp 目录,或者它正在使用的文件被阻止了。检查你的 apache 日志,你能给出一个在 linux 上显示的文本示例吗?您的 php 文件中可能存在空格或回车键。例如
,在结束标签和开始标签的中间,有一个返回键,它可能会在 Linux 上搞乱事情,但在 Windows 上不会(因为 Windows 会忽略导致换行的特殊字符)。
另外,在 fpdf 生成代码的末尾,不要关闭标签,即:
Best guess is the fpdf can't write to a tmp directory, or the files it's using are some how blocked. Check your apache logs, and can you give an example of the text that is displayed on linux? There might be a white space or return key in your php file. for example
In the middle with the closing and opening tags, there's a return key which can mess things up on linux but not windows (as windows ignores the special character that causes a new line).
Also, at the end of the fpdf generating code, dont close the tag, ie: