pagePdf static method

dynamic pagePdf(
  1. Page page, {
  2. Function? callback,
  3. Map<String, dynamic> pageSettings = const {},
})

Implementation

static pagePdf(Page page,{Function? callback,Map<String,dynamic >pageSettings=const {}})async{
  PaperFormat pageFormat=PaperFormat.a4;
  _debug(pageSettings);
  if(pageSettings.containsKey("height")&&pageSettings.containsKey("width")){
    pageFormat=PaperFormat.mm(width:pageSettings.getDouble("width"), height:pageSettings.getDouble("height")+1);
  }
  else if(pageSettings.containsKey("page_size")){
    String pageSize=pageSettings.getString("page_size").toUpperCase();
    if(PrintHelper.pages.containsKey(pageSize)){
      Map<String,dynamic >page=PrintHelper.pages.getMap<String,dynamic>(pageSize);
      double height=page.getDouble("height");
      double width=page.getDouble("width");
      if(pageSettings.containsKey("page_orientation")){
        bool isRoll=false;
        if(page.containsKey("is_roll")){
          isRoll=page.getBool("is_roll");
        }
        if(!isRoll){
          height=page.getDouble("width");
          width=page.getDouble("height");
        }
      }
      pageFormat=PaperFormat.mm(width:width, height:height);

    }
  }
  // page.emulateMediaType(MediaType.screen);
  Uint8List? pdfData=await page.pdf(format: pageFormat);
  if(callback!=null){
    callback(pdfData);
  }
  page.close();
}