java读取doc,pdf问题。

java读取doc,pdf问题。,第1张

PDFBox是一个开源的对pdf文件进行 *** 作的库。 PDFBox-0.7.3.jar加入classpath。同时FontBox1.0.jar加入classpath,否则报错

import java.io.FileInputStream  

import java.io.FileNotFoundException  

import java.io.IOException  

  

import org.pdfbox.pdfparser.PDFParser  

import org.pdfbox.pdmodel.PDDocument  

import org.pdfbox.util.PDFTextStripper  

  

public class PdfReader {  

    /** 

     * simply reader all the text from a pdf file.  

     * You have to deal with the format of the output text by yourself. 

     * 2008-2-25 

     * @param pdfFilePath file path 

     * @return all text in the pdf file 

     */  

    public static String getTextFromPDF(String pdfFilePath)   

    {  

        String result = null  

        FileInputStream is = null  

        PDDocument document = null  

        try {  

            is = new FileInputStream(pdfFilePath)  

            PDFParser parser = new PDFParser(is)  

            parser.parse()  

            document = parser.getPDDocument()  

            PDFTextStripper stripper = new PDFTextStripper()  

            result = stripper.getText(document)  

        } catch (FileNotFoundException e) {  

            // TODO Auto-generated catch block  

            e.printStackTrace()  

        } catch (IOException e) {  

            // TODO Auto-generated catch block  

            e.printStackTrace()  

        } finally {  

            if (is != null) {  

                try {  

                    is.close()  

                } catch (IOException e) {  

                    // TODO Auto-generated catch block  

                    e.printStackTrace()  

                }  

            }  

            if (document != null) {  

                try {  

                    document.close()  

                } catch (IOException e) {  

                    // TODO Auto-generated catch block  

                    e.printStackTrace()  

                }  

            }  

        }  

        return result  

    }  

    public  static void main(String[] args)  

    {  

        String str=PdfReader.getTextFromPDF("C:\\Read.pdf")  

        System.out.println(str)  

      

    }  

}

代码2:

import java.io.File  

import java.io.FileOutputStream  

import java.io.OutputStreamWriter  

import java.io.Writer  

import java.net.MalformedURLException  

import java.net.URL  

import org.pdfbox.pdmodel.PDDocument  

import org.pdfbox.util.PDFTextStripper  

public class PDFReader {  

 public void readFdf(String file) throws Exception {  

   

  boolean sort = false  

   

  String pdfFile = file  

  String textFile = null  

 

  String encoding = "UTF-8"  

  

  int startPage = 1  

  

  int endPage = Integer.MAX_VALUE  

   

  Writer output = null  

   

  PDDocument document = null  

  try {  

   try {  

    // 首先当作一个URL来装载文件,如果得到异常再从本地文件系统//去装载文件  

    URL url = new URL(pdfFile)  

   //注意参数已不是以前版本中的URL.而是File。  

    document = PDDocument.load(pdfFile)  

    // 获取PDF的文件名  

    String fileName = url.getFile()  

    // 以原来PDF的名称来命名新产生的txt文件  

    if (fileName.length() > 4) {  

     File outputFile = new File(fileName.substring(0, fileName  

       .length() - 4)  

       + ".txt")  

     textFile = outputFile.getName()  

    }  

   } catch (MalformedURLException e) {  

    // 如果作为URL装载得到异常则从文件系统装载  

   //注意参数已不是以前版本中的URL.而是File。  

    document = PDDocument.load(pdfFile)  

    if (pdfFile.length() > 4) {  

     textFile = pdfFile.substring(0, pdfFile.length() - 4)  

       + ".txt"  

    }  

   }  

   

   output = new OutputStreamWriter(new FileOutputStream(textFile),  

     encoding)  

  

   PDFTextStripper stripper = null  

   stripper = new PDFTextStripper()  

   // 设置是否排序  

   stripper.setSortByPosition(sort)  

   // 设置起始页  

   stripper.setStartPage(startPage)  

   // 设置结束页  

   stripper.setEndPage(endPage)  

   // 调用PDFTextStripper的writeText提取并输出文本  

   stripper.writeText(document, output)  

  } finally {  

   if (output != null) {  

    // 关闭输出流  

    output.close()  

   }  

   if (document != null) {  

    // 关闭PDF Document  

    document.close()  

   }  

  }  

 }  

