From 849add5889a7bd624730b5fbb7e229c88ba0682a Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 14 Dec 2023 19:31:25 +0545 Subject: [PATCH 01/12] Plugin Migrate --- android/build.gradle | 2 +- pubspec.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8990414..6b51b5b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ group 'com.afur.flutter_html_to_pdf' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.20' repositories { google() mavenCentral() diff --git a/pubspec.yaml b/pubspec.yaml index db314ef..2cbacb6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_html_to_pdf description: Flutter plugin for generating PDF documents from HTML code templates -version: 0.7.0 +version: 0.7.1 homepage: https://github.com/Afur/flutter_html_to_pdf environment: - sdk: '>=2.12.0 <3.0.0' - flutter: ">=1.12.0" + sdk: '>=3.0.5 <4.0.0' + flutter: ">=3.0.0" dependencies: flutter: From 331df07daaaa9fc28853e0e68bc628d1d2eb783b Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 14 Dec 2023 19:33:25 +0545 Subject: [PATCH 02/12] Example Migrate --- example/android/app/build.gradle | 8 ++++---- example/android/app/src/main/AndroidManifest.xml | 1 + example/android/build.gradle | 6 +++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/lib/main.dart | 16 +++++++--------- example/pubspec.yaml | 7 +++---- example/test/widget_test.dart | 6 +++--- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index b0ed919..dd04ba9 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) { def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") + throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -44,8 +44,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.afur.flutter_html_to_pdf_example" - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion flutter.minSdkVersion + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index c63d539..6982e16 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ android:icon="@mipmap/ic_launcher"> { - String generatedPdfFilePath; + late String generatedPdfFilePath; @override void initState() { @@ -71,7 +70,11 @@ class _MyAppState extends State { final targetPath = appDocDir.path; final targetFileName = "example-pdf"; - final generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(htmlContent, targetPath, targetFileName); + final generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent( + htmlContent, + targetPath, + targetFileName, + ); generatedPdfFilePath = generatedPdfFile.path; } @@ -83,12 +86,7 @@ class _MyAppState extends State { body: Center( child: ElevatedButton( child: Text("Open Generated PDF Preview"), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => PDFViewerScaffold(appBar: AppBar(title: Text("Generated PDF Document")), path: generatedPdfFilePath)), - ); - }, + onPressed: () {}, ), ), )); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8923a59..497e9fc 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,17 +3,16 @@ description: Demonstrates how to use the flutter_html_to_pdf plugin. publish_to: 'none' environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=3.0.5 <4.0.0" dependencies: flutter: sdk: flutter - path_provider: ^0.4.1 - flutter_full_pdf_viewer: ^1.0.2 + path_provider: ^2.1.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.6 dev_dependencies: flutter_test: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index d61f707..a5bf6b2 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -13,13 +13,13 @@ import 'package:flutter_html_to_pdf_example/main.dart'; void main() { testWidgets('Verify Platform version', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(MyApp()); // Verify that platform version is retrieved. expect( find.byWidgetPredicate( - (Widget widget) => widget is Text && - widget.data!.startsWith('Running on:'), + (Widget widget) => + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget, ); From 0225f5e81f4c10393797e226e050bf48c0b0d96c Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 14 Dec 2023 19:53:12 +0545 Subject: [PATCH 03/12] Replaced PDF viewing plugin --- example/lib/main.dart | 66 +++++++++++++++++++++++++++++-------------- example/pubspec.yaml | 1 + 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index b75af64..61174ba 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,11 +4,14 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_html_to_pdf/flutter_html_to_pdf.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:pdf_viewer_plugin/pdf_viewer_plugin.dart'; void main() { - runApp(MaterialApp( - home: MyApp(), - )); + runApp( + MaterialApp( + home: MyApp(), + ), + ); } class MyApp extends StatefulWidget { @@ -17,12 +20,42 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - late String generatedPdfFilePath; + String? generatedPdfFilePath; @override - void initState() { - super.initState(); - generateExampleDocument(); + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + body: SafeArea( + child: SizedBox( + width: MediaQuery.of(context).size.width, + child: buildBody(), + ), + ), + )); + } + + Column buildBody() { + return Column( + children: [ + Expanded( + child: generatedPdfFilePath != null + ? PdfView(path: generatedPdfFilePath!) + : SizedBox(), + ), + buildButton(), + ], + ); + } + + Padding buildButton() { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 12.0), + child: ElevatedButton( + child: Text("Open Generated PDF Preview"), + onPressed: generateExampleDocument, + ), + ); } Future generateExampleDocument() async { @@ -75,20 +108,11 @@ class _MyAppState extends State { targetPath, targetFileName, ); - generatedPdfFilePath = generatedPdfFile.path; - } - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - appBar: AppBar(), - body: Center( - child: ElevatedButton( - child: Text("Open Generated PDF Preview"), - onPressed: () {}, - ), - ), - )); + setState( + () { + generatedPdfFilePath = generatedPdfFile.path; + }, + ); } } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 497e9fc..c91fee5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -9,6 +9,7 @@ dependencies: flutter: sdk: flutter path_provider: ^2.1.1 + pdf_viewer_plugin: ^2.0.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 7673798ec70510f356c3945e0a9cd0b098452f57 Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 14 Dec 2023 19:54:29 +0545 Subject: [PATCH 04/12] Example plugin dependency fix --- example/ios/Runner/Info.plist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index b301a78..96a9f27 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -41,5 +41,7 @@ UIViewControllerBasedStatusBarAppearance + io.flutter.embedded_views_preview + From 825290615bae70b6fd3287e73579630a7a5bf7a5 Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 14 Dec 2023 21:08:31 +0545 Subject: [PATCH 05/12] Lowering support --- example/pubspec.yaml | 6 +++--- pubspec.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c91fee5..a91d33b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,17 +3,17 @@ description: Demonstrates how to use the flutter_html_to_pdf plugin. publish_to: 'none' environment: - sdk: ">=3.0.5 <4.0.0" + sdk: '>=2.18.0 <4.0.0' dependencies: flutter: sdk: flutter - path_provider: ^2.1.1 + path_provider: ^2.1.0 pdf_viewer_plugin: ^2.0.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.6 + cupertino_icons: ^1.0.5 dev_dependencies: flutter_test: diff --git a/pubspec.yaml b/pubspec.yaml index 2cbacb6..27d2a60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_html_to_pdf description: Flutter plugin for generating PDF documents from HTML code templates -version: 0.7.1 +version: 0.7.0 homepage: https://github.com/Afur/flutter_html_to_pdf environment: - sdk: '>=3.0.5 <4.0.0' - flutter: ">=3.0.0" + sdk: '>=2.18.0 <4.0.0' + flutter: ">=3.3.0" dependencies: flutter: From 3b6ace1ebca144615257e81ac02ee91d3b706bfb Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 21 Dec 2023 15:07:04 +0545 Subject: [PATCH 06/12] Added Style tag to ensure background colors are not ignored --- lib/file_utils.dart | 13 +++++++++++++ lib/flutter_html_to_pdf.dart | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/file_utils.dart b/lib/file_utils.dart index 84ef7d1..23bc28c 100644 --- a/lib/file_utils.dart +++ b/lib/file_utils.dart @@ -12,4 +12,17 @@ class FileUtils { fileOriginal.delete(); return fileCopy; } + + static Future appendStyleTagToHtmlFile(String htmlPath) async { + String printStyleHtml = """ + + """; + await File(htmlPath).writeAsString(printStyleHtml,mode: FileMode.append); + } } diff --git a/lib/flutter_html_to_pdf.dart b/lib/flutter_html_to_pdf.dart index 148ee2e..8de4628 100644 --- a/lib/flutter_html_to_pdf.dart +++ b/lib/flutter_html_to_pdf.dart @@ -12,6 +12,7 @@ class FlutterHtmlToPdf { /// Can throw a [PlatformException] or (unlikely) a [MissingPluginException] converting html to pdf static Future convertFromHtmlContent(String htmlContent, String targetDirectory, String targetName) async { final temporaryCreatedHtmlFile = await FileUtils.createFileWithStringContent(htmlContent, "$targetDirectory/$targetName.html"); + await FileUtils.appendStyleTagToHtmlFile(temporaryCreatedHtmlFile.path); final generatedPdfFilePath = await _convertFromHtmlFilePath(temporaryCreatedHtmlFile.path); final generatedPdfFile = FileUtils.copyAndDeleteOriginalFile(generatedPdfFilePath, targetDirectory, targetName); temporaryCreatedHtmlFile.delete(); @@ -22,6 +23,7 @@ class FlutterHtmlToPdf { /// Creates PDF Document from File that contains HTML content /// Can throw a [PlatformException] or (unlikely) a [MissingPluginException] converting html to pdf static Future convertFromHtmlFile(File htmlFile, String targetDirectory, String targetName) async { + await FileUtils.appendStyleTagToHtmlFile(htmlFile.path); final generatedPdfFilePath = await _convertFromHtmlFilePath(htmlFile.path); final generatedPdfFile = FileUtils.copyAndDeleteOriginalFile(generatedPdfFilePath, targetDirectory, targetName); @@ -31,6 +33,7 @@ class FlutterHtmlToPdf { /// Creates PDF Document from path to File that contains HTML content /// Can throw a [PlatformException] or (unlikely) a [MissingPluginException] converting html to pdf static Future convertFromHtmlFilePath(String htmlFilePath, String targetDirectory, String targetName) async { + await FileUtils.appendStyleTagToHtmlFile(htmlFilePath); final generatedPdfFilePath = await _convertFromHtmlFilePath(htmlFilePath); final generatedPdfFile = FileUtils.copyAndDeleteOriginalFile(generatedPdfFilePath, targetDirectory, targetName); From 9400bc4c9596ed505d4edaafd4448f3704865370 Mon Sep 17 00:00:00 2001 From: mandip rai Date: Thu, 21 Dec 2023 21:50:10 +0545 Subject: [PATCH 07/12] iOS implementation for Orientation and Papersize --- ios/Classes/PDFCreator.swift | 4 ++-- ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ios/Classes/PDFCreator.swift b/ios/Classes/PDFCreator.swift index 41b8e12..cfb2a5e 100644 --- a/ios/Classes/PDFCreator.swift +++ b/ios/Classes/PDFCreator.swift @@ -6,14 +6,14 @@ class PDFCreator { Creates a PDF using the given print formatter and saves it to the user's document directory. - returns: The generated PDF path. */ - class func create(printFormatter: UIPrintFormatter) -> URL { + class func create(printFormatter: UIPrintFormatter, width: Double, height: Double) -> URL { // assign the print formatter to the print page renderer let renderer = UIPrintPageRenderer() renderer.addPrintFormatter(printFormatter, startingAtPageAt: 0) // assign paperRect and printableRect values - let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8) // A4, 72 dpi + let page = CGRect(x: 0, y: 0, width: width, height: height) renderer.setValue(page, forKey: "paperRect") renderer.setValue(page, forKey: "printableRect") diff --git a/ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift b/ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift index b9d51d2..127e592 100644 --- a/ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift +++ b/ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift @@ -17,10 +17,12 @@ public class SwiftFlutterHtmlToPdfPlugin: NSObject, FlutterPlugin{ case "convertHtmlToPdf": let args = call.arguments as? [String: Any] let htmlFilePath = args!["htmlFilePath"] as? String + let width = Double(args!["width"] as! Int) + let height = Double(args!["height"] as! Int) // !!! this is workaround for issue with rendering PDF images on iOS !!! let viewControler = UIApplication.shared.delegate?.window?!.rootViewController - wkWebView = WKWebView.init(frame: viewControler!.view.bounds) + wkWebView = WKWebView.init(frame: CGRect(origin: CGPoint(x:0, y:0), size: CGSize(width: width, height: height))) wkWebView.isHidden = true wkWebView.tag = 100 viewControler?.view.addSubview(wkWebView) @@ -30,8 +32,8 @@ public class SwiftFlutterHtmlToPdfPlugin: NSObject, FlutterPlugin{ urlObservation = wkWebView.observe(\.isLoading, changeHandler: { (webView, change) in // this is workaround for issue with loading local images - DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { - let convertedFileURL = PDFCreator.create(printFormatter: self.wkWebView.viewPrintFormatter()) + DispatchQueue.main.asyncAfter(deadline: .now() + 10.5) { + let convertedFileURL = PDFCreator.create(printFormatter: self.wkWebView.viewPrintFormatter(), width: width, height:height) let convertedFilePath = convertedFileURL.absoluteString.replacingOccurrences(of: "file://", with: "") // return generated pdf path if let viewWithTag = viewControler?.view.viewWithTag(100) { viewWithTag.removeFromSuperview() // remove hidden webview when pdf is generated From 6eb2b5a44788e768b3d7533f665ac6b9d3a12576 Mon Sep 17 00:00:00 2001 From: mandip rai Date: Wed, 27 Dec 2023 13:51:33 +0545 Subject: [PATCH 08/12] Landscape mode and Print size support added --- .../FlutterHtmlToPdfPlugin.kt | 4 +- .../flutter_html_to_pdf/HtmlToPdfConverter.kt | 30 ++++- example/lib/main.dart | 23 ++-- ios/Classes/PDFCreator.swift | 8 +- ios/Classes/SwiftFlutterHtmlToPdfPlugin.swift | 8 +- lib/flutter_html_to_pdf.dart | 93 ++++++++++++--- lib/pdf_print_configuration.dart | 25 ++++ lib/print_configuration_enums.dart | 108 ++++++++++++++++++ 8 files changed, 260 insertions(+), 39 deletions(-) create mode 100644 lib/pdf_print_configuration.dart create mode 100644 lib/print_configuration_enums.dart diff --git a/android/src/main/kotlin/com/afur/flutter_html_to_pdf/FlutterHtmlToPdfPlugin.kt b/android/src/main/kotlin/com/afur/flutter_html_to_pdf/FlutterHtmlToPdfPlugin.kt index fe9600f..95876f9 100644 --- a/android/src/main/kotlin/com/afur/flutter_html_to_pdf/FlutterHtmlToPdfPlugin.kt +++ b/android/src/main/kotlin/com/afur/flutter_html_to_pdf/FlutterHtmlToPdfPlugin.kt @@ -35,8 +35,10 @@ class FlutterHtmlToPdfPlugin: FlutterPlugin, MethodCallHandler { private fun convertHtmlToPdf(call: MethodCall, result: Result) { val htmlFilePath = call.argument("htmlFilePath") + val printSize = call.argument("printSize") + val orientation = call.argument("orientation") - HtmlToPdfConverter().convert(htmlFilePath!!, applicationContext, object : HtmlToPdfConverter.Callback { + HtmlToPdfConverter().convert(htmlFilePath!!, applicationContext, printSize!!, orientation!!, object : HtmlToPdfConverter.Callback { override fun onSuccess(filePath: String) { result.success(filePath) } diff --git a/android/src/main/kotlin/com/afur/flutter_html_to_pdf/HtmlToPdfConverter.kt b/android/src/main/kotlin/com/afur/flutter_html_to_pdf/HtmlToPdfConverter.kt index 8d6144e..da2a112 100644 --- a/android/src/main/kotlin/com/afur/flutter_html_to_pdf/HtmlToPdfConverter.kt +++ b/android/src/main/kotlin/com/afur/flutter_html_to_pdf/HtmlToPdfConverter.kt @@ -19,7 +19,7 @@ class HtmlToPdfConverter { } @SuppressLint("SetJavaScriptEnabled") - fun convert(filePath: String, applicationContext: Context, callback: Callback) { + fun convert(filePath: String, applicationContext: Context, printSize: String, orientation: String, callback: Callback) { val webView = WebView(applicationContext) val htmlContent = File(filePath).readText(Charsets.UTF_8) webView.settings.javaScriptEnabled = true @@ -29,18 +29,38 @@ class HtmlToPdfConverter { webView.webViewClient = object : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { super.onPageFinished(view, url) - createPdfFromWebView(webView, applicationContext, callback) + createPdfFromWebView(webView, applicationContext, printSize, orientation, callback) } } } - fun createPdfFromWebView(webView: WebView, applicationContext: Context, callback: Callback) { + fun createPdfFromWebView(webView: WebView, applicationContext: Context, printSize: String, orientation: String, callback: Callback) { val path = applicationContext.filesDir if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + var mediaSize = PrintAttributes.MediaSize.ISO_A4 + + when (printSize) { + "A0" -> mediaSize = PrintAttributes.MediaSize.ISO_A0 + "A1" -> mediaSize = PrintAttributes.MediaSize.ISO_A1 + "A2" -> mediaSize = PrintAttributes.MediaSize.ISO_A2 + "A3" -> mediaSize = PrintAttributes.MediaSize.ISO_A3 + "A4" -> mediaSize = PrintAttributes.MediaSize.ISO_A4 + "A5" -> mediaSize = PrintAttributes.MediaSize.ISO_A5 + "A6" -> mediaSize = PrintAttributes.MediaSize.ISO_A6 + "A7" -> mediaSize = PrintAttributes.MediaSize.ISO_A7 + "A8" -> mediaSize = PrintAttributes.MediaSize.ISO_A8 + "A9" -> mediaSize = PrintAttributes.MediaSize.ISO_A9 + "A10" -> mediaSize = PrintAttributes.MediaSize.ISO_A10 + } + + when (orientation) { + "LANDSCAPE" -> mediaSize = mediaSize.asPortrait() + "PORTRAIT" -> mediaSize = mediaSize.asLandscape() + } val attributes = PrintAttributes.Builder() - .setMediaSize(PrintAttributes.MediaSize.ISO_A4) - .setResolution(PrintAttributes.Resolution("pdf", "pdf", 600, 600)) + .setMediaSize(mediaSize) + .setResolution(PrintAttributes.Resolution("pdf", "pdf", 300, 300)) .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build() val printer = PdfPrinter(attributes) diff --git a/example/lib/main.dart b/example/lib/main.dart index 61174ba..a7c6629 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,14 +25,15 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( - home: Scaffold( - body: SafeArea( - child: SizedBox( - width: MediaQuery.of(context).size.width, - child: buildBody(), + home: Scaffold( + body: SafeArea( + child: SizedBox( + width: MediaQuery.of(context).size.width, + child: buildBody(), + ), ), ), - )); + ); } Column buildBody() { @@ -104,9 +105,13 @@ class _MyAppState extends State { final targetFileName = "example-pdf"; final generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent( - htmlContent, - targetPath, - targetFileName, + htmlContent: htmlContent, + printPdfConfiguration: PrintPdfConfiguration( + targetDirectory: targetPath, + targetName: targetFileName, + printSize: PrintSize.A4, + printOrientation: PrintOrientation.Portrait, + ), ); setState( diff --git a/ios/Classes/PDFCreator.swift b/ios/Classes/PDFCreator.swift index cfb2a5e..1056093 100644 --- a/ios/Classes/PDFCreator.swift +++ b/ios/Classes/PDFCreator.swift @@ -14,16 +14,18 @@ class PDFCreator { // assign paperRect and printableRect values let page = CGRect(x: 0, y: 0, width: width, height: height) + let printable = page.insetBy(dx: 0, dy: 0) + renderer.setValue(page, forKey: "paperRect") - renderer.setValue(page, forKey: "printableRect") + renderer.setValue(printable, forKey: "printableRect") // create pdf context and draw each page let pdfData = NSMutableData() UIGraphicsBeginPDFContextToData(pdfData, .zero, nil) for i in 0..