DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.39k stars 614 forks source link

How to change printing margins #1676

Open deniscass opened 3 months ago

deniscass commented 3 months ago

Hi guys,

I need a help about change printer margins from this module in Flutter. For example, i have a Epson Thermal printer T20 thats accept print pdfs. I need change all margins to 0.5cm a print some text content in 80 columns layout.

When i attempt change PdfFormat and Document settings in my code, i get large default margin in printed result. How work with document and page setting to get margin changed:

Thanks in advance

bksbora commented 3 months ago

   const double inch = 72.0;
    const double cm = inch / 2.54;
      body: Container(
          height: MediaQuery.of(context).size.height,
          color: AppTheme().kirlibeyaz,
          child: PdfPreview(
            canDebug: false,
            canChangePageFormat: false,
            canChangeOrientation: false,
            pdfFileName: '${customerModel.musteriAdiSoyadi!.replaceAll(RegExp(r' '), "-").toString()}-${AppLocalizations.of(context)!.production}',
            maxPageWidth: (MediaQuery.of(context).size.height),
            build: (format) => _generatePdf(
              // ? Veriyi Pdf'e Aktarma!
              // Margin
              const PdfPageFormat(21.0 * cm, 29.7 * cm, marginAll: 0.5 * cm),
            ),
          )),
          ``` Hope it will solve your problem.
deniscass commented 4 weeks ago

Thank so much @bksbora i will try this