2015-05-14 75 views
0

我已经在白天搜索了几天,但还没有找到我的问题的解决方案呢。以html格式提交嵌入式pdf

理想情况下,我想将可填写的pdf表单嵌入到Intranet html表单中,以便提交给服务器进行处理(能够解析字段/值将是肉汁,但不是必需的)。这些文件都在同一个域中,所以没有跨域问题。我知道我可以向pdf表单本身添加提交功能,但是1)脚本功能超出了pdf文档管理员的能力,我不想这样做,2)有数百个pdf文档,3)我需要附加脚本字段/值与表单一起提交,4)我希望pdf文档包含在登录会话中。到目前为止,服务器日志显示所有字段/值,但传递的PDFInput参数除外,但该值为空。

这是我到目前为止有:

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

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

我试着用iframe,并设置输入型=“对象”沿对象嵌入它,但我可以”没有任何组合可以工作。

这甚至可能吗?有更好的方法吗?

+0

嗯有趣。您可以使用'pdf.js'查看PDF客户端,然后在提交时,'填充'填充的版本,将其转换为base64字符串并将其提交回服务器。这看起来相关:https://stackoverflow.com/questions/13538832/convert-pdf-to-a-base64-encoded-string-in-javascript – lispHK01

回答

0

据我所知,你不能直接从HTML那样捕获PDF数据。您最好的选择是将提交功能添加到PDF中,然后使用服务器端脚本处理生成的FDF数据。

您将需要将Submit a Form按钮添加到您的PDF或修改现有的按钮。确保PDF中的表单操作在URI后面有​​(例如https://example.com/process.php#FDF)。

解析数据服务器端很简单。我不知道你用的是什么服务器端语言,但这里是一个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>'; 
} 

注意,一个PDF只使用Web浏览器的内侧观察正确的web服务器进行交互。

我不知道有一种可靠的方式来以编程方式向PDF添加提交按钮,我也不知道可靠的转换方法。你是在一个摇滚和困难的地方在这里恕我直言。

更多信息: