![](/img/trans.png)
[英]How to launch a pdf file embedded in web browser with Reading mode and JAVA
[英]JAVA Reading web embedded PDF
我需要一种方法来阅读一些嵌入网络的 pdf 行(如https://www.tutorialspoint.com/java/java_tutorial.pdf )。
我正在使用我用于抓取普通 html 页面的方式,但它似乎不适用于 pdf 网页。 我没有在 pdf 页面上显示什么,而是得到了编码字符(我可以通过下载 pdf 并用记事本打开它来获得这些字符)
我需要从该网络嵌入的 pdf 中抓取 html 代码,有人可以帮助我吗?
编辑:现在我正在尝试使用(str是网址)
URL url = null;
try {
url = new URL(str);
} catch (MalformedURLException e) {
}
String html = "";
try {
html = IOUtils.toString(url.openConnection().getInputStream());
} catch (IOException e) {
}
return html;
我得到的不是 html 代码,而是:
%PDF-1.5
%µµµµ
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 134 0 R/MarkInfo<</Marked true>>>>
endobj
2 0 obj
<</Type/Pages/Count 32/Kids[ 3 0 R 14 0 R 30 0 R 46 0 R 48 0 R 55 0 R 57 0 R 59 0 R 61 0 R 63 0 R 65 0 R 67 0 R 76 0 R 87 0 R 89 0 R 91 0 R 96 0 R 102 0 R 104 0 R 106 0 R 108 0 R 110 0 R 112 0 R 114 0 R 116 0 R 118 0 R 121 0 R 123 0 R 125 0 R 127 0 R 129 0 R 131 0 R] >>
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R/F2 9 0 R/F3 11 0 R>>/ExtGState<</GS7 7 0 R/GS8 8 0 R>>/XObject<</Image13 13 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/MediaBox[ 0 0 595.32 841.92] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>
endobj
4 0 obj
<</Filter/FlateDecode/Length 270>>
stream
xœµÓËJC1à} ïð/U蜙$“”.z±T(X=àB\ˆÔ®ªXß<©Š,ÈA³�™d>fšK‡Ír²˜‚G#Œ§¼XÃÄuåœ-JÞ!¡â°[[ss†'kÆ5͹@„8 }´¦f3®$ŠŠ˜‡vÛåͯ6¯õi¯ L‘s·g¯Ømöá|$|5·æö§wh/¬™u5WÖ`¶œ
我解决了使用 PDFBOX https://pdfbox.apache.org/并做:
URL url = new URL(urlOfPDF);
InputStream in = new BufferedInputStream(url.openStream());
PDDocument pddDocument = PDDocument.load(in);
PDFText2HTML stripper = new PDFText2HTML();
String text = stripper.getText(pddDocument);
return text;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.