 /** 

  * @param args 

  */  

 public static void main(String[] args) {  

  // TODO Auto-generated method stub  

     PDFReader pdfReader = new PDFReader()  

  try {  

   // 取得E盘下的SpringGuide.pdf的内容  

   pdfReader.readFdf("C:\\Read.pdf")  

  } catch (Exception e) {  

   e.printStackTrace()  

  }  

 }  

}

2、抽取支持中文的pdf文件-xpdf

xpdf是一个开源项目,我们可以调用他的本地方法来实现抽取中文pdf文件。

http://www.java-cn.com/technology/tech_downs/1880_004.zip

补丁包:

http://www.java-cn.com/technology/tech_downs/1880_005.zip

按照readme放好中文的patch,就可以开始写调用本地方法的java程序了。

下面是一个如何调用的例子:

import java.io.*  

/** 

* <p>Title: pdf extraction</p> 

* <p>Description: email:[email protected]</p> 

* <p>Copyright: Matrix Copyright (c) 2003</p> 

* <p>Company: Matrix.org.cn</p> 

* @author chris 

* @version 1.0,who use this example pls remain the declare 

*/  

  

  

public class PdfWin {  

public PdfWin() {  

}  

public static void main(String args[]) throws Exception  

{  

String PATH_TO_XPDF="C:Program Filesxpdfpdftotext.exe"  

String filename="c:a.pdf"  

String[] cmd = new String[] { PATH_TO_XPDF, "-enc", "UTF-8", "-q", filename, "-"}  

Process p = Runtime.getRuntime().exec(cmd)  

BufferedInputStream bis = new BufferedInputStream(p.getInputStream())  

InputStreamReader reader = new InputStreamReader(bis, "UTF-8")  

StringWriter out = new StringWriter()  

char [] buf = new char[10000]  

int len  

while((len = reader.read(buf))>= 0) {  

//out.write(buf, 0, len)  

System.out.println("the length is"+len)  

}  

reader.close()  

String ts=new String(buf)  

System.out.println("the str is"+ts)  

}  

}

相信大多数人都看过《阿甘正传》,这部包揽当年6项奥斯卡奖的影片。以下两篇关于《阿甘正传》的影评,一篇写于1994年,一篇写于2014年。

Roger Ebert

July 6, 1994

I've never met anyone like Forrest Gump (阿甘) in a movie before, and for that matter I've never seen a movie quite like "Forrest Gump." Any attempt to describe him will risk making (冒险做某事) the movie seem more conventional (平常) than it is, but let me try. It's a comedy, I guess. Or maybe a drama. Or a dream.

The screenplay by Eric Roth has the complexity (复杂) of modern fiction, not the formulas of modern movies. Its hero, played by Tom Hanks, is a thoroughly (彻底的) decent man with an IQ of 75, who manages between the 1950s and the 1980s to become involved in every major event(重要的事件)in American history. And he survives them all with only honesty and niceness as his shields.

And yet this is not a heartwarming story about a mentally retarded man.(这并不是一个关于智障人士的暖心故事。)That cubbyhole (本意指小房间,暗指前一句的评价) is much too small and limiting for Forrest Gump. The movie is more of a meditation on our times, as seen through the eyes of a man who lacks cynicism and takes things for exactly what they are. Watch him carefully and you will understand why some people are criticized (因为什么而被批评) for being "**too clever by half (一半) **." Forrest is clever by just exactly enough. (阿甘的聪明刚刚好)

Tom Hanks may be the only actor/who could have played the role.

