无法将iText生成的pdf发送到docuSign

时间:2014-02-25 13:01:07

标签: itext docusignapi

我正在尝试将信封中的两个pdf发送到docusign。 pdf是使用iText库生成的。仅在使用iText生成的pdf时才会出现此问题。其他(从网上下载)pdfs在我的应用程序中使用docusign工作正常,所以在java代码中没有问题。在信封内发送单个(iText生成的)pdf也没有问题。仅在发送多个(iText生成的)pdf文档时才会出现问题。使用docusign REST api发送此pdf时,我收到了一个http 400 Bad Request错误。任何人都可以在我的pdf中指出问题。

以下是我要发送的pdf的链接。

http://www.pdfhost.net/index.php?Action=Download&File=c8eeab729a8299e08e643d99afa00672 http://www.pdfhost.net/index.php?Action=Download&File=c8e0d2b8dfa9c2b82d10cc0503995310

提前致谢。

-----编辑-----

在Adobe Reader中使用“另存为新PDF”选项并保存文档后,我尝试了这两个文档。在此之后,两个pdfs成功上传到docusign。有人可以帮助我解决Adobe Reader对我的文档进行的更改,使其与docusign一起使用。使用“另存为新pdf”选项后,pdf的大小也增加了,快速Web视图属性设置为YES。

-----编辑-----

这是我对docusign的请求内容。这次使用iText生成的简单文本pdf。此请求也会导致400 Bad请求错误。

--BOUNDARY
Content-Type: application/json
Content-Disposition: form-data

{"status":"sent","emailBlurb":"email body","emailSubject":"email subject","documents":[{"documentId":"501","name":"cc5fda55_pdf","order":"1"},{"documentId":"502","name":"cc5fda56_pdf","order":"2"}],"recipients":{"signers":[{"recipientId":"74d5772d-6a5b-4fb0-b95d-947d8ecafd3c","returnUrl":null,"name":"Lucy Lu","email":"lucy.lu@gmail.com","clientUserId":"74d5772d-6a5b-4fb0-b95d-947d8ecafd3c","routingOrder":"1","tabs":{"signHereTabs":[{"documentId":"501","pageNumber":"1","anchorString":"ee_signature","anchorXOffset":"0","anchorYOffset":"0","anchorIgnoreIfNotPresent":"true","anchorUnits":"inches"},{"documentId":"502","pageNumber":"1","anchorString":"ee_signature","anchorXOffset":"0","anchorYOffset":"0","anchorIgnoreIfNotPresent":"true","anchorUnits":"inches"}]}}]}}
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="cc5fda55_pdf"; documentId=501

%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 77/Filter/FlateDecode>>stream
<BYTE CONTENT HERE>
endstream
endobj
4 0 obj
<</Parent 3 0 R/Contents 2 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 1 0 R>>>>/MediaBox[0 0 595 842]>>
endobj
1 0 obj
<</BaseFont/Helvetica/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
3 0 obj
<</ITXT(5.0.6)/Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText 5.0.6 \(c\) 1T3XT BVBA)/ModDate(D:20140303192905+05'30')/CreationDate(D:20140303192905+05'30')>>
endobj
xref
0 7
0000000000 65535 f 
0000000315 00000 n 
0000000015 00000 n 
0000000403 00000 n 
0000000158 00000 n 
0000000466 00000 n 
0000000511 00000 n 
trailer
<</Root 5 0 R/ID [<e5359ec2954ce59003907592ee9885c4><af4ec60043c4444d2e7f07c3286e29da>]/Info 6 0 R/Size 7>>
startxref
641
%%EOF
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="cc5fda56_pdf"; documentId=502

%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 77/Filter/FlateDecode>>stream
<BYTE CONTENT HERE>
endstream
endobj
4 0 obj
<</Parent 3 0 R/Contents 2 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 1 0 R>>>>/MediaBox[0 0 595 842]>>
endobj
1 0 obj
<</BaseFont/Helvetica/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
3 0 obj
<</ITXT(5.0.6)/Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText 5.0.6 \(c\) 1T3XT BVBA)/ModDate(D:20140303192905+05'30')/CreationDate(D:20140303192905+05'30')>>
endobj
xref
0 7
0000000000 65535 f 
0000000315 00000 n 
0000000015 00000 n 
0000000403 00000 n 
0000000158 00000 n 
0000000466 00000 n 
0000000511 00000 n 
trailer
<</Root 5 0 R/ID [<e5359ec2954ce59003907592ee9885c4><af4ec60043c4444d2e7f07c3286e29da>]/Info 6 0 R/Size 7>>
startxref
641
%%EOF

--BOUNDARY--

1 个答案:

答案 0 :(得分:1)

我已经测试了您的PDF并且我已经证明问题不是由iText引起的,而是由使用iText创建PDF或提供PDF的服务的人引入的错误。请在纯文本编辑器中打开文档。你会看到这个:

