UglyToad / PdfPig

Read and extract text and other content from PDFs in C# (port of PDFBox)
https://github.com/UglyToad/PdfPig/wiki
Apache License 2.0
1.73k stars 241 forks source link

Bug: PdfPageBuilder.CopyFrom did not preserve the page orientation #348

Closed Banyc closed 1 year ago

Banyc commented 3 years ago

The source page (page.Rotation == 90) is in horizontal orientation. The new document generated from PdfPageBuilder.CopyFrom has a correct orientation in page size, but with a vertical-oriented content.

The example code is in the following:

PdfDocumentBuilder builder = new();
var page = this.document.GetPage(pageIndex + 1);
PdfPageBuilder pageBuilder = builder.AddPage(page.Width, page.Height);
pageBuilder.CopyFrom(page);

var bytes = builder.Build();
File.WriteAllBytes(outputFilePath, bytes);
hangy commented 3 years ago

There are a handful of properties currently not copiesd by CopyFrom: https://github.com/UglyToad/PdfPig/blob/2df5ec9b1021b87fae6392a9b5e88c1d3ecfd4c7/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs#L594-L596

Maybe you could use AddPage as an alternative: https://github.com/UglyToad/PdfPig/blob/c74ca5fda8a51f3af9cf19c675272f57d3beee60/src/UglyToad.PdfPig/Writer/PdfMerger.cs#L140

EliotJones commented 1 year ago

I think this should be covered by AddPage