如何确定文件是否为PDF文件?

编程入门 行业动态 更新时间:2024-10-20 16:37:18
本文介绍了如何确定文件是否为PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Java中的PdfBox从PDF文件提取文本.提供的某些输入文件无效,这些文件上的PDFTextStripper暂停.有没有一种干净的方法来检查提供的文件是否确实是有效的PDF?

I am using PdfBox in Java to extract text from PDF files. Some of the input files provided are not valid and PDFTextStripper halts on these files. Is there a clean way to check if the provided file is indeed a valid PDF?

推荐答案

您可以找出文件(或字节数组)的mime类型,因此不必盲目地依赖扩展名.我是用光圈的MimeExtractor( aperture.sourceforge/)来完成的,或者是几天前我看到的为此专用的库( sourceforge/projects/mime-util )

you can find out the mime type of a file (or byte array), so you dont dumbly rely on the extension. I do it with aperture's MimeExtractor (aperture.sourceforge/) or I saw some days ago a library just for that (sourceforge/projects/mime-util)

我使用光圈从各种文件中提取文本,不仅是pdf,而且还需要例如针对pdf进行调整(光圈使用pdfbox,但是当pdfbox失败时我添加了另一个库作为后备)

I use aperture to extract text from a variety of files, not only pdf, but have to tweak thinks for pdfs for example (aperture uses pdfbox, but i added another library as fallback when pdfbox fails)

更多推荐

如何确定文件是否为PDF文件?

本文发布于:2023-11-29 17:15:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!