David PHAM-VAN

Deprecate support for convertHtml

... ... @@ -7,6 +7,7 @@
- Update cursors in zoom mode for web [Aleksei]
- Output image sized to cropBox instead of mediaBox (iOS) [garrettApproachableGeek]
- Replace Activity with Context for Service Compatibility (Android) [Heinrich]
- Deprecate support for `convertHtml`
## 5.11.1
... ...
... ... @@ -126,12 +126,27 @@ await Printing.sharePdf(bytes: await doc.save(), filename: 'my-document.pdf');
To print an HTML document:
import [HTMLtoPDFWidgets](https://pub.dev/packages/htmltopdfwidgets)
```dart
await Printing.layoutPdf(
onLayout: (PdfPageFormat format) async => await Printing.convertHtml(
format: format,
html: '<html><body><p>Hello!</p></body></html>',
));
await Printing.layoutPdf(onLayout: (PdfPageFormat format) async {
const body = '''
<h1>Heading Example</h1>
<p>This is a paragraph.</p>
<img src="image.jpg" alt="Example Image" />
<blockquote>This is a quote.</blockquote>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
''';
final pdf = pw.Document();
final widgets = await HTMLToPdf().convert(body);
pdf.addPage(pw.MultiPage(build: (context) => widgets));
return await pdf.save();
});
```
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 {
result.put("directPrint", false);
result.put("dynamicLayout", canPrint);
result.put("canPrint", canPrint);
result.put("canConvertHtml", canRaster);
result.put("canShare", true);
result.put("canRaster", canRaster);
return result;
... ...
... ... @@ -396,7 +396,6 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
"directPrint": true,
"dynamicLayout": true,
"canPrint": true,
"canConvertHtml": true,
"canShare": true,
"canRaster": true,
"canListPrinters": false,
... ...
... ... @@ -184,6 +184,7 @@ mixin Printing {
///
/// This is not supported on all platforms. Check the result of [info] to
/// find at runtime if this feature is available or not.
@Deprecated('Please use another method to create your PDF document')
static Future<Uint8List> convertHtml({
required String html,
String? baseUrl,
... ...
... ... @@ -309,7 +309,6 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
"directPrint": true,
"dynamicLayout": true,
"canPrint": true,
"canConvertHtml": true,
"canShare": true,
"canRaster": true,
"canListPrinters": true,
... ...
... ... @@ -44,10 +44,6 @@ void main() {
.setMockMethodCallHandler(channel, null);
});
test('convertHtml', () async {
// expect(await Printing.platformVersion, '42');
});
test('flutterImageProvider(FileImage)', () async {
final image =
await flutterImageProvider(FileImage(File('$path/example.png')));
... ...
... ... @@ -20,7 +20,6 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:pdf/pdf.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:printing/printing.dart';
import 'package:printing/src/interface.dart';
... ... @@ -73,13 +72,6 @@ void main() {
);
});
test('convertHtml', () async {
expect(
await Printing.convertHtml(html: '<html></html>'),
isInstanceOf<Uint8List>(),
);
});
test('raster', () async {
expect(
Printing.raster(Uint8List(0)),
... ... @@ -129,11 +121,6 @@ class MockPrinting extends Mock
@override
Stream<PdfRaster> raster(
Uint8List document, List<int>? pages, double dpi) async* {}
@override
Future<Uint8List> convertHtml(
String html, String? baseUrl, PdfPageFormat format) async =>
Uint8List(0);
}
class MockContext extends Mock implements BuildContext {}
... ...
... ... @@ -398,9 +398,8 @@ void PrintJob::rasterPdf(std::vector<uint8_t> data,
std::map<std::string, bool> PrintJob::printingInfo() {
return std::map<std::string, bool>{
{"directPrint", true}, {"dynamicLayout", true}, {"canPrint", true},
{"canListPrinters", true}, {"canConvertHtml", false}, {"canShare", true},
{"canRaster", true},
{"directPrint", true}, {"dynamicLayout", true}, {"canPrint", true},
{"canListPrinters", true}, {"canShare", true}, {"canRaster", true},
};
}
... ...
... ... @@ -54,6 +54,8 @@ void buildFile(String src, String dest, bool flutter) {
st.writeln('import \'package:flutter/services.dart\' show rootBundle;');
if (flutter) {
st.writeln('import \'package:path_provider/path_provider.dart\';');
st.writeln(
'import \'package:htmltopdfwidgets/htmltopdfwidgets.dart\' show HTMLToPdf;');
} else {
st.writeln('import \'dart:convert\';');
st.writeln('import \'dart:html\' as html;');
... ...
... ... @@ -13,6 +13,7 @@ dependencies:
args:
flutter:
sdk: flutter
htmltopdfwidgets:
markdown:
meta:
string_scanner:
... ...