【问题标题】:Filling out a PDF form and submitting to the server via PHP填写 PDF 表单并通过 PHP 提交到服务器
【发布时间】:2013-11-01 23:26:35
【问题描述】:

我在 Livecycle Designer ES3 中创建了一个 PDF 表单。

我的工作是让提交按钮将整个 pdf 保存在服务器上的某个文件夹中。

该按钮指向我的 Web 服务器上的一个 php 文件。该按钮的类型为“提交”,并作为“URL 编码日期 (HTTP)”提交。

我试过了:

$file = $GLOBALS['HTTP_RAW_POST_DATA'];
$newfile = "/var/watchfolder/" . microtime(true) . ".pdf";
file_put_contents($newfile, $file);

我也试过了:

$file = file_get_contents("php://input");
$newfile = "/var/watchfolder/" . microtime(true) . ".pdf";
file_put_contents($newfile, $file);

他们两次都写了一个文件,但文件的内容是这样的:

OrderDate=&DocumentNo=&Concat_BuyfromVendorNo_BuyfromVendorName=&JobNo=&TicketNo=&Concat_SellToCustomerNo_SellToCustomerName=&LineNo_1=&No_1=&OutstandingQuantity_1=&Quantity_1=123&...

Reader 或 Acrobat 都不会将其作为有效的 pdf 打开。

如何让它写成 pdf 格式的文件?


更新:

* 我想通了。在 Livecycle 中选择“提交为:PDF”并将其指向您的 php 文件。

我的看起来像:

<?php
ob_start();
$file = file_get_contents("php://input"); //Gets binary PDF Data
$time = microtime(true);
$newfile = "/var/watchfolder/" . $time . ".pdf"; //Names xml file based on the time to the microsecond so nothing gets overwritten.
$worked = file_put_contents($newfile, $file); //Creates File
ob_end_clean();

$file = "/var/www/forms/Submission_Confirmation.pdf";
$filename = 'Submission_Confirmation.pdf'; /* Note: Always use .pdf at the end. */

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);

?>

最后一部分在阅读器中加载 PDF 作为确认。它可以是您想要的任何 pdf,包括刚刚提交的 PDF。

Reader 在 Acrobat 中扩展 PDF

填写并提交

瞧!

【问题讨论】:

    标签: php forms pdf livecycle


    【解决方案1】:

    那是因为纯文本/html (ASCII) 不是 pdf 格式(至于二进制)。

    您需要使用 PHP PDF,可以在这里找到很好的示例和操作方法:

    http://www.php.net/manual/en/pdf.examples-basic.php

    另外,$GLOBALS['HTTP_RAW_POST_DATA']; 只是个问题。检查$_POST全局变量并检索需要放入pdf文件的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多