We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

syncfusion_flutter_pdf saving file with nothing on it, not even extension of .pdf on file name

i'm programmin in a MacOs, and runnig my code in IOS emulator, when i save the path with ''getApplicationDocumentsDirectory();'' i choose to save the file, because it open an box asking what should do with it, but the file hads nothing, is not even .pdf, trying to get some help but can't found it so thats bring me here, i try with and without ''pdfdocument.dispose'', heres my code:




Future<void> pdfCreater() async {
PdfDocument pdfdocumento = PdfDocument();
final page = pdfdocumento.pages.add();

page.graphics.drawString('Impressão Matricular', PdfStandardFont(PdfFontFamily.helvetica, 35));

List<int> Bytes = await pdfdocumento.save();
pdfdocumento.dispose();
PdfSaver(Bytes, 'matricula_data');
}


Future<void> PdfSaver(List<int> Bytes, String FileName) async {

final path = await getDownloadPath(); // function for see directory if android or ios
final file = File('$path/$FileName');
await file.writeAsBytes(Bytes, flush: true);
OpenFile.open('$path/$FileName');
}

2 Replies 1 reply marked as answer

IJ Irfana Jaffer Sadhik Syncfusion Team February 1, 2023 01:19 PM UTC

Based on the provided code example, we found that the PDF file was being saved without an extension, which was causing the reported issue. We suggest you add the proper extension when writing files. You can refer to the following code example for further details.

  Future<void> _createPdf() async {

    PdfDocument pdfdocumento = PdfDocument();

    final page = pdfdocumento.pages.add();

 

    page.graphics.drawString(

        'Impressão Matricular', PdfStandardFont(PdfFontFamily.helvetica, 35));

 

    List<int> bytes = await pdfdocumento.save();

    pdfdocumento.dispose();

    pdfSaver(bytes, 'matricula_data.pdf');

  }

 

  Future<void> pdfSaver(List<int> bytes, String fileName) async {

    Directory path =

        await getApplicationDocumentsDirectory(); // function for see directory if android or ios

    String outputPath = path.path;

    final file = File('$outputPath/$fileName');

    await file.writeAsBytes(bytes, flush: true);

    OpenFile.open('$outputPath/$fileName');

  }

}

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/create_pdf_sample-687432817

You can try the above sample on your end and let us know if you have any questions.


Marked as answer

BS Bruce Scavelo replied to Irfana Jaffer Sadhik February 12, 2023 02:18 PM UTC

thank u so much <3


Loader.
Live Chat Icon For mobile
Up arrow icon