Enrich test data, fix multi-page PDF export, and polish UI
- Populate debug test data with random notes, guided reflections, and weather - Fix PDF export to use UIPrintPageRenderer for proper multi-page pagination - Add journal/reflection indicator icons to day list entry cells - Fix weather card icon contrast by using secondarySystemBackground - Align Generate Report and Export PDF button widths in ReportsView Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import WebKit
|
||||
|
||||
@MainActor
|
||||
@@ -60,7 +61,7 @@ final class ReportPDFGenerator {
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=612, initial-scale=1">
|
||||
<style>
|
||||
\(cssStyles)
|
||||
</style>
|
||||
@@ -294,7 +295,7 @@ final class ReportPDFGenerator {
|
||||
let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: 612, height: 792))
|
||||
webView.isOpaque = false
|
||||
|
||||
// Load HTML and wait for it to render
|
||||
// Load HTML and wait for it to finish rendering
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
let delegate = PDFNavigationDelegate { result in
|
||||
switch result {
|
||||
@@ -443,18 +444,29 @@ private class PDFNavigationDelegate: NSObject, WKNavigationDelegate {
|
||||
}
|
||||
|
||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||
let config = WKPDFConfiguration()
|
||||
config.rect = CGRect(x: 0, y: 0, width: 612, height: 792) // US Letter
|
||||
// Use UIPrintPageRenderer for proper multi-page pagination.
|
||||
// createPDF(configuration:) only captures a single rect — it does NOT paginate.
|
||||
let renderer = UIPrintPageRenderer()
|
||||
renderer.addPrintFormatter(webView.viewPrintFormatter(), startingAtPageAt: 0)
|
||||
|
||||
webView.createPDF(configuration: config) { [weak self] result in
|
||||
DispatchQueue.main.async {
|
||||
switch result {
|
||||
case .success(let data):
|
||||
self?.completion(.success(data))
|
||||
case .failure(let error):
|
||||
self?.completion(.failure(ReportPDFGenerator.PDFError.pdfGenerationFailed(underlying: error)))
|
||||
}
|
||||
}
|
||||
// US Letter size (72 points per inch: 8.5 x 11 inches)
|
||||
let pageRect = CGRect(x: 0, y: 0, width: 612, height: 792)
|
||||
renderer.setValue(pageRect, forKey: "paperRect")
|
||||
renderer.setValue(pageRect, forKey: "printableRect")
|
||||
|
||||
let pdfData = NSMutableData()
|
||||
UIGraphicsBeginPDFContextToData(pdfData, pageRect, nil)
|
||||
renderer.prepare(forDrawingPages: NSMakeRange(0, renderer.numberOfPages))
|
||||
|
||||
let bounds = UIGraphicsGetPDFContextBounds()
|
||||
for i in 0..<renderer.numberOfPages {
|
||||
UIGraphicsBeginPDFPage()
|
||||
renderer.drawPage(at: i, in: bounds)
|
||||
}
|
||||
UIGraphicsEndPDFContext()
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.completion(.success(pdfData as Data))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user