...
Codeblock |
---|
File outputFile=...
UIDocument<Component> uiDocument = getPageView().getDocument();
if (uiDocument != null && //
uiDocument.getState() == Document.BasicState.READY && //
uiDocument.getPageCount() > 0) {
final EventList<Page> pages = uiDocument.getPages();
final ReadWriteLock lock = pages.getReadWriteLock();
lock.readLock().lock();
try {
Page page = uiDocument.getPage(0); // jede Seite bietet Zugriff auf die beinhalteten PageSegments, die einen Zugriff auf ihr Original-Datenstrom anbieten.
FileOutputStream fos = null;
try {
fos = new FileOutputStream(outputFile);
final PageSegmentSource pss = page.getPageSegment(DocumentLayer.DEFAULT).getSource();
final SeekableInputStream stream = pss.getStream();
synchronized (stream) {
stream.seek(0);
IOUtils.copy(stream, fos);
}
} catch (final Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} finally {
lock.readLock().unlock();
}
}
|