我看过使用 ITextSharp 或 PDFBox 从 pdf 文件中提取文本的示例。 PDFBox 似乎是提取文本最“可靠”的方法,但它需要许多额外的步骤。
我已尝试使用找到的说明构建 dll here ,但我不知道如何正确构建 .Net 所需的文件。
我很迷茫,有人可以逐步提供“在您的 .Net 应用程序中为傻瓜添加 PDFBox”吗?
最佳答案
我终于让它工作了。我已经概述了获得工作示例所遵循的步骤。我希望有人觉得这有帮助。
下载 Java JDK
下载 IKVM 0.42.0.6
下载 PDFBox 1.6.0-src.zip
Ant Manual很有帮助。
我重命名了 Ant 和 PDFBox 文件夹以缩短它们的名称并将它们移动到我的 C: 驱动器
您必须设置您的环境变量。 (Windows 7的) 右键我的电脑->属性->高级系统设置->环境变量
我使用了以下设置,但您的设置会有所不同,具体取决于您安装 Java 的位置以及放置 Ant 和 PDF Box 文件夹的位置。
Variable Value ANT_HOME C:\apache-ant\ JAVA_HOME C:\Program Files (x86)\Java\jdk1.7.0_01 Path ;C:\apache-ant\bin\ (Append semi-colon and path)
Once the above it done, type in “ant” in a command window, you should get a “build.xml does not exist!” message if everything is setup correctly.
Edit the build.xml file inside the ”pdfbox-1.6.0\pdfbox” folder. Find the line that has Replace “.” with “Your IKVM Folder Path”.
I moved IKVM to “C:\IKVM" so mine looks like:
Open a command window and cd to “C:\pdfbox-1.6.0\pdfbox “ and type “ant”
…and then a miracle occurs.
A bunch of new folders should now exist in the pdfbox folder. The required dll’s are in the bin folder. I don’t know why, but I got a “-SNAPSHOT” and the end of all my files (pdfbox-1.6.0-SNAPSHOT.dll).
IKVM.GNU.Classpath (Also called IKVM.OpenJDK.Classpath) no longer exists, it was modularized since the 0.40 release. It is now available in the form of several IKVM.OpenJDK dll’s. You only need a few of them.
Create a new project in Visual Studio C#
Copy these files from the pdfBox bin folder to the bin folder of your Visual C# project bin folder:
pdfbox-1.6.0-SNAPSHOT.dll fontbox-1.6.0-SNAPSHOT.dll commons-logging.dll
Copy these files from the ikvm bin folder to the bin folder of your Visual C# project bin folder:
IKVM.OpenJDK.Core.dll IKVM.OpenJDK.SwingAWT.dll IKVM.OpenJDK.Text.dll IKVM.OpenJDK.Util.dll IKVM.Runtime.dll
Add References to the IKVM dll’s above and build your project.
Add a Reference to the pdfbox dll and build your project again.
You are now ready to write some code. The simple example below produced a nice text file from the input pdf.
using System;
using System.IO;
using org.apache.pdfbox.pdmodel;
using org.apache.pdfbox.util;
namespace testPDF
{
class Program
{
static void Main()
{
PDFtoText pdf = new PDFtoText();
string pdfText = pdf.parsePDF(@"C:\Sample.pdf");
using (StreamWriter writer = new StreamWriter(@"C:\Sample.txt"))
{ writer.Write(pdfText); }
}
class PDFtoText
{
public string parsePDF(string filepath)
{
PDDocument document = PDDocument.load(filepath);
PDFTextStripper stripper = new PDFTextStripper();
return stripper.getText(document);
}
}
}
}
关于c# - 如何为 .Net 构建 PDFBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8441991/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我刚刚为fedora安装了emacs。我想用emacs编写ruby。为ruby提供代码提示、代码完成类型功能所需的工具、扩展是什么? 最佳答案 ruby-mode已经包含在Emacs23之后的版本中。不过,它也可以通过ELPA获得。您可能感兴趣的其他一些事情是集成RVM、feature-mode(Cucumber)、rspec-mode、ruby-electric、inf-ruby、rinari(用于Rails)等。这是我当前用于Ruby开发的Emacs配置:https://github.com/citizen428/emacs
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
在编写Ruby(客户端脚本)时,我看到了三种构建更长字符串的方法,包括行尾,所有这些对我来说“闻起来”有点难看。有没有更干净、更好的方法?变量递增。ifrender_quote?quote="NowthatthereistheTec-9,acrappyspraygunfromSouthMiami."quote+="ThisgunisadvertisedasthemostpopularguninAmericancrime.Doyoubelievethatshit?"quote+="Itactuallysaysthatinthelittlebookthatcomeswithit:themo
C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm