One problem encountered over the past few days is to convert all the content in the PDF document into images.
I found a lot of information on the Internet and found many ways to achieve this first. I also sorted out these materials. I will introduce an implementation method that I think is good at using Java. 1) download a pdfrenderer. jar package URL: https://pdf-renderer.dev.java.net/2) on this official website there are a few samples, you can take a look: https://pdf-renderer.dev.java.net/examples.html3) the following code is to generate a pdf png Format Image Public void pai_png (INT pagenumber) {<br/> int pagen = pagenumber; <br/> file = new file ("D:/test.pdf "); </P> <p> pdffile = NULL; <br/> // set up the PDF reading <br/> try {<br/> randomaccessfile RAF = new randomaccessfile (file, "R "); <br/> filechannel channel = Raf. getchannel (); <br/> bytebuffer Buf = channel. map (filechannel. mapmode. read_only, 0, channel. size (); <br/> pdffile = new pdffile (BUF); <br/>}< br/> catch (exception E) {}</P> <p> If (pagen <pdffile. getnumpages () <br/> return; <br/> // print the number of pages of the PDF document <br/> system. out. println (pdffile. getnumpages (); </P> <p> // you can specify pagen to generate a PNG image. <br/> pdfpage page = pdffile. getpage (pagen); <br/> // create and configure a graphics object <br/> int width = (INT) page. getbbox (). getwidth (); <br/> int Height = (INT) page. getbbox (). getheight (); <br/> bufferedimage IMG = new bufferedimage (width, height, bufferedimage. type_int_argb); <br/> graphics2d g2 = IMG. creategraphics (); <br/> g2.setrenderinghint (renderinghints. key_antialiasing, renderinghints. value_antialias_on); <br/> // do the actual drawing <br/> pdfrenderer Renderer = new pdfrenderer (page, G2, <br/> New rectangle (0, 0, width, height), null, color. red); <br/> try {<br/> page. waitforfinish (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}< br/> Renderer. run (); <br/> g2.dispose (); </P> <p> try {<br/> ImageIO. write (IMG, "PNG", new file ("D:/image.png"); <br/>}< br/> catch (exception ex ){}In addition to generating PNG images, the PDF Renderer also has a function to view PDF in your own applications.
Print and preview PDF files.
Merge PDF files into 3D scenarios.
Drawing on a PDF file and tagging on a network viewer.
Address: http://baiyun11095.blog.163.com/blog/static/33798962201032415853412/