One of the problems I've encountered these days is to convert all of the content in a PDF document into a picture. I found a lot of information on the Internet, hair first there are many ways to achieve this, I have done some collation of these materials. I'm here to introduce an implementation that I think is a good idea, using Java. 1) Download a Pdfrenderer.jar package url: HTTPS://PDF-RENDERER.DEV.JAVA.NET/2) There are several sample on this website, You can take a look at: https://pdf-renderer.dev.java.net/examples.html 3 The following code is a picture of a PDF generated in Png format public void pdf_png (int pagenumber) {int pagen= pagenumber; File File = new file ("D:/test.pdf"); Pdffile Pdffile=null; Set up the PDF reading try{randomaccessfile RAF = new Randomaccessfile (file, "R"); FileChannel channel = Raf.getchannel (); Bytebuffer buf = Channel.map (FileChannel.MapMode.READ_ONLY, 0, Channel.size ()); Pdffile = new Pdffile (BUF); catch (Exception e) {} if (Pagen<pdffile.getnumpages ()) return; Print out the number of pages in the PDF document SYSTEM.OUT.PRINTLN (Pdffile.getnumpages ()); Setting the Pagen also generates PNG pictures pdfpage page = Pdffile.getpage (Pagen); Create and configure a Graphics object int width = (int) page.getbbox (). GetWidth (); int height = (int) page.getbbox (). GetHeight (); BufferedImage img = new BufferedImage (width, height, bufferedimage.type_int_argb); graphics2d g2 = Img.creategraphics (); G2.setrenderinghint (renderinghints.key_antialiasing, renderinghints.value_antialias_on); Do the actual drawing pdfrenderer renderer = new Pdfrenderer (page, G2, New Rectangle (0, 0, width, height), null, Color. RED); try{page.waitforfinish ();} catch (Exception e) {e.printstacktrace ();} renderer.run (); G2.dispose (); try{imageio.write (IMG, PNG, New File ("D:/image.png");} catch (Exception ex) {} in addition to generating PNG pictures, PDF renderer also features &N bsp; View PDFs in the user's own application.
Provides a print preview of a PDF file.
Merge the PDF into the 3D scene.
Draw on top of the PDF and can be annotated in the network viewer. Original address: http://baiyun11095.blog.163.com/blog/static/33798962201032415853412/