I can't think of anyone else as Gump, after seeing how Hanks makes him into a person so dignified (有尊严的) , so straight-ahead (简单的,直截了当的) . The performance is a breathtaking balancing act between comedy and sadness, in a story/rich in big laughs and quiet truths.(他的表演成功的平衡了喜剧和悲剧,这个故事充满了欢笑和沉默的真理)

Forrest is born to an Alabama boardinghouse owner/(Sally Field) who tries to correct his posture/by making him wear braces, but who never criticizes his mind. When Forrest is called "stupid," his mother tells him, "Stupid is as stupid does," and Forrest turns out (结果是,证明是) to be incapable of doing anything less than profound (具有深远意义的) . Also, when the braces finally fall from his legs, it turns out he can run like the wind.

That's how he gets a college football scholarship, in a life story that eventually becomes a running gag about his good luck. Gump the football hero becomes Gump the Medal of Honor winner in Vietnam, and then Gump the Ping-Pong champion, Gump the shrimp boat captain, Gump the millionaire stockholder (he gets shares in a new "fruit company" named Apple Computer), and Gump the man who runs across America and then retraces (原路返回) his steps.

It could be argued / that with his IQ of 75 Forrest does not quite understand everything that happens to him. Not so. He understands everything he needs to know, and the rest, the movie suggests (文中指,表达出) , is just surplus (多余的) . He even understands everything that's important about love, although (引导让步状语从句) Jenny (主语) , the girl he falls in love with in grade school and never falls out of love with, tells him, "Forrest, you don't know what love is." She is a stripper by that time.

The movie is ingenious (巧妙的,足智多谋的) in taking Forrest on his tour of recent American history. The director, Robert Zemeckis, is experienced with (对什么很有经验) the magic that special effects can do (his credits (功绩) include the "Back To The Future" movies and "Who Framed Roger Rabbit"), and here he uses computerized visual legerdemain to place Gump in historic situations with actual people.

Forrest stands next to the schoolhouse door withGeorge Wallace, he teaches Elvis how to swivel his hips (扭屁股), he visits the White House three times, he's on theDick Cavettshow withJohn Lennon, and in a sequence(结果) that will have you rubbing your eyes with its realism(你将会揉你的眼睛去考虑事情的真假), he addresses (对谁讲话) a Vietnam-era peace rally (大型集会) on the Mall in Washington . Special effects are also used in creating the character of Forrest's Vietnam friend Lt . Dan (Gary Sinise), aRon Kovictype/who quite convincingly (令人信服,有说服力的) loses his legs.

