diff --git a/HelloWorld.pdf b/HelloWorld.pdf new file mode 100644 index 0000000..85e6bcb Binary files /dev/null and b/HelloWorld.pdf differ diff --git a/src/main/java/com/github/fabriciofx/cactoos/pdf/Document.java b/src/main/java/com/github/fabriciofx/cactoos/pdf/Document.java index 9680451..e84cd24 100644 --- a/src/main/java/com/github/fabriciofx/cactoos/pdf/Document.java +++ b/src/main/java/com/github/fabriciofx/cactoos/pdf/Document.java @@ -52,6 +52,11 @@ public final class Document implements Bytes { */ private static final String EOF = "%%%%EOF"; + /** + * Count. + */ + private final Count count; + /** * PDF metadata. */ @@ -65,10 +70,16 @@ public final class Document implements Bytes { /** * Ctor. * + * @param count Count * @param metadata Metadata * @param catalog Catalog */ - public Document(final Metadata metadata, final Catalog catalog) { + public Document( + final Count count, + final Metadata metadata, + final Catalog catalog + ) { + this.count = count; this.metadata = metadata; this.catalog = catalog; } @@ -87,8 +98,9 @@ public byte[] asBytes() throws Exception { baos.write(this.catalog.asBytes()); baos.write( new FormattedText( - "trailer << /Root %s /Size 6 >>\n", - this.catalog.reference() + "trailer << /Root %s /Size %d >>\n", + this.catalog.reference(), + this.count.value() ).asString().getBytes() ); baos.write(Document.EOF.getBytes()); diff --git a/src/test/java/com/github/fabriciofx/cactoos/pdf/DocumentTest.java b/src/test/java/com/github/fabriciofx/cactoos/pdf/DocumentTest.java index 7a79dff..814e0bd 100644 --- a/src/test/java/com/github/fabriciofx/cactoos/pdf/DocumentTest.java +++ b/src/test/java/com/github/fabriciofx/cactoos/pdf/DocumentTest.java @@ -45,6 +45,7 @@ void buildDocument() { "Must represent a PDF document", new TextOf( new Document( + count, new Metadata(count, "Hello World"), new Catalog( count, @@ -84,7 +85,7 @@ void buildDocument() { "4 0 obj\n<< /Type /Page /Resources 2 0 R /Contents 3 0 R /Parent 5 0 R >>\nendobj", "2 0 obj\n<< /Font << /F1 << /Type /Font /BaseFont /Times-Roman /Subtype /Type1 >> >> >>\nendobj", "3 0 obj\n<< /Length 62 >>\nstream\nBT /F1 18 Tf 0 0 Td (Hello World with \\(, \\), \\\\ and \\r) Tj ET\nendstream\nendobj", - "trailer << /Root 6 0 R /Size 6 >>", + "trailer << /Root 6 0 R /Size 7 >>", "%%%%EOF" ) ) @@ -99,6 +100,7 @@ void buildFile() throws Exception { Files.write( file.toPath(), new Document( + count, new Metadata(count, "Hello World"), new Catalog( count,