java tika pdf_使用Java中的Apache Tika从pdf文件中提取文本

线程“main”中的异常java.lang.NoSuchMethodError:org.slf4j.spi.LocationAwareLogger.log(Lorg / slf4j / Marker; Ljava / lang / String; ILjava / lang / String; Ljava / lang / Throwable;)V at org.apache.commons.logging.impl.SLF4JLocationAwareLog.warn(SLF4JLocationAwareLog.java:162)在org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.loadDiskCache(FileSystemFontProvider.java:461)在org.apache.pdfbox.pdmodel . font.FileSystemFontProvider(FileSystemFontProvider.java:217)在org.apache.pdfbox.pdmodel.font.FontMapperImpl $ DefaultFontProvider . (FontMapperImpl.java:130)在org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl . 的java:149)在org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:413)在org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFontBoxFont(FontMapperImpl.java:376)在org.apache位于org.apache.pdfbox.pdm的org.apache.pdfbox.pdmodel.font.PDType1Font . (PDType1Font.java:146)的.pdfbox.pdmodel.font.FontMapperImpl.getFontBoxFo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用以下Java代码使用TikaPDF文件转换为图像文件: ``` import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.pdf.PDFParserConfig; import org.apache.tika.sax.BodyContentHandler; import org.apache.tika.sax.ToXMLContentHandler; import org.apache.tika.sax.ToXMLContentHandler.XHTML; import org.apache.tika.sax.XHTMLContentHandler; import org.apache.tika.sax.image.ImageContentHandler; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; public class TikaPDFtoImageConverter { public static void main(String[] args) throws Exception { File pdfFile = new File("input.pdf"); File outputFile = new File("output.png"); int pageNumber = 1; String imageFormat = "png"; convertPDFtoImage(pdfFile, outputFile, pageNumber, imageFormat); } public static void convertPDFtoImage(File pdfFile, File outputFile, int pageNumber, String imageFormat) throws Exception { InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = TikaPDFtoImageConverter.class.getResourceAsStream(pdfFile.getName()); outputStream = new FileOutputStream(outputFile); AutoDetectParser parser = new AutoDetectParser(); PDFParserConfig pdfConfig = new PDFParserConfig(); pdfConfig.setExtractInlineImages(true); ParseContext parseContext = new ParseContext(); parseContext.set(PDFParserConfig.class, pdfConfig); ContentHandler contentHandler = new ImageContentHandler(outputStream); Metadata metadata = new Metadata(); parser.parse(inputStream, contentHandler, metadata, parseContext); } catch (Exception e) { e.printStackTrace(); throw e; } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); } } if (outputStream != null) { try { outputStream.close(); } catch (Exception e) { e.printStackTrace(); } } } } } ``` 该代码使用Tika解析器和ImageContentHandler将PDF文件转换为图像文件。您可以指定转换的页面号和图像格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值