size property

Size size

Gets size of the PDF page- Read only

//Create a new PDF documentation
PdfDocument document = PdfDocument();
//Create a new PDF page and Gets the size of its page
Size size = document.pages.add().size;
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

Size get size {
  if (_helper.isLoadedPage) {
    if (_size == null || (_size!.width == 0 && _size!.height == 0)) {
      double width = 0;
      double height = 0;
      final IPdfPrimitive? mBox = _helper.dictionary!.getValue(
          PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent);
      final IPdfPrimitive? cBox = _helper.dictionary!.getValue(
          PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent);
      if (cBox != null && cBox is PdfArray) {
        final num c0 = (cBox[0]! as PdfNumber).value!;
        final num? c1 = (cBox[1]! as PdfNumber).value;
        final num c2 = (cBox[2]! as PdfNumber).value!;
        final num? c3 = (cBox[3]! as PdfNumber).value;
        width = (c2 - c0).toDouble();
        height = c3 != 0 ? (c3! - c1!).toDouble() : c1!.toDouble();
      } else if (mBox != null && mBox is PdfArray) {
        final num m0 = (mBox[0]! as PdfNumber).value!;
        final num? m1 = (mBox[1]! as PdfNumber).value;
        final num m2 = (mBox[2]! as PdfNumber).value!;
        final num? m3 = (mBox[3]! as PdfNumber).value;
        width = (m2 - m0).toDouble();
        height = m3 != 0 ? (m3! - m1!).toDouble() : m1!.toDouble();
      }
      _size = Size(width, height);
    }
    return _size!;
  } else {
    return _helper.section!.pageSettings.size;
  }
}