exported pdf documents are now automatically closed
This commit is contained in:
@@ -73,6 +73,8 @@ public class ZUGFeRDExporter implements Closeable {
|
|||||||
private PDDocument doc;
|
private PDDocument doc;
|
||||||
int ZFVersion;
|
int ZFVersion;
|
||||||
|
|
||||||
|
private boolean disableAutoClose;
|
||||||
|
|
||||||
public ZUGFeRDExporter() {
|
public ZUGFeRDExporter() {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@@ -282,12 +284,19 @@ public class ZUGFeRDExporter implements Closeable {
|
|||||||
|
|
||||||
public void export(String ZUGFeRDfilename) throws IOException {
|
public void export(String ZUGFeRDfilename) throws IOException {
|
||||||
doc.save(ZUGFeRDfilename);
|
doc.save(ZUGFeRDfilename);
|
||||||
|
if (!disableAutoClose) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(OutputStream output) throws IOException {
|
public void export(OutputStream output) throws IOException {
|
||||||
doc.save(output);
|
doc.save(output);
|
||||||
|
if (!disableAutoClose) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Embeds an external file (generic - any type allowed) in the PDF.
|
* Embeds an external file (generic - any type allowed) in the PDF.
|
||||||
*
|
*
|
||||||
@@ -418,4 +427,12 @@ public class ZUGFeRDExporter implements Closeable {
|
|||||||
return doc;
|
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);
|
zea1.PDFattachZugferdFile(null);
|
||||||
|
|
||||||
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
||||||
|
zea1.disableAutoClose(true);
|
||||||
zea1.export(TARGET_PDF);
|
zea1.export(TARGET_PDF);
|
||||||
zea1.export(baos);
|
zea1.export(baos);
|
||||||
|
zea1.close();
|
||||||
String pdfContent=baos.toString("UTF-8");
|
String pdfContent=baos.toString("UTF-8");
|
||||||
assertFalse(pdfContent.indexOf("(via mustangproject.org")==-1);
|
assertFalse(pdfContent.indexOf("(via mustangproject.org")==-1);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -370,10 +370,12 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
|
|||||||
ze.setZUGFeRDVersion(2);
|
ze.setZUGFeRDVersion(2);
|
||||||
|
|
||||||
ze.PDFattachZugferdFile(this);
|
ze.PDFattachZugferdFile(this);
|
||||||
|
ze.disableAutoClose(true);
|
||||||
ze.export(TARGET_PDF);
|
ze.export(TARGET_PDF);
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ze.export(baos);
|
ze.export(baos);
|
||||||
|
ze.close();
|
||||||
String pdfContent = baos.toString("UTF-8");
|
String pdfContent = baos.toString("UTF-8");
|
||||||
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
|
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user