exported pdf documents are now automatically closed
This commit is contained in:
@@ -73,6 +73,8 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
private PDDocument doc;
|
||||
int ZFVersion;
|
||||
|
||||
private boolean disableAutoClose;
|
||||
|
||||
public ZUGFeRDExporter() {
|
||||
init();
|
||||
}
|
||||
@@ -282,12 +284,19 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user