Skip to content

Commit 81742f3

Browse files
Merge pull request #252 from sixdouglas/Fix/#250-RemoveClosableAndAutoClosableFromPdfWriter
Fix #250 - Remove Closable And AutoClosable From PdfWriter
2 parents c3ea87f + c5343f4 commit 81742f3

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import java.awt.Color;
5353
import java.awt.color.ICC_Profile;
5454
import java.io.ByteArrayOutputStream;
55-
import java.io.Closeable;
5655
import java.io.IOException;
5756
import java.io.OutputStream;
5857
import java.security.cert.Certificate;
@@ -104,8 +103,6 @@
104103
*/
105104

106105
public class PdfWriter extends DocWriter implements
107-
AutoCloseable,
108-
Closeable,
109106
PdfViewerPreferences,
110107
PdfEncryptionSettings,
111108
PdfVersion,
@@ -1158,8 +1155,7 @@ public void open() {
11581155
@Override
11591156
public void close() {
11601157
if (open) {
1161-
if (this.document.isOpen()) this.document.close();
1162-
1158+
11631159
if ((currentPageNumber - 1) != pageReferences.size())
11641160
// 2019-04-26: If you get this error, it could be that you are using OpenPDF or
11651161
// another library such as flying-saucer's ITextRenderer in a non-threadsafe way.

openpdf/src/test/java/com/lowagie/text/pdf/SimplePdfTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ void testSimplePdf() throws Exception {
3434
void testTryWithResources_with_os_before_doc() throws Exception {
3535
try (PdfReader reader = new PdfReader("./src/test/resources/HelloWorldMeta.pdf");
3636
FileOutputStream os = new FileOutputStream(File.createTempFile("temp-file-name", ".pdf"));
37-
Document document = new Document();
38-
PdfWriter writer = PdfWriter.getInstance(document, os)
37+
Document document = new Document()
3938
) {
39+
PdfWriter writer = PdfWriter.getInstance(document, os);
4040
document.open();
4141
final PdfContentByte cb = writer.getDirectContent();
4242

@@ -49,9 +49,9 @@ void testTryWithResources_with_os_before_doc() throws Exception {
4949
@Test
5050
void testTryWithResources_with_unknown_os() throws Exception {
5151
try (PdfReader reader = new PdfReader("./src/test/resources/HelloWorldMeta.pdf");
52-
Document document = new Document();
53-
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(File.createTempFile("temp-file-name", ".pdf")))
52+
Document document = new Document()
5453
) {
54+
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(File.createTempFile("temp-file-name", ".pdf")));
5555
document.open();
5656
final PdfContentByte cb = writer.getDirectContent();
5757

0 commit comments

Comments
 (0)