diff --git a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs index 0c30becc..64a90fbf 100644 --- a/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs +++ b/src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs @@ -233,6 +233,45 @@ } } + [Fact] + public void CanWriteTwoPageDocument() + { + var builder = new PdfDocumentBuilder(); + var page1 = builder.AddPage(PageSize.A4); + var page2 = builder.AddPage(PageSize.A4); + + var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Fonts", "TrueType"); + var file = Path.Combine(path, "Roboto-Regular.ttf"); + + var font = builder.AddTrueTypeFont(File.ReadAllBytes(file)); + + var topLine = new PdfPoint(30, page1.PageSize.Height - 60); + var letters = page1.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor", 9, topLine, font); + page1.AddText("incididunt ut labore et dolore magna aliqua.", 9, new PdfPoint(30, topLine.Y - letters.Max(x => x.GlyphRectangle.Height) - 5), font); + + var page2Letters = page2.AddText("The very hungry caterpillar ate all the apples in the garden.", 12, topLine, font); + var left = page2Letters[0].GlyphRectangle.Left; + var bottom = page2Letters.Min(x => x.GlyphRectangle.Bottom); + var right = page2Letters[page2Letters.Count - 1].GlyphRectangle.Right; + var top = page2Letters.Max(x => x.GlyphRectangle.Top); + page2.SetStrokeColor(10, 250, 69); + page2.DrawRectangle(new PdfPoint(left, bottom), right - left, top - bottom); + + var bytes = builder.Build(); + WriteFile(nameof(CanWriteTwoPageDocument), bytes); + + using (var document = PdfDocument.Open(bytes)) + { + var page1Out = document.GetPage(1); + + Assert.StartsWith("Lorem ipsum dolor sit", page1Out.Text); + + var page2Out = document.GetPage(2); + + Assert.StartsWith("The very hungry caterpillar", page2Out.Text); + } + } + private static void WriteFile(string name, byte[] bytes) { try diff --git a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs index 6303ac70..9a608dc8 100644 --- a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs @@ -253,7 +253,7 @@ { { NameToken.Type, NameToken.Pages }, { NameToken.Kids, new ArrayToken(pageReferences) }, - { NameToken.Count, new NumericToken(1) } + { NameToken.Count, new NumericToken(pageReferences.Count) } }); var pagesRef = context.WriteObject(memory, pagesDictionary, reserved); diff --git a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs index b433c22d..bb417542 100644 --- a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs @@ -65,7 +65,7 @@ /// /// Draws a rectangle on the current page starting at the specified point with the given width, height and line width. /// - /// The position of the rectangle, for positive width and height this is the top-left corner. + /// The position of the rectangle, for positive width and height this is the bottom-left corner. /// The width of the rectangle. /// The height of the rectangle. /// The width of the line border of the rectangle.