| 67 | import com.artifex.mupdf.fitz.*; |
| 68 | |
| 69 | class MultiThreaded |
| 70 | { |
| 71 | public static void main(String args[]) |
| 72 | { |
| 73 | /* Parse arguments. */ |
| 74 | if (args.length < 1) |
| 75 | { |
| 76 | System.err.println("usage: MultiThreaded input-file"); |
| 77 | System.err.println("\tinput-file: path of PDF, XPS, CBZ or EPUB document to open"); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | String filename = args[0]; |
| 82 | |
| 83 | /* Open the document on the main thread. |
| 84 | * You may not reference doc in any other thread. |
| 85 | */ |
| 86 | Document doc; |
| 87 | try { |
| 88 | doc = Document.openDocument(filename); |
| 89 | } catch (RuntimeException ex) { |
| 90 | System.err.println("cannot open document: " + ex.getMessage()); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | /* Count the pages on the main thread. */ |
| 95 | int pageCount; |
| 96 | try { |
| 97 | pageCount = doc.countPages(); |
| 98 | } catch (RuntimeException ex) { |
| 99 | System.err.println("cannot count document pages: " + ex.getMessage()); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | /* Create a thread, an output pixmap and an exception placeholder per page. */ |
| 104 | final Thread[] threads = new Thread[pageCount]; |
| 105 | final Pixmap[] pixmaps = new Pixmap[pageCount]; |
| 106 | final Exception[] exceptions = new Exception[pageCount]; |
| 107 | |
| 108 | for (int i = 0; i < pageCount; ++i) |
| 109 | { |
| 110 | final int pageNumber = i; |
| 111 | try { |
| 112 | /* Load page and convert it to a display list on |
| 113 | * the main thread. Note that this cannot be done |
| 114 | * in worker threads since doc should only be used |
| 115 | * by the main thread. |
| 116 | */ |
| 117 | Page page = doc.loadPage(pageNumber); |
| 118 | |
| 119 | /* Determine the bounding box for the page */ |
| 120 | final Rect bounds = page.getBounds(); |
| 121 | |
| 122 | /* Convert the page into a display list. The display |
| 123 | * list can be used by any other thread as it is not |
| 124 | * bound to doc. |
| 125 | */ |
| 126 | final DisplayList displayList = page.toDisplayList(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…