%PDF-1.4
%âãÏÓ
3 0 obj <</Length 236/Filter/FlateDecode>>stream
xœu‘?kÃ0Å÷û7¶Týq$y-´CK†€ CÈ+¶±kbòõ{’b‡  é~Ü{ÇC:ÇŽY¾bÊ¢;§ƒ
œ3®Ì
/ ñ›ú5ŽkØî8 ÃêO ,fÆcÒJ–ÏÜD–ŠX3­ˆ…e4oÆüÛÂ×O˜Î@TN®ëäÔkŸ(¯q–®ü.ïm¾ÅÔ~Åc>9Ù
öÄÍÄA•&õ’fm ¿ðÞýýK è<ˆø¤•ŽÊÌ0«ÑµðâÊj@Ú÷Õ¡Ú7¡(zlŠq¤Ëw=þìÇ×Ý0¸KÇ^]=ýàþâqe»
endstream
endobj
1 0 obj<</Parent 4 0 R/Contents 3 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 2 0 R>>>>/MediaBox[0 0 300.98 495.38]>>
endobj
2 0 obj<</BaseFont/Times-Roman/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
4 0 obj<</Type/Pages/Count 1/Kids[1 0 R]>>
endobj
5 0 obj<</Type/Catalog/Pages 4 0 R>>
endobj
6 0 obj<</Producer(iText 2.0.8 \(by lowagie.com\))/ModDate(D:20140225153804+05'30')/CreationDate(D:20140225153804+05'30')>>
endobj
xref
0 7
0000000000 65535 f 
0000000318 00000 n 
0000000480 00000 n 
0000000015 00000 n 
0000000569 00000 n 
0000000619 00000 n 
0000000663 00000 n 
trailer
<</Root 5 0 R/ID [<3edf7c900aab4e26d6ac2b1326544426><539a2d0a5c5a341b17d8331a3eab6622>]/Info 6 0 R/Size 7>>
startxref
794
%%EOF

这是一个普通的,有效的PDF文档,使用强大的旧版iText生成。你可以通过lowagie.com(我是Lowagie)认出我的名字。你不会对这个文件有任何问题。

但是,如果向下滚动,您会看到:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PDF&nbsp;Host</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
a:link {
    color: #999999;
    text-decoration: none;
}
a:visited {
    color: #CCCCCC;
    text-decoration: none;
}
a:hover {
    color: #99CCCC;
    text-decoration: none;
}
a:active {
    text-decoration: none;
}
.style1 {color: #FFFFFF}
-->
</style>
<script type="text/javascript">

  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-24601794-1']);
      _gaq.push(['_trackPageview']);

        (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
              })();

              </script>
              </head>
<body bgcolor="#2d878f" background="bkg.jpg" style="background-repeat:repeat-x" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<p>&nbsp;</p>
<table width="725" height="423" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
    <td height="197" valign="top">
    <img src="images/pdfhost2_01.jpg" width="725" height="197" alt=""></td>
  </tr>
    <tr>
        <td height="53"><table width="725" height="53" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th bgcolor="133841" scope="col"><a href="index.php" class="style1">Home</a> - <a href="index.php?Action=Upload" class="style1">Upload PDF&nbsp;Document</a></th>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td valign="top"><table width="725" height="175" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th height="59" background="tbk.jpg" scope="col"><div align="center"></div>
            <table width="680" height="306" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <th valign="top" scope="col">                  <p align="center"><br>
                </p>
<p align="left" class="style2">

                  Welcome to PDFHost.NET!<br /><br />

                  On this website you can upload PDF documents to send to your friends, family, and other people.<br />
                  The service on this website is completely free. We can provide this service through our advertisers.<br /><br />

                  To upload a PDF document, please click on the button below. You will be asked to fillin all the needed information to complete the upload.<br /><br />
                  <p align="center"><a href="index.php?Action=Upload"><img src="button.jpg" style="border-style: none"/></a> </p>

                                </p><br /><br />
    <script type="text/javascript"><!--
google_ad_client = "ca-pub-3986885209750256";
/* PDFHost.net */
google_ad_slot = "9986575127";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
    <br>
            </p></th>
          </tr>
        </table>

        <p align="left">&nbsp;</p></th>
      </tr>
    </table></td>
</tr>
<tr>
    <td>
        <img src="images/pdfhost2_04.jpg" width="725" height="10" alt="">   </td>
</tr>
</table>

<p>&nbsp;</p>
</body>
</html>

这是HTML,这不属于PDF文件。很明显,这个HTML不是由iText添加的。 Adobe Reader将忽略HTML并正确显示PDF,但是当您尝试关闭PDF时,它会要求您保存PDF。其他工具可能会出现HTML问题。

如何解决这个问题?丢弃%%EOF之后的所有内容,您将获得有效的PDF。我用Adobe Preflight对此进行了测试,得到了一个绿色复选标记(意思是:PDF中没有语法错误)。

我的答案可能无关紧要:似乎HTML是由您用来分发PDF的服务添加的(PDFHost.NET,这家公司显然已经发现了一种相当肮脏的推广方式本身)。在这种情况下,请使用不会污染“证据”的分销渠道; - )

我很确定这个问题与iText无关,因为您说发送使用iText生成的单个文件时服务正常,只有当您发送两个文件时。这就提出了一个问题,当你发送两个文件时有什么不同:你用哪种方法来组合两个文件?

最后:我看到PDF是使用iText 2.0.8创建的。如果您知道谁创建了这些PDF,请让他或她升级到更新版本。请参阅http://itextpdf.com/salesfaq(不再支持该版本,如果继续使用,则可能会遇到其他更严重的问题。)

相关问题