split huge 40000 page pdf into single pages, itextsharp, outofmemoryexception

后端 未结 5 785
清酒与你
清酒与你 2021-01-31 21:40

I am getting huge PDF files with lots of data. The current PDF is 350 MB and has about 40000 pages. It would of course have been nice to get smaller PDFs, but this is what I hav

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 21:56

    This is a total shot in the dark, and I haven't tested this code - it's a code extract from the 'iText In Action' book that is given as an example of how to deal with large PDF files. The code is in Java but should be fairly easy to convert -

    This is the method that loads everything into memory -

    PdfReader reader;
    long before;
    before = getMemoryUse();
    reader = new PdfReader(
    "HelloWorldToRead.pdf", null);
    System.out.println("Memory used by the full read: "
    + (getMemoryUse() - before));
    

    This is the memory saving way, where the document should be loaded bit-by-bit as required -

    before = getMemoryUse();
    reader = new PdfReader(
    new RandomAccessFileOrArray("HelloWorldToRead.pdf"), null);
    System.out.println("Memory used by the partial read: "
    + (getMemoryUse() - before));
    

提交回复
热议问题