Java-pdf Turn Word

Source: Internet
Author: User
Tags create directory


Note: The original text to " java-pdf to Word "

One: Java Pdf text to Word

Nonsense not to say that directly


Very simple to use:
1. New PDFBox Object
2, call the Pdftodoc () method, and then pass a parameter (file path)

Latest jar: Link: https://pan.baidu.com/s/1snqjpSx Password: JUJG or add QQ Group: 464429490 (in group file) Two: Java Pdf picture table to Word

Article source: " java-pdf turn Pictures "

Many people respond to PDF to Doc picture loss, table loss, style loss, coding problems, and so on.
Yes, this code is the only way to convert text to doc files.

because: Stripper.writetext (doc,writer);
Doc refers to Doc file
Writer refers to FileOutputStream fos=new FileOutputStream ("PDF file Address");
Writer writer=new outputstreamwriter (FOS, "UTF-8");

So we came up with JS to generate images, or PDF first to the picture JS full screen:

  1function takescreenshot () {  2     Html2canvas (document. Body, {   3         function (canvas) {  4             document. Body.appendchild (canvas);   5         },  6     });   7 }
JS Generate PDF:
1Html2canvas (Document. Body, {2Onrendered:function(canvas) {3     varurl = Canvas.todataurl ();4     //document.body.appendchild (canvas);5     varDoc =NewJspdf ();6Doc.setfontsize (40);7    //doc.text (+, "Yanhui");8 9    varImgasdataurl = URL;TenDoc.addimage (Imgasdataurl, ' JPEG ', 15, 40, 420, 180); OneDoc.save (' Yan Hui net. pdf '); A}, -width:600, -height:600 the});


JS Preview pdf

1 window. onload =function() {2          varSuccess =NewPdfobject ({3URL: "pdf/test.pdf",4Pdfopenparams: {5                  ScrollBars: ' 0 ',6                  Toolbar: ' 0 ',7                  StatusBar: ' 0 '8}9}). Embed ("PDF");Ten};


JS so powerful, our Java is not to be outdone Java implementation PDF to image to PDF

1 //PDF image and custom image format size2File File =NewFile (Pdfpath);3         Try{4PDDocument doc = pddocument.load (file);5Pdfrenderer renderer =NewPdfrenderer (DOC);6             intPageCount = Doc.getnumberofpages ();7              for(inti = 0; i < PageCount; i++) {8BufferedImage image = renderer.renderimagewithdpi (i, 240);9BufferedImage Srcimage = Resize (image, Image.getwidth (), Image.getheight ());TenImageio.write (Srcimage, "PNG",NewFile (Pngpath.replace (".", i+"."))); One} A}Catch(IOException e) { -E.printstacktrace (); -}


  1 bufferedimage image = Imageio.read (new FileInputStream (Pngpath));   2          list<bufferedimage> images=New arraylist<bufferedimage> ();   3              BufferedImage Srcimage = Resize (image, Image.getwidth (), Image.getheight ());   4              images.add (srcimage);   5          //synthesis picture to PDF  6          createpdffromimage (pdfpath,images);
Java generated PDF, support Chinese encoding
1Document document = Createdoc (filename);2         //Open Document3Document.open ();4         //write in document5Paragraph Centerpar = Convertpartochinese ("Yan Hui net",", bold, red);6Centerpar.setalignment (Element.align_center);7 8Document.add (Centerpar);9 //Document.add (new Paragraph ("\ n"));Ten //Document.add (Convertpartochinese ("black", +, Bolditalic, black)); OneDocument.add (NewParagraph ("\ n")); ADocument.add (Convertpartochinese ("You most love the brilliant-Hui blog, add QQ group 494808400, you can get more Java data. ", (), Normal, Black)); -Document.add (NewParagraph ("\ n")); -         //Document write picture the         if(Checkfile (Imgpath)) { -Image image = Writeimg (Imgpath); -Document.add (image); -Document.add (NewParagraph ("\ n")); +} - //Document.add (new Paragraph ("\ n")); + //// generate three-column table A //pdfptable table = new pdfptable (3); at //// Set table specific width - //Table.settotalwidth (+); - //// Set the length of each column - //Table.setwidths (new float[] {50f, 15f, 25f}); - //Pdfpcell cell1 = new Pdfpcell (); - //Paragraph para = new Paragraph ("AAAAA"); in //Cell1.setphrase (para); - //Table.addcell (CELL1); to //Table.addcell (New Pdfpcell ("New Phrase (" IText " )); + //Table.addcell (New Pdfpcell ("New Phrase (" IText " )); - //Document.add (table); the  * //Document.add (new Paragraph ("\ n")); $ //Document.add (new Paragraph ("\ n"));Panax Notoginseng         //PDF Peer Display - //Paragraph par = new Paragraph (); the //Chunk CHUNK1 = new Chunk (Convertchunkbychinese ("Test score:", +, Bold, black)); + //Chunk chunk2 = new Chunk (Convertchunkbychinese ("The", "the", "bold, red)"); A //Par.add (CHUNK1); the //Par.add (CHUNK2); + //// set overall indent - //par.setfirstlineindent (setting); $ / ///Center $ //Paragraph Centerpar = Convertpartochinese ("Test in play", +, italic, black); - //Centerpar.setalignment (element.align_center); - //Document.add (PAR); the         //New chapter -         //Chapter titleWuyi //Paragraph chaptertitle = new Paragraph (Convertpartochinese ("chapter title", Bolditalic, Blue)); the //Chapter chapter1 = new Chapter (chaptertitle, 1); - //chapter1.setnumberdepth (0); Wu //Paragraph p = new Paragraph ("Test!!!!!"); - //Chapter1.add (p); About //Document.add (chapter1); $  -         //Close document -Document.close ();
and a pdf2word2.0.
1PDDocument Doc=pddocument.load (NewFile (name1));2         intPagenumber=doc.getnumberofpages ();3 4name1 = name1.substring (0, Name1.lastindexof ("."));5 //String dirName = "d:\\pdf\\";//Create directory D:\\pdf\\a.doc6String dirName = name1;//Create directory D:\\pdf\\a.doc7         //createdir (dirName);//Call method to create a directory8String fileName = DirName + ". doc";//Create file9CreateFile (FileName);TenFileOutputStream fos=NewFileOutputStream (FileName); OneWriter writer=NewOutputStreamWriter (FOS, "UTF-8"); APdftextstripper stripper=NewPdftextstripper (); -  - //Doc.addsignature (arg0, arg1, arg2); the  -Stripper.setsortbyposition (true);//Sort -         //stripper.setwordseparator ("");//pdfbox to Chinese by default is to separate each word with a space, by this statement to eliminate the space (the video said) -Stripper.setstartpage (1);//Set the start page of the transformation +Stripper.setendpage (pagenumber);//Set the end page of the conversion -Stripper.writetext (Doc,writer); +Writer.close (); ADoc.close (); atSystem.out.println ("PDF Conversion Word success! ");




Three: Java-pdf turn word3.0

Note: original source " Java-pdf turn word3.0 "

Java-pdf Turn word3.0

2.0 is a PDF to a picture, Now out of 3.0 pictures to turn to Word, write 1.0 when the purpose is to use Pdfbox.jar to convert PDF files to Word files, in WPS relay words need to charge members, if using Java, only need to configure the environment, greatly save money, and gradually most of the Java needs to write this demand, Some I add others, others do not provide source code, only said the method, but I am also very grateful ... There are a lot of people add me QQ, said I this that the PDF to Word can be realized, said I did not provide code is not a liar or something, for this PDF to Word required to retain the style, keep the picture, others WPS turn also need to collect money, they development is not necessarily in Java development, you can also use C + + Develop a, here PDF to word This requirement is just a simple implementation of text conversion, of course, you can also add QQ to discuss, later will be 4.0 5.0 5.2 ... Version of the. Say a lot of sensational words, it is time to show the real technology.

First share PDF to HTML:
This is a small series copy down on the Internet, first the entire download pdf2htmlex-v1.0 folder

  1 pdf2html ("d:\\designsoftware\\pdf\\pdf2htmlex-v1.0\\pdf2htmlex.exe",  2                  "d:\\a.pdf",  3                  "d:\\htmlpdf", "a1.html");


The a.pdf of D is converted to a1.html and stored in the D-disk htmlpdf directory.

Then share the HTML to Word:
Baidu also down the

  1new Html2doc (). Writewordfile ("d:/a3.html", "d:/test222.doc", 1 );

The a3.html of D is converted to Test222.doc and stored in the D-disk directory.
Where 1 means that local HTML 2 means online and not open, I tested the online change to Doc after the style was lost, just like the feeling of doubting life ...

This chapter of the Code of the blog is free, because most of the code is patchwork down to complete the requirements, but 1.0 and 2.0 of the code needs to open our brilliant VIP to get.

So that your needs can be achieved PDF to Word, as long as the PDF read the picture, and then write the picture to the Word document, you can achieve the PDF to Word save the picture effect. Then someone will ask, save the picture but can not edit, there is yarn to use AH.
So you can look at the 2.0, PDF to Word, we first make a Word template, and then fill in the data, so word can achieve the editing effect, the disadvantage is to have a fixed template, change ability is poor. Think of a better way to leave a message. Spray I can also leave a message, anyway was sprayed is not the first time, this part of the code can be downloaded for free, you can add QQ490647751, reply java-pdf turn word3.0, you can get code learning.

I thought of the PDF to html,html to Word, but the HTML to Word style and picture also lost, helpless give up ...

Java-pdf Turn Word

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.