exported pdf documents are now automatically closed

This commit is contained in:
Jochen Stärk
2017-11-18 12:35:51 +01:00
parent dce0015c0b
commit 3ea71f95e9
3 changed files with 22 additions and 2 deletions

View File

@@ -73,6 +73,8 @@ public class ZUGFeRDExporter implements Closeable {
private PDDocument doc;
int ZFVersion;
private boolean disableAutoClose;
public ZUGFeRDExporter() {
init();
}
@@ -282,11 +284,18 @@ public class ZUGFeRDExporter implements Closeable {
public void export(String ZUGFeRDfilename) throws IOException {
doc.save(ZUGFeRDfilename);
if (!disableAutoClose) {
close();
}
}
public void export(OutputStream output) throws IOException {
doc.save(output);
if (!disableAutoClose) {
close();
}
}
/**
* Embeds an external file (generic - any type allowed) in the PDF.
@@ -418,4 +427,12 @@ public class ZUGFeRDExporter implements Closeable {
return doc;
}
public boolean isAutoCloseDisabled() {
return disableAutoClose;
}
public void disableAutoClose(boolean disableAutoClose) {
this.disableAutoClose = disableAutoClose;
}
}

View File

@@ -186,9 +186,10 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
zea1.PDFattachZugferdFile(null);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent=baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org")==-1);
} catch (IOException e) {

View File

@@ -370,10 +370,12 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
ze.setZUGFeRDVersion(2);
ze.PDFattachZugferdFile(this);
ze.disableAutoClose(true);
ze.export(TARGET_PDF);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);