use of eu.transkribus.core.model.builder.ExportCache in project TranskribusCore by Transkribus.
the class TrpXlsxBuilder method main.
public static void main(String[] args) throws Exception {
TrpDoc doc = LocalDocReader.load("C:/Users/Administrator/OCR_Sample_Document_-_Gothic_letter/");
TrpXlsxBuilder txslx = new TrpXlsxBuilder();
writeXlsxForDoc(doc, true, new File("C:/Users/Administrator/test.xlsx"), null, null, new ExportCache());
// ExcelTest("C:/Users/Administrator/test.xlsx");
System.out.println("finished");
}
use of eu.transkribus.core.model.builder.ExportCache in project TranskribusCore by Transkribus.
the class PdfExporter method export.
public File export(final TrpDoc doc, final String path, Set<Integer> pageIndices, final boolean useWordLevel, final boolean addTextPages, final boolean imagesOnly, final boolean highlightTags, final boolean doBlackening, boolean createTitle, ExportCache cache) throws DocumentException, MalformedURLException, IOException, JAXBException, URISyntaxException, InterruptedException {
if (doc == null) {
throw new IllegalArgumentException("TrpDoc is null!");
}
if (path == null) {
throw new IllegalArgumentException("path is null!");
}
if (cache == null) {
cache = new ExportCache();
}
// if(startPage == null || startPage < 1) startPage = 1;
// final int nrOfPages = doc.getPages().size();
// if(endPage == null || endPage > nrOfPages+1) endPage = nrOfPages;
//
// if(startPage > endPage){
// throw new IllegalArgumentException("Start page must be smaller than end page!");
// }
File pdfFile = new File(path);
TrpPdfDocument pdf = new TrpPdfDocument(pdfFile, useWordLevel, highlightTags, doBlackening, createTitle);
setChanged();
notifyObservers("Creating PDF document...");
boolean onePagePrinted = false;
// for(int i = startPage-1; i <= endPage-1; i++){
for (int i = 0; i < doc.getPages().size(); ++i) {
if (pageIndices != null && !pageIndices.contains(i))
continue;
logger.info("Processing page " + (i + 1));
TrpPage p = doc.getPages().get(i);
URL imgUrl = p.getUrl();
/*
* md is only needed for getting resolution because in the image it may be missing
* But if it is a local doc we have to try to get from img because md is null
*/
FimgStoreImgMd md = null;
if (doc.isRemoteDoc()) {
FimgStoreGetClient getter = new FimgStoreGetClient(p.getUrl());
md = (FimgStoreImgMd) getter.getFileMd(p.getKey());
}
URL xmlUrl = p.getCurrentTranscript().getUrl();
logger.debug("output with tags " + highlightTags);
// PcGtsType pc = PageXmlUtils.unmarshal(xmlUrl);
// should be the same as above
JAXBPageTranscript pt = null;
if (cache != null) {
pt = cache.getPageTranscriptAtIndex(i);
}
PcGtsType pc;
if (pt != null) {
pc = pt.getPageData();
} else {
pc = PageXmlUtils.unmarshal(xmlUrl);
}
if (!onePagePrinted) {
// add first page and previously add a title page with doc metadata and editorial declarations (if this option is set)
pdf.addPage(imgUrl, doc, pc, addTextPages, imagesOnly, md, doBlackening, cache);
onePagePrinted = true;
} else {
pdf.addPage(imgUrl, null, pc, addTextPages, imagesOnly, md, doBlackening, cache);
}
setChanged();
notifyObservers(Integer.valueOf(i + 1));
if (cancel) {
pdf.close();
File file = new File(path);
if (!file.delete()) {
throw new IOException("Could not delete the incomplete PDF file during export cancel");
}
throw new InterruptedException("Export canceled by the user");
// break;
}
}
if (highlightTags) {
pdf.addTags(doc, pageIndices, useWordLevel, cache);
}
pdf.close();
setChanged();
notifyObservers("PDF written at: " + path);
logger.info("PDF written at: " + path);
return pdfFile;
}
use of eu.transkribus.core.model.builder.ExportCache in project TranskribusCore by Transkribus.
the class TrpTxtBuilder method main.
public static void main(String[] args) {
// final String path = "/mnt/dea_scratch/TRP/Bentham_box_002_GT";
final String path = "X:/TRP/Bentham_box_002_GT";
try {
TrpDoc doc = LocalDocReader.load(path);
writeTxtForDoc(doc, true, false, true, new File("TxtExportTest.txt"), null, null, new ExportCache());
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Docx4JException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations