Showing
11 changed files
with
27 additions
and
28 deletions
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | - Update cursors in zoom mode for web [Aleksei] | 7 | - Update cursors in zoom mode for web [Aleksei] |
| 8 | - Output image sized to cropBox instead of mediaBox (iOS) [garrettApproachableGeek] | 8 | - Output image sized to cropBox instead of mediaBox (iOS) [garrettApproachableGeek] |
| 9 | - Replace Activity with Context for Service Compatibility (Android) [Heinrich] | 9 | - Replace Activity with Context for Service Compatibility (Android) [Heinrich] |
| 10 | +- Deprecate support for `convertHtml` | ||
| 10 | 11 | ||
| 11 | ## 5.11.1 | 12 | ## 5.11.1 |
| 12 | 13 |
| @@ -126,12 +126,27 @@ await Printing.sharePdf(bytes: await doc.save(), filename: 'my-document.pdf'); | @@ -126,12 +126,27 @@ await Printing.sharePdf(bytes: await doc.save(), filename: 'my-document.pdf'); | ||
| 126 | 126 | ||
| 127 | To print an HTML document: | 127 | To print an HTML document: |
| 128 | 128 | ||
| 129 | +import [HTMLtoPDFWidgets](https://pub.dev/packages/htmltopdfwidgets) | ||
| 130 | + | ||
| 129 | ```dart | 131 | ```dart |
| 130 | -await Printing.layoutPdf( | ||
| 131 | - onLayout: (PdfPageFormat format) async => await Printing.convertHtml( | ||
| 132 | - format: format, | ||
| 133 | - html: '<html><body><p>Hello!</p></body></html>', | ||
| 134 | - )); | 132 | +await Printing.layoutPdf(onLayout: (PdfPageFormat format) async { |
| 133 | + const body = ''' | ||
| 134 | + <h1>Heading Example</h1> | ||
| 135 | + <p>This is a paragraph.</p> | ||
| 136 | + <img src="image.jpg" alt="Example Image" /> | ||
| 137 | + <blockquote>This is a quote.</blockquote> | ||
| 138 | + <ul> | ||
| 139 | + <li>First item</li> | ||
| 140 | + <li>Second item</li> | ||
| 141 | + <li>Third item</li> | ||
| 142 | + </ul> | ||
| 143 | + '''; | ||
| 144 | + | ||
| 145 | + final pdf = pw.Document(); | ||
| 146 | + final widgets = await HTMLToPdf().convert(body); | ||
| 147 | + pdf.addPage(pw.MultiPage(build: (context) => widgets)); | ||
| 148 | + return await pdf.save(); | ||
| 149 | +}); | ||
| 135 | ``` | 150 | ``` |
| 136 | 151 | ||
| 137 | Convert a Pdf to images, one image per page, get only pages 1 and 2 at 72 dpi: | 152 | Convert a Pdf to images, one image per page, get only pages 1 and 2 at 72 dpi: |
| @@ -86,7 +86,6 @@ public class PrintingJob extends PrintDocumentAdapter { | @@ -86,7 +86,6 @@ public class PrintingJob extends PrintDocumentAdapter { | ||
| 86 | result.put("directPrint", false); | 86 | result.put("directPrint", false); |
| 87 | result.put("dynamicLayout", canPrint); | 87 | result.put("dynamicLayout", canPrint); |
| 88 | result.put("canPrint", canPrint); | 88 | result.put("canPrint", canPrint); |
| 89 | - result.put("canConvertHtml", canRaster); | ||
| 90 | result.put("canShare", true); | 89 | result.put("canShare", true); |
| 91 | result.put("canRaster", canRaster); | 90 | result.put("canRaster", canRaster); |
| 92 | return result; | 91 | return result; |
| @@ -396,7 +396,6 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | @@ -396,7 +396,6 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate | ||
| 396 | "directPrint": true, | 396 | "directPrint": true, |
| 397 | "dynamicLayout": true, | 397 | "dynamicLayout": true, |
| 398 | "canPrint": true, | 398 | "canPrint": true, |
| 399 | - "canConvertHtml": true, | ||
| 400 | "canShare": true, | 399 | "canShare": true, |
| 401 | "canRaster": true, | 400 | "canRaster": true, |
| 402 | "canListPrinters": false, | 401 | "canListPrinters": false, |
| @@ -184,6 +184,7 @@ mixin Printing { | @@ -184,6 +184,7 @@ mixin Printing { | ||
| 184 | /// | 184 | /// |
| 185 | /// This is not supported on all platforms. Check the result of [info] to | 185 | /// This is not supported on all platforms. Check the result of [info] to |
| 186 | /// find at runtime if this feature is available or not. | 186 | /// find at runtime if this feature is available or not. |
| 187 | + @Deprecated('Please use another method to create your PDF document') | ||
| 187 | static Future<Uint8List> convertHtml({ | 188 | static Future<Uint8List> convertHtml({ |
| 188 | required String html, | 189 | required String html, |
| 189 | String? baseUrl, | 190 | String? baseUrl, |
| @@ -309,7 +309,6 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | @@ -309,7 +309,6 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { | ||
| 309 | "directPrint": true, | 309 | "directPrint": true, |
| 310 | "dynamicLayout": true, | 310 | "dynamicLayout": true, |
| 311 | "canPrint": true, | 311 | "canPrint": true, |
| 312 | - "canConvertHtml": true, | ||
| 313 | "canShare": true, | 312 | "canShare": true, |
| 314 | "canRaster": true, | 313 | "canRaster": true, |
| 315 | "canListPrinters": true, | 314 | "canListPrinters": true, |
| @@ -44,10 +44,6 @@ void main() { | @@ -44,10 +44,6 @@ void main() { | ||
| 44 | .setMockMethodCallHandler(channel, null); | 44 | .setMockMethodCallHandler(channel, null); |
| 45 | }); | 45 | }); |
| 46 | 46 | ||
| 47 | - test('convertHtml', () async { | ||
| 48 | - // expect(await Printing.platformVersion, '42'); | ||
| 49 | - }); | ||
| 50 | - | ||
| 51 | test('flutterImageProvider(FileImage)', () async { | 47 | test('flutterImageProvider(FileImage)', () async { |
| 52 | final image = | 48 | final image = |
| 53 | await flutterImageProvider(FileImage(File('$path/example.png'))); | 49 | await flutterImageProvider(FileImage(File('$path/example.png'))); |
| @@ -20,7 +20,6 @@ import 'package:flutter/widgets.dart'; | @@ -20,7 +20,6 @@ import 'package:flutter/widgets.dart'; | ||
| 20 | import 'package:flutter_test/flutter_test.dart'; | 20 | import 'package:flutter_test/flutter_test.dart'; |
| 21 | import 'package:mockito/mockito.dart'; | 21 | import 'package:mockito/mockito.dart'; |
| 22 | import 'package:pdf/pdf.dart'; | 22 | import 'package:pdf/pdf.dart'; |
| 23 | - | ||
| 24 | import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | 23 | import 'package:plugin_platform_interface/plugin_platform_interface.dart'; |
| 25 | import 'package:printing/printing.dart'; | 24 | import 'package:printing/printing.dart'; |
| 26 | import 'package:printing/src/interface.dart'; | 25 | import 'package:printing/src/interface.dart'; |
| @@ -73,13 +72,6 @@ void main() { | @@ -73,13 +72,6 @@ void main() { | ||
| 73 | ); | 72 | ); |
| 74 | }); | 73 | }); |
| 75 | 74 | ||
| 76 | - test('convertHtml', () async { | ||
| 77 | - expect( | ||
| 78 | - await Printing.convertHtml(html: '<html></html>'), | ||
| 79 | - isInstanceOf<Uint8List>(), | ||
| 80 | - ); | ||
| 81 | - }); | ||
| 82 | - | ||
| 83 | test('raster', () async { | 75 | test('raster', () async { |
| 84 | expect( | 76 | expect( |
| 85 | Printing.raster(Uint8List(0)), | 77 | Printing.raster(Uint8List(0)), |
| @@ -129,11 +121,6 @@ class MockPrinting extends Mock | @@ -129,11 +121,6 @@ class MockPrinting extends Mock | ||
| 129 | @override | 121 | @override |
| 130 | Stream<PdfRaster> raster( | 122 | Stream<PdfRaster> raster( |
| 131 | Uint8List document, List<int>? pages, double dpi) async* {} | 123 | Uint8List document, List<int>? pages, double dpi) async* {} |
| 132 | - | ||
| 133 | - @override | ||
| 134 | - Future<Uint8List> convertHtml( | ||
| 135 | - String html, String? baseUrl, PdfPageFormat format) async => | ||
| 136 | - Uint8List(0); | ||
| 137 | } | 124 | } |
| 138 | 125 | ||
| 139 | class MockContext extends Mock implements BuildContext {} | 126 | class MockContext extends Mock implements BuildContext {} |
| @@ -398,9 +398,8 @@ void PrintJob::rasterPdf(std::vector<uint8_t> data, | @@ -398,9 +398,8 @@ void PrintJob::rasterPdf(std::vector<uint8_t> data, | ||
| 398 | 398 | ||
| 399 | std::map<std::string, bool> PrintJob::printingInfo() { | 399 | std::map<std::string, bool> PrintJob::printingInfo() { |
| 400 | return std::map<std::string, bool>{ | 400 | return std::map<std::string, bool>{ |
| 401 | - {"directPrint", true}, {"dynamicLayout", true}, {"canPrint", true}, | ||
| 402 | - {"canListPrinters", true}, {"canConvertHtml", false}, {"canShare", true}, | ||
| 403 | - {"canRaster", true}, | 401 | + {"directPrint", true}, {"dynamicLayout", true}, {"canPrint", true}, |
| 402 | + {"canListPrinters", true}, {"canShare", true}, {"canRaster", true}, | ||
| 404 | }; | 403 | }; |
| 405 | } | 404 | } |
| 406 | 405 |
| @@ -54,6 +54,8 @@ void buildFile(String src, String dest, bool flutter) { | @@ -54,6 +54,8 @@ void buildFile(String src, String dest, bool flutter) { | ||
| 54 | st.writeln('import \'package:flutter/services.dart\' show rootBundle;'); | 54 | st.writeln('import \'package:flutter/services.dart\' show rootBundle;'); |
| 55 | if (flutter) { | 55 | if (flutter) { |
| 56 | st.writeln('import \'package:path_provider/path_provider.dart\';'); | 56 | st.writeln('import \'package:path_provider/path_provider.dart\';'); |
| 57 | + st.writeln( | ||
| 58 | + 'import \'package:htmltopdfwidgets/htmltopdfwidgets.dart\' show HTMLToPdf;'); | ||
| 57 | } else { | 59 | } else { |
| 58 | st.writeln('import \'dart:convert\';'); | 60 | st.writeln('import \'dart:convert\';'); |
| 59 | st.writeln('import \'dart:html\' as html;'); | 61 | st.writeln('import \'dart:html\' as html;'); |
-
Please register or login to post a comment