@RequestMapping(value = "/test", method = RequestMethod.GET) public void test(HttpServletResponse response, HttpServletRequest request) throws IOException, InterruptedException { logger.info("==========test============"); String path = "H:\\dd\\pdf\\a\\??????_??????????Java??????????????????.pdf"; String toPath1 = "H:\\dd\\pdf\\a\\??????_??????????Java??????????????????test1.pdf"; String toPath2 = "H:\\dd\\pdf\\a\\??????_??????????Java??????????????????test2.pdf"; String toPath3 = "H:\\dd\\pdf\\a\\??????_??????????Java??????????????????test3.pdf"; PDDocument document = PDDocument.load(new File(path)); PDPageTree pages = document.getPages(); Iterator<PDPage> iterator = pages.iterator(); int numberOfPages = document.getNumberOfPages(); System.out.println("numberOfPages = " + numberOfPages); CountDownLatch count = new CountDownLatch(3); new Thread(()->{ PDDocument to = new PDDocument(); for (int i = 0; i < 1000; i++) { to.addPage(document.getPage(i)); } try { System.out.println(to);
to.save(toPath1); to.close(); } catch (IOException e) { e.printStackTrace(); } count.countDown(); }).start(); new Thread(()->{ PDDocument to = new PDDocument(); for (int i = 0; i < 500; i++) { to.addPage(document.getPage(i)); } try { System.out.println(to); to.save(toPath2); to.close(); } catch (IOException e) { e.printStackTrace(); } count.countDown(); }).start(); new Thread(()->{ PDDocument to = new PDDocument(); for (int i = 0; i < 100; i++) { to.addPage(document.getPage(i)); } try { System.out.println(to); to.save(toPath3); to.close(); } catch (IOException e) { e.printStackTrace(); } count.countDown(); }).start(); count.await(); document.close(); }