use of org.dea.fimgstoreclient.beans.FimgStoreImgMd in project TranskribusCore by Transkribus.
the class FimgStoreReadConnection method getImgMd.
public static FimgStoreImgMd getImgMd(URL url) throws IOException {
FimgStoreFileMd md = getFileMd(url);
if (!(md instanceof FimgStoreImgMd)) {
throw new IOException("File with key " + md.getKey() + " is not an image!");
}
FimgStoreImgMd imgMd = (FimgStoreImgMd) md;
return imgMd;
}
use of org.dea.fimgstoreclient.beans.FimgStoreImgMd in project TranskribusCore by Transkribus.
the class PageXmlUtils method createEmptyPcGtsType.
public static PcGtsType createEmptyPcGtsType(final URL imgUrl, Dimension dim) throws IOException {
final String prot = imgUrl.getProtocol();
PcGtsType pcGts;
if (prot.startsWith("http")) {
// fimagestore file
FimgStoreImgMd md = FimgStoreReadConnection.getImgMd(imgUrl);
pcGts = createEmptyPcGtsTypeForRemoteImg(imgUrl, md);
} else {
// try to deal with it as local file
final File imgFile = FileUtils.toFile(imgUrl);
pcGts = createEmptyPcGtsType(imgFile, dim);
}
return pcGts;
}
use of org.dea.fimgstoreclient.beans.FimgStoreImgMd in project TranskribusCore by Transkribus.
the class PageXmlUtilsTest method testSth.
public static void testSth() throws Exception {
File[] files = { new File("/mnt/dea_scratch/TRP/test/page_xsl_test/ocr/Mittheilungen_Perthes_1855_0009.xml"), new File("/mnt/dea_scratch/TRP/test/ImagesOldPageXml/page/2010-03-19_backup/035_320_001.xml"), new File("/mnt/dea_scratch/TRP/test/page_xsl_test/Mittheilungen_Perthes_1855_0009.xml") };
try {
URL url = new URL("https://dbis-thure.uibk.ac.at/fimagestore/Get?fileType=metadata&id=YSUGXUUGAHYCUQVMEUJAYQGO");
FimgStoreImgMd md = FimgStoreReadConnection.getImgMd(url);
PcGtsType t = PageXmlUtils.createEmptyPcGtsType(url, md.getDimension());
JaxbUtils.marshalToSysOut(t);
} catch (IOException | JAXBException e) {
e.printStackTrace();
}
// for(File f : files){
// try {
// System.out.println(XmlUtils.getXmlFormat(f).toString());
// } catch (IOException e) {
//
// e.printStackTrace();
// }
// }
}
use of org.dea.fimgstoreclient.beans.FimgStoreImgMd 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;
}
Aggregations