I'm currently using Swift along with a WKWebView to load HTML, establish the A4 page dimensions, and then save it as a PDF. (Though, I believe this is more of an HTML/CSS-focused question).
The generation process looks like this:
func generatePDFData(landscape: Bool, newLayout: Bool) -> NSMutableData {
var a4PageFrame: CGRect?
a4PageFrame = landscape ? CGRect(x: 0, y: 0, width: 841.8, height: 595.2) : CGRect(x: 0, y: 0, width: 595.2, height: 841.8)
let originalBounds = bounds
bounds = CGRect(x: originalBounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: scrollView.contentSize.height)
let printFormatter = viewPrintFormatter()
let printPageRenderer = UIPrintPageRenderer()
printPageRenderer.addPrintFormatter(printFormatter, startingAtPageAt: 0)
printPageRenderer.setValue(a4PageFrame, forKey: "paperRect")
printPageRenderer.setValue(a4PageFrame, forKey: "printableRect")
printPageRenderer.headerHeight = newLayout ? 10 : 25
printPageRenderer.footerHeight = newLayout ? 10 : 25
bounds = originalBounds
return printPageRenderer.renderPDFData()
}
Additionally, here is a sampling of the HTML code used:
<!DOCTYPE html>
<html>
<head>
...
</style>
</head>
<body>
...
</body>
</html>
I am wondering if there exists a method to display all of this content on just one page through auto-adjustment? Specifically, resizing the table to fit onto a single page (even if that means reducing font size, etc., which would likely be necessary). The content varies in quantity, sometimes more or less depending on user input. Typically printed in landscape mode, but even on desktops, fitting everything onto one page is difficult: https://i.sstatic.net/KuSSs.jpg