简体   繁体   English

以html格式提交嵌入式pdf

[英]Submitting embedded pdf in html form

I've searched in vain for days, but haven't found a solution for my problem yet. 我已经搜寻了好几天,但没有找到解决我的问题的方法。

Ideally, I would like to embed a fillable pdf form into an intranet html form for submission to the server for processing (ability to parse the field/values would be gravy, but not required). 理想情况下,我想将可填充的pdf表单嵌入到Intranet html表单中,以提交给服务器进行处理(解析字段/值的能力很重要,但不是必需的)。 The files are all in the same domain so no cross-domain issues. 这些文件都在同一域中,因此没有跨域问题。 I know I could add submission functionality to the pdf form itself, but 1) scripting is beyond the ability of the pdf document administrator and I don't want to take that on, 2) there are hundreds of pdf documents, 3) I need additional scripted fields/values submitted with the form, 4) I want the pdf document to be contained within the login session. 我知道我可以将提交功能添加到pdf表单本身,但是1)脚本超出了pdf文档管理员的能力,我不想接受它; 2)有数百个pdf文档,3)我需要随表格一起提交的其他脚本字段/值,4)我希望pdf文档包含在登录会话中。 So far, the server log shows all the field/values, except the PDFInput parameter which is passed, but the value is empty. 到目前为止,服务器日志显示了所有字段/值,但传递的PDFInput参数除外,但该值为空。

Here's what I have so far: 这是我到目前为止的内容:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $(uploadForm).on("submit", function(event) {
            var iframe = document.getElementById('PDFObj');
            var iframeDocument = [iframe.contentDocument || iframe.contentWindow.document];

            var pluginData = iframeDocument;
            $(this).append('<input type="file" name="PDFInput" id="PDFInput" value="' + pluginData + '" style="visibility:hidden"/>');
            return true;
        });
    });
</script>

and

<form enctype="multipart/form-data" method="post" name='uploadForm' id='uploadForm'>
    <input type='hidden' name='rm' id='rm' value='uploadFile'>
    <table align='center'>
        <tr>
            <td align='left'>
                <strong>Notes:</strong>
                <br>
                <textarea cols='80' rows='2' name='notes' id='notes'></textarea>
                <br>
                <br>
            </td>
        </tr>
        <tr>
            <td colspan=2 align='center'>
                <input type='submit'>
            </td>
        </tr>
        <tr>
            <td colspan=2>
                <br>
                <input type='hidden' name='formid' id='formid' value='6F45B3AF-91F3-108C-D3D9-701F541B49DC'>
                <iframe type='application/pdf' src="url.pl?formid=6F45B3AF-91F3-108C-D3D9-701F541B49DC.pdf" height='800' width='1000' name='PDFObj' id='PDFObj'>
            </td>
        </tr>
    </table>
</form>

I've tried embedding it using iframe and object along with setting input type="object", but I can't get any combination to work. 我尝试使用iframe和object以及设置输入type =“ object”嵌入它,但是我无法使用任何组合。

Is this even possible? 这有可能吗? Is there a better approach? 有没有更好的方法?

As far as I know, you're not going to be able to capture the PDF data directly from HTML like that. 据我所知,您将无法像这样直接从HTML捕获PDF数据。 Your best bet is going to be to add submit functionality to the PDFs, then process the resulting FDF data with a server-side script. 最好的选择是将提交功能添加到PDF,然后使用服务器端脚本处理生成的FDF数据。

You will need either add Submit a Form buttons to your PDFs, or modify the existing buttons. 您需要将“ Submit a Form按钮添加到PDF中,或修改现有按钮。 Make sure the form action in the PDF has #FDF after the URI (eg https://example.com/process.php#FDF ). 确保PDF中的表单操作在URI之后具有#FDF (例如https://example.com/process.php#FDF )。

Parsing the data server side is simple. 解析数据服务器端很简单。 I'm not sure what server side language you are using, but here is a PHP snippet 我不确定您使用的是哪种服务器端语言,但这是一个PHP代码段

<?php // process.php, report the data we received 
echo '<h2>GET Data</h2>'; 
foreach( $_GET as $key => $value ) { 
  echo '<p>Key: '.$key.', Value: '.$value.'</p>'; 
} 
echo '<h2>POST Data</h2>'; 
foreach( $_POST as $key => $value ) { 
  echo '<p>Key: '.$key.', Value: '.$value.'</p>'; 
} 

Note that a PDF only interacts with a web server properly when viewed inside of a web browser. 请注意,在Web浏览器中查看PDF时,PDF只能与Web服务器正常交互。

I do not know of a reliable way to programmatically add submit buttons to PDFs, nor do I know of a reliable conversion method. 我不知道以编程方式将提交按钮添加到PDF的可靠方法,也不知道可靠的转换方法。 You're between a rock and a hard place here IMHO. 您在这里恕我直言,介于岩石与艰辛之间。

More info: 更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM