Reputation: 12043
Assuming I print a small amount of text into a PDF document, I like to know how much of the page is actually used by the text.
For example, if I render a short text paragraph into a PDF document, I like to learn the content height of only that text, not of the entire A4 (letter) page.
Background
I need to render a long HTML page into a PDF document that uses a smaller page size. The result is that the content gets rendered into several PDF pages. I currently use NSPrintOperation
for this.
The challenge is that I also need to render a footer page into each page. For this, I need to dynamically determine the height of that footer so that I can set the page's bottom margin accordingly, resulting in the footer area be kept free when rendering the main (body) HTML content. Once that's finished, I can then add the footer to each page in a separate step (using CGPDFDocument
).
I wish there was a simpler way, but it seems that the macOS HTML renderer cannot handle html footers when printing multiple pages.
Upvotes: 0
Views: 225
Reputation: 12043
I found a solution, though that's a bit ugly:
NSPDFImageRepMBS
NSImageMBS
and add the imageRep to it with addRepresentation:
CGPDFDocument
, going over each page of the main PDF, drawing thes main pages along with the footer (offset into the page's footer area) into each page.Upvotes: 0