Using carefully selected TV clips (声音或影像的片段) and dubbed voices, Zemeckis is able to create some hilarious moments, as when LBJ examines the wound in what Forrest describes as "my butt-ox." And the biggest laugh in the movie comes after Nixon inquires where Forrest is staying in Washington, and then recommends the Watergate. (That's not the laugh, just the setup.) As Forrest's life becomes a guided tour of straight-arrow (传统的,正直的,循规蹈矩的) America, Jenny (played by Robin Wright) goes on a parallel tour(平行的道路)of the counterculture (反主流文化) . She goes to California, of course, and drops out, tunes in, and turns on. She's into psychedelics and flower power (对迷幻等感兴趣) , antiwar rallies(参加反战集会)and love-ins, drugs and needles. Eventually it becomes clear that between them Forrest and Jenny have covered all of the landmarks of our recent cultural history, and theaccommodation (住所) they arrive at in the end / is like a dream of reconciliation (和解) for our society. What a magical movie. 本段主要讲了,虽然阿甘和珍妮走过了美国文化的地标性事件,走了两条不一样的道路,但最后以他们两在一起为结局。

...

James Berardinelli

September 05, 2014

Since its theatrical (戏剧的,剧场的) release in the summer of 1994, Forrest Gump has become one of those movies seemingly everyone is familiar with . It's a cultural touchstone (试金石) with lines like "Life is a box of chocolates(生活就像一盒巧克力)" appearing everywhere from tee-shirts to greeting cards. The film's popularity was italicized (强调的) by the way it rampaged (横冲直撞的) through the 1995 Oscars, winning six awards (including the "big three" of Best Picture, Director, and Actor).(1995年横扫奥斯卡,包揽了6项大奖)Now, for its 20th anniversary, the decision has been made to do something Hollywood almost never does during the home videoera(家庭影院时代) : a big screen re-release(大屏幕出现了).

How to get people into theaters to watch (or re-watch) Forrest run when it's a lot easier to do it at home? Enter the IMAX gimmick (小把戏) . Calling it anything less crass would be dishonest/ since (引导原因状语从句) there's no inherent reason/why Forrest Gump should be bulked up for IMAX没有内在的原因说为什么阿甘应该被搬上大荧幕(or pseudo -IMAX, depending on how one views the smaller AMC version of the product). Still, commercial considerations aside, there's something majestic about watching this tall tale unfold on a larger screen than one can find in the average family room. The IMAX format is a nice way to entice (怂恿) some viewers to see the movie in a theater while maintaining the original composition .(构成,组成)//20周年了,IMAX出来了,《阿甘正传》作为一部经典,值得去影院支持。

The original review holds up today because, unlike some decades-old (几十年老的了) motion pictures, this one doesn't seem dated (过时的) . It wears its age well (永葆青春的感觉) . Here's what I wrote in 1994/when the movie was first released:

Ever find the grind of life getting you down? Is the day-to-day struggle threatening to drag you under? If so, there is a movie out there that can replenish (补充,重新装满) your energy and refresh your outlook (满血复活并能拥有全新的世界观) . Passionate and magical, Forrest Gump is a tonic for the weary (疲倦的) of spirit (是疲惫灵魂的一剂补药) . For those who限定性定语从句(feel/that being set adrift in a season of action movies is like wandering into a desert, the oasis lies ahead.)

Back when Tom Hanks' movie career was relatively new, the actor made a film called Big, which told the story of a young boy forced to grow up fast as a result of an ill-advised (不明智的) wish made at a carnival. In some ways, Forrest Gump represents a return to the themes of that earlier movie. In this case, the main character remains a child in heart and spirit, even as his body grows to maturity (成熟的) . Hanks is called upon yet again to play the innocent .

Forrest Gump (Hanks), named after a civil war (内战) hero, grows up in Greenbow, Alabama, where his mother (Sally Field) runs a boarding house (经营家庭旅馆) . Although Forrest is a little "slow" (his IQ is 75, 5 below the state's definition of "normal"), his mental impairment (残缺,不完整) doesn't seem to bother him, his mother, or his best (and only) friend, Jenny Curran (played as an adult by Robin Wright). In fact, the naiveté that comes through a limited understanding of the world around him gives Forrest a uniquely positive perspective(观点,看法)on life. Across the span of the next thirty years, Forrest becomes a star football player, a war hero, a successful businessman, and a pop icon (一个流行标志) . Through it all, however, there is one defining element (因素即珍妮) in his life: his love for Jenny. She is never far from his thoughts, no matter what he's doing or where he is.

A trio of assets lifts Forrest Gump above the average "life story" (melo)drama : its optimism , freshness, and emotional honesty. Though the movie does not seek to reduce every member of the audience to tears, it has moments whose power comes from their simplicity. Equally as important is laughter, and Forrest Gump has moments of humor strewn (洒满,充满) throughout.

During the 60s and 70s, no topic more inflamed (激怒) the turbulent national consciousness (震荡的全国性的思潮) than that of Vietnam(越南)and those who were sent overseas to fight.(在60到70年代,没有什么事比越战更能引起人们震荡的全国性的思潮)Forrest, as might be expected, has a singular viewpoint/on his time spent there: "We took long walks and were always looking for this guy named Charlie." This observation emphasizes the essence of the title character's nature.

Through the miracle of visual effects , Forrest meets his fair share of famous people - George Wallace, Presidents Kennedy, Johnson, and Nixon, and John Lennon. While mixing the real footage (影像,录像的意思) of these notables (显眼的) with new images featuring (由谁主演) Hanks is not a seamless (流畅的) process, the result is nevertheless effective. (This is a precursor of what would become commonplace in future films as the effects work employed here became refined .)

Forrest Gump has several messages, few of which require much digging into the subtext to unearth . The most frequently recurring theme is an admonition not to give up on life. Why surrender (投降) when you don't know what lies ahead ? By contrasting Forrest's life with the lives of those around him, and by showing / how the passage of time brings solace (慰藉) to even the most embittered (满心怨恨的) earts, the movie underlines this point. 对比别人和阿甘的生活,说明时间是如何慰藉一个愤世嫉俗的人的。

Tom Hanks won 1994's Academy Award for Philadelphia, but his performance here is more nuanced (细致入微的) . [With Forrest Gump, he would become only the second man to win back-to-back Lead Actor Oscars, joining Spencer Tracy 就是与奥黛丽赫本一声错过的那个男银,看了这个我才知道 .] The Alabama accent may seem a little awkward (尴尬) at first, but it doesn't take long for the acting(但不会花很长时间就发现他的表演不会)to dwarf ( v.使什么相形见绌 ) the twang . Hanks fashions a human character free of guile and deceit , and barely able to comprehend (理解)a concept like evil. Robin Wright gives the best performance of her career, surpassing (超过) what she accomplished in The Playboys. Looking and seeming like a younger Jessica Lange (一个早期的美国女演员,也拿过两次奥斯卡) , she is believable as the object of Forrest's undying affection. The scene-stealer, however, is Gary Sinise. A renowned (出名的) stage director and actor(舞台剧的演员), Sinise is probably best known to film-goers (to the extent that he is known at all) for his portrayal of George in 1992's Of Mice and Men (which he also directed). In this movie, his portrayal of Lieutenant Dan Taylor is riveting (引人入胜) . The passion and pain he brings to the middle portions of Forrest Gump hold together some of the film's weaker moments.

The soundtrack boasts a variety of sounds of the era - perhaps too wide a variety. Often, music can be useful in establishing a mood, but Forrest Gump rockets into the realm (范围) of overkill (过分) . There are sequences/when the choice of song is inspired (the use of "Running on Empty" for Forrest's "long run" comes to mind), but the soundtrack could have used a little pruning(修剪). There are times when it seems as much designed to sell CDs as to cement (水泥,引申为加固,加强) the setting.

Ultimately , however, any such gripes about Forrest Gump are minor(很小的). This is a marvelous motion picture -- a mint julep on a hot summer's afternoon.

重要词汇:

·Complexity: 复杂性 complicated: 复杂的,纠缠不清的

·Thoroughly:彻底的,完整的

·Major:主要的,重要的

·Be criticized for: 因为…被批评

·Too clever by half: 自作聪明

·Dignified:有尊严的,庄严的

·Straight-ahead:直截了当的,简单的

·Turn out:发生(结果为);被发现是

·Profound:影响深远的;意义深刻的;知识渊博的

·Surplus:多余的,超出的

·Ingenious:精妙的,足智多谋的

·Credit:存款,信誉,功劳

·Convincing:令人信服的,有说服力的

·Clip:(影视/音乐的)小片段

·Hilarious:十分有趣,非常滑稽的

·Straight-arrow:耿直的,坦率的,循规蹈矩的

·Parallel: 平行线,平行的,类似的

·Reconciliation:和解,相互适应

·Italicized:斜体的,重要的(强调的)

·Rampage:横冲直撞,暴怒

·Pseudo-:假的

·Entice:诱使,怂恿

·Replenish:补充,重新装满

·Weary:疲倦的,十分厌倦的(多用于书面语)

·Ill-advised: 不明智的,欠考虑的

·Strewn: 撒满的,散播的,strew的过去分词(常用被动态)

·Inflame:激怒,使加剧

·Seamless:流畅的,浑然一体的;无缝的

·Admonition:告诫,警告

·Solace:安慰,慰藉

·Embittered:怨愤的,满腹牢骚的

·Nuanced:细致入微的

·Dwarf:使…相形见绌,使矮小

·Twang:有着鼻音的口音

·Guile:狡猾

·Deceit:欺诈

·Comprehend:理解,领悟

·Renowned:有名望的

·Portrayal:描绘,扮演

·Riveting:令人着迷的,引人入胜的

·Realm:领域,范围

·Overkill:过分,过火

·Cement:加固;水泥

·Gripe:所抱怨的小事;抱怨

·Marvelous:非凡的,令人惊异的

长难句:

1) Its hero, played by Tom Hanks, is a thoroughly decent man with an IQ of 75, who manages between the 1950s and the 1980s to become involved in every major event in American history.

由汤姆汉克斯饰演的主角是一个绝对的大好人,但智商只有75,他参与了上世纪50年代到80年代,美国每一个重要的事件。

2) The movie is more of a meditation on our times, as seen through the eyes of a man who lacks cynicism and takes things for exactly what they are.

这部电影更像是对我们所处的这个时代的一个反思,而这个反思,是从一个没有戾气,就相信他所看见的就是真实的,这样一个人的角度出发。

3) Forrest turns out to be incapable of doing anything less than profound. Also, when the braces finally fall from his legs, it turns out he can run like the wind.

