【发布时间】:2013-08-28 12:39:31
【问题描述】:
我在telufu pdf 中有 pdf(将 anils.com 替换为 123.176.47.55)我想从该 pdf 中提取一些文本(就像在那个 pdf 页面中我需要阅读的第 3 块数据中一样)我下载了所有字体该页面使用mupdf-1.3-windows
它会下载 pdf 使用的所有字体,但是当我通过使用这些字体将文本写入另一个 pdf 时,一些文本没有重新编写,代码就像
//output file name
public static String pdf1 = "C:\\Documents and Settings\\Administrator\\Desktop\\itextpdf\\anil.pdf";
public static void main(String[] args) throws IOException, DocumentException {
try {
PdfReader reader = new PdfReader(new URL("http://anils/DraftRolls/PDFGeneration.aspx?urlPath=D%3a\\SSR_2013_FINAL+ROLLS\\AC_238\\Telugu\\S01A238P038.PDF"),null);
System.out.println("This PDF has "+reader.getNumberOfPages()+" pages.");
// reading page no 3
String page = PdfTextExtractor.getTextFromPage(reader, 3);
// all fonts I had checked total of 7 fonts but I didn't get all the fonts
BaseFont f = BaseFont.createFont("C:\\Documents and Settings\\Administrator\\Desktop\\itextpdf\\fonts\\AAAAAD+Gautami-0174.ttf", "", BaseFont.EMBEDDED);
Font telugu = new Font(f, 18.0f, Font.BOLD);
Paragraph description = new Paragraph(page,telugu);
// description.setAlignment(Paragraph.ALIGN_CENTER);
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(pdf1));
// step 3
document.open();
document.add(description);
document.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
有些文字从未匹配任何字体如何解决?
【问题讨论】:
-
您的代码已经告诉您您做错了什么:您正在使用
PdfTextExtractor提取纯文本(没有样式,没有字体,...)。您没有使用PdfCopy或PdfStamper来处理实际的PDF 内容(包括字体字典、注释等)。 -
是否可以将pdf字体和样式转换为具有相同字体和样式的html文本
-
这很难做到。特别是如果您的 PDF 没有被标记。在任何人回答这个问题之前,您需要告诉我们:您的 PDF 被标记了吗? (如果不是:忘记转换为 HTML。)
-
我的查询有哪些可能的解决方案?
-
如果一个 PDF 没有被标记,那你就不走运了。在您用人眼看到表格的地方,机器只能看到文本和行的 sn-ps。如果没有适当的标签,机器就无法看到任何表格。样式或多或少也是如此。 PDF 中没有 或 标签这样的东西。只有不同的字体,例如 Helvetica Bold 和 Helvetica Italic,但您不能总是根据用于该字体的名称来判断字体是粗体还是斜体。长话短说:忘记你的要求。你要求的东西是非常困难的,如果不是不可能的话。