我正试图将我用docx_template库制作的docx文件:^0.3.3到PDF,我尝试过使用库来做到这一点。我有这个:
//Get external storage directory
final directory = await getApplicationDocumentsDirectory();
//Get directory path
String path = directory.path;
final of = File('$path/Engranes Rectos Sistema Ingles.docx');
if (d != null) await of.writeAsBytes(d);
Directory directory2 = (await getApplicationDocumentsDirectory());
String path2 = directory2.path;
final PdfDocument document = PdfDocument(
inputBytes: File('$path/Engranes Rectos Sistema Ingles.docx')
.readAsBytesSync());
//Save the document.
File file = File('$path/Engranes Rectos Sistema Ingles.pdf');
await file.writeAsBytes(await document.save(), flush: true);
//Dispose the document.
document.dispose();
OpenFile.open('$path/Engranes Rectos Sistema Ingles.pdf');
使用此包或任何支持以字节形式输入的包
https://pub.dev/packages/syncfusion_flutter_pdf
您可以将doc转换为字节并生成如下所示的pdf
//Load the existing docx document.
final PdfDocument document =
PdfDocument(inputBytes: File('input.docx').readAsBytesSync());
//Save the document.
File('yourFileName.pdf').writeAsBytes(await document.save());
//Dispose the document.
document.dispose();
Kaushik Chandru的回答不适合我:[ERROR:flutter/runtime/dart_vm_initializer.cc(41)]未处理异常:RangeError (end):无效值:不在包含范围2048..12210: 1024# 0 RangeError。checkValidRange(飞镖:核心/errors.dart: 379:9)# 1 _TypedIntListMixin。分表(飞镖:typed_data-patch/typed_data_patch.dart: 466:31)# 2 CrossTable。_checkJunk(包:syncfusion_flutter_pdf/src/pdf/实现/io/cross_table.dart: 503:38)
# 3 CrossTable。_initialize (package:syncfusion_flutter_pdf/src/pdf/implementation/io/cross_table.dart:112:32)
#4 new CrossTable (package:syncfusion_flutter_pdf/src/pdf/implementation/io/cross_table.dart:27:5)# 5 PdfCrossTable。_initializeCrossTable(包:syncfusion_flutter_pdf/src/pdf/实现/io/pdf_cross_table.dart: 177:19)#6新pdfcrossstable(包:syncfusion_flutter_pdf/src/pdf/implementation/io/pdf_cross_table.dart:41:9)# 7 PdfDocument。_initialize(包:syncfusion_flutter_pdf/src/pdf/实现/pdf_document/pdf_document.dart: 757:28)#8 new PdfDocument (package:syncfusion_flutter_pdf/src/pdf/implementation/pdf_document/pdf_document.dart:78:5)
#9 loadDocument (package:summary_ai/load_document.dart:19:7)