结果发现,Forrest是一个有能力去做很多具有重要意义的事情的人。而且,当支架从他腿上滑落下去的时候,你会发现,他可以跑得像风一样快。

4) It could be argued that with his IQ of 75 Forrest does not quite understand everything that happens to him.

有人可能会说,Forrest作为一个智商75的人,是很难真正理解他身边所发生的一切的。

5) He even understands everything that's important about love, although Jenny, the girl he falls in love with in grade school and never falls out of love with, tells him, "Forrest, you don't know what love is."

他甚至明白所有那些关于爱至关重要的事儿,尽管那个他从小学就开始爱,一直爱到最后的妹子Jenny跟他说“Forrest, 你根本不懂什么是爱。”

6) As Forrest's life becomes a guided tour of straight-arrow America, Jenny (played by Robin Wright) goes on a parallel tour of the counterculture. She goes to California, of course, and drops out, tunes in, and turns on.

正如Forrest的一生变成了美国传统正直的旅行,Jenny(由Robin Wright饰演)走的是一条平行空间的道路,是一次反主流文化之旅。她去了加利福尼亚,当然,她逃避现实社会,去融入那个团体,而且内心的激情被点燃了。

7) The film's popularity was italicized by the way it rampaged through the 1995 Oscars, winning six awards (including the "big three" of Best Picture, Director, and Actor).

