我必须使用SOAP服务并在flutter应用程序中生成pdf文档。我使用FileOutputStream对Java进行了同样的操作。由于不熟悉,我尝试使用PDF软件包(https://pub.dartlang.org/packages/pdf)。但是pdf是用字节码生成的,而不是解码后的数据。
有什么建议吗?
TaxFormObject object =
TaxFormObject(xml.parse(response.body).findAllElements("document"));
_taxform = base64.decode(object.attachment);
setState(() {
"TaxForm:" + object.attachment;
});
final file = await _localFile;
Future<File> get _localFile async {
final path = await _localPath;
final pdf = PdfDocument(deflate: zlib.encode);
final page = PdfPage(pdf, pageFormat: PdfPageFormat.letter);
final g = page.getGraphics();
final font = g.defaultFont;
final top = page.pageFormat.height;
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRect(50.0 * PdfPageFormat.mm, top - 80.0 * PdfPageFormat.mm,
100.0 * PdfPageFormat.mm, 50.0 * PdfPageFormat.mm);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(font, 12.0, _taxform.toString(), 10.0 * PdfPageFormat.mm,
top - 10.0 * PdfPageFormat.mm);
initPlatformState();
var file = File('$path/TaxForm.pdf');
file.writeAsBytesSync(pdf.save());
//file.writeAsBytesSync(_taxform);
}