Skip to content

Commit

Permalink
Add another test case to PdfSmartCopyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusfaber authored and asturio committed Aug 7, 2024
1 parent 995773a commit a975154
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions openpdf/src/test/java/com/lowagie/text/pdf/PdfSmartCopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.time.Duration;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -76,4 +78,36 @@ void canWriteAndCopy() throws IOException {
}
}

@Test
void canInterleaveTwoFilesWithCustomPages() throws IOException {
// Interleaves two PDF files with a custom page in front of each
try (PdfReader reader1 = new PdfReader("src/test/resources/pdfsmartcopy_bec.pdf");
PdfReader reader2 = new PdfReader("src/test/resources/HelloWorldMeta.pdf")
) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (Document document = new Document()) {
try (PdfCopy copy = new PdfSmartCopy(document, outputStream)) {
document.open();

for (int i = 1; i <= 10; i++) {
document.add(new Paragraph("Page " + i + " from document 1"));
document.newPage();
PdfImportedPage page1 = copy.getImportedPage(reader1, ((i - 1) % reader1.getNumberOfPages()) + 1);
copy.addPage(page1);
document.add(new Paragraph("Page " + i + " from document 2"));
document.newPage();
PdfImportedPage page2 = copy.getImportedPage(reader2, ((i - 1) % reader2.getNumberOfPages()) + 1);
copy.addPage(page2);
}

copy.freeReader(reader1);
copy.freeReader(reader2);
}
}
try (PdfReader resultReader = new PdfReader(outputStream.toByteArray())) {
assertEquals(40, resultReader.getNumberOfPages());
}
}
}

}

0 comments on commit a975154

Please sign in to comment.