【问题标题】:How to get original pdf from embed type=application/pdf using java如何使用 java 从 embed type=application/pdf 获取原始 pdf
【发布时间】:2012-12-07 22:45:33
【问题描述】:

我正在使用Jsoup 解析一些 HTML 以获取一些 PDF 网址。

PDF 显示在 <embed> 标签中,例如:

<html>
<body marginwidth="0" marginheight="0" style="background-color: rgb(38,38,38)">
<embed width="100%" height="100%" name="plugin" src="http://www.domain.com/apdf_id.pdf?tp=&amp;arnumber=1253069&amp;isnumber=28038" type="application/pdf">
</body>
</html>

如何从该页面获取 PDF URL,以便将其下载到本地计算机?

【问题讨论】:

    标签: html pdf download embed jsoup


    【解决方案1】:

    只需选择&lt;embed type="application/pdf"&gt; 元素并获取其src 属性作为绝对URL。

    String pdfURL = document.select("embed[type=application/pdf").first().absUrl("src");
    

    您也可以专门选择&lt;embed name="plugin"&gt;

    String pdfURL = document.select("embed[name=plugin").first().absUrl("src");
    

    那么你可以使用java.net.URL来获取InputStream的风格。

    InputStream input = new URL(pdfURL).openStream();
    

    最后只需按照通常的方式将其写入任意OutputStream,例如FileOutputStream

    另见:

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 1970-01-01
      • 2017-03-09
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多