从电影横扫1995年奥斯卡,赢得了6项大奖来看(包括最重要的三个奖项,最佳影片/最佳导演/最佳演员),无疑彰显了它的受欢迎程度。

8) Still, commercial considerations aside, there's something majestic about watching this tall tale unfold on a larger screen than one can find in the average family room.

但是,商业考虑先放在一边,比起在普通的家里看,这部巨制童话在宽银幕上展开确实有一下直的期待的东西。

9) For those who feel that being set adrift in a season of action movies is like wandering into a desert, the oasis lies ahead.

对于那些感觉被放逐在这一整季动作片里,就像是走进了沙漠一样的人,绿洲,就在前方了。

10) Back when Tom Hanks' movie career was relatively new, the actor made a film called Big, which told the story of a young boy forced to grow up fast as a result of an ill-advised wish made at a carnival.

回到那个时候,汤姆汉克斯的影视生涯才刚刚开始,他拍了一部电影叫做“Big”,这部电影讲述了一个小男孩,因为在一个嘉年华里去了一个不明智的愿望而被迫迅速长大的故事。

11) In fact, the naiveté that comes through a limited understanding of the world around him gives Forrest a uniquely positive perspective on life.

事实上,正是因为对身边的世界有限的认识所带来的天真,给了Forrest一种独一无二积极的世界观。

12) Though the movie does not seek to reduce every member of the audience to tears, it has moments whose power comes from their simplicity. Equally as important is laughter, and Forrest Gump has moments of humor strewn throughout.

尽管这部影片没有刻意去让观众泪眼婆娑,但正是这种简约的手法是的其中的一些场景极富力量感动。同样笑声也是同等的重要,而且,阿甘这部电影中贯穿前后都充满了幽默。

13) During the 60s and 70s, no topic more inflamed the turbulent national consciousness than that of Vietnam and those who were sent overseas to fight.

在上世纪60年代和70年代,没有什么话题比越南和那些被送到海外去打仗的人,更能够激起全国性的动乱的思想了。

14) By contrasting Forrest's life with the lives of those around him, and by showing how the passage of time brings solace to even the most embittered hearts, the movie underlines this point.

电影通过对比阿甘和他身边的人的生活,以及通过展示时间是如何给那些充满怨恨的心灵带来慰藉的方式,向我们再次强调了这一点—— not to give up on life.

15) The passion and pain he brings to the middle portions of Forrest Gump hold together some of the film's weaker moments.

Lt. Dan这个角色所带给阿甘这部电影中部的激情和痛苦,很好的整合改善了这一阶段电影中的薄弱情节。

16) There are times when it seems as much designed to sell CDs as to cement the setting.

有的时候,你觉得电影配乐(用力过猛)就好像是要出CD专辑一样,而不是简简单单的去烘托加强电影场景。

解决方案------------------------------------------------- 下载 PDFBox-0.7.3.zip

PDFBox-0.7.3.dll lucene-demos-2.0.0.dll lucene-core-2.0.0.dll bcmail-jdk14-132.dll bcprov-jdk14-132.dll FontBox-0.1.0-dev.dll ICSharpCode.SharpZipLib.dll IKVM.AWT.WinForms.dll IKVM.GNU.Classpath.dll IKVM.Runtime.dll ikvm-native.dll 放入Bin中 C# code

<%@ Page Language="C#" %>

<%@ Import Namespace="System" %>

<%@ Import Namespace="org.pdfbox.pdmodel" %><%@ Import Namespace="org.pdfbox.util" %><script language="C#" runat="server">

protected void Page_Load(object sender, System.EventArgs e) {

stringpdfPath = Server.MapPath("index.pdf")PDDocument doc = PDDocument.load(pdfPath)

PDFTextStripper stripper = new PDFTextStripper()string txt = stripper.getText(doc)

Response.Write(txt)}

</script>

显示:

1.在工具箱中添加Adobe提供的ActiveX控件;

2.在工具箱最下面就会有一个Adobe PDF Reader控件出现, 拖一个Adobe PDF Reader控件到窗体上,双击窗体,在窗体加载时,d出对话框,加载PDF文件:

3、用另一个窗体打开需用到LoadFile来加载PDF显示内容;

例如:

建立一个需要d出来加载PDF内容的Form3窗体:

public partial class Form3:Form

{

string pdf = string.Empty

public Form3(string filePath):this()

{

pdf = filePath

axAcroPdf1.LoadFile(filePath)//axAcroPdf1是PDF控件命名

}

}

窗体Form2的代码为:

Form3 form3 = new Form3(路径 + ".pdf")//路径为存放PDF文件的路径

form3.show()

每次打开了PDF文件后,关闭的时候就会出现内存错误,暂未找到方法解决!

显示提示以下内容!!!

"0x057a3b11"指令引用的"0x00000004"内存。该内存不能为"read".要终止程序,请单击确定!

--------------------------------------------------------------------------------------------

解决PDF异常退出方式:

[System.Runtime.InteropServices.DllImport("ole32.dll")]

static extern void CoFreeUnusedLibraries()

private void axAcroPDF1_OnError(object sender, EventArgs e)

{

}

//窗体3正常释放axAcroPDF控件

private void Form3_FormClosing(object sender, FormClosingEventArgs e)

{

if (axAcroPDF1 != null)

{

axAcroPDF1.Dispose()

System.Windows.Forms.Application.DoEvents()

CoFreeUnusedLibraries()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/9882092.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存