Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Issue with roll80 paper size #1804

Open
4 tasks
MohammedNiyasK opened this issue Jan 9, 2025 · 0 comments
Open
4 tasks

Issue with roll80 paper size #1804

MohammedNiyasK opened this issue Jan 9, 2025 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@MohammedNiyasK
Copy link

Describe the bug

When using the Roll80 paper size, if I select Roll80 in the PDF preview, it displays correctly. However, when I click the print button on the preview page, it navigates to the print page, and the paper size changes to Letter format.

If I select the share button and then click the print button, the content preview on the print page is aligned to the left side of the page.

To Reproduce
Code snippet to reproduce the behavior:

// your code
class SamplePdfPreview extends StatelessWidget {
  const SamplePdfPreview({super.key});

  static const double inch = 72.0;
  static const double mm = inch / 25.4;
  static const double milToMm = 0.0254;

  static const _defaultPageFormats = <String, PdfPageFormat>{
    'A4': PdfPageFormat.a4,
    'THERMAL': PdfPageFormat(
      4015 * milToMm * PdfPageFormat.mm, // Convert width to mm
      double.infinity,
      marginAll: 5 * PdfPageFormat.mm, // Example margin
    ),
    'roll80': PdfPageFormat.roll80,
    'ISO_C7': PdfPageFormat(
      4015 * milToMm * PdfPageFormat.mm, // Convert width to mm
      6929 * milToMm * PdfPageFormat.mm,
      marginAll: 5 * PdfPageFormat.mm,
    ),
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('PDF Preview'),
      ),
      body: PdfPreview(
        initialPageFormat: _defaultPageFormats['roll80'], // Start with roll80
        canChangePageFormat: true,
        pageFormats: _defaultPageFormats,
        allowPrinting: true,
        dynamicLayout: false,
        build: (format) async {
          return await _buildPdf1(format);
        },
        enableScrollToPage: true,
      ),
    );
  }

  static Future<Uint8List> _buildPdf1(PdfPageFormat format) async {
    final pdf = pw.Document();

    final List<Map<String, dynamic>> data = [
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
      {"Item": "Item 1", "Qty": 2, "Rate": 50, "Amount": 100},
      {"Item": "Item 2", "Qty": 1, "Rate": 30, "Amount": 30},
      {"Item": "Item 3", "Qty": 3, "Rate": 20, "Amount": 60},
      {"Item": "Item 4", "Qty": 5, "Rate": 10, "Amount": 50},
    ];

    pdf.addPage(
      pw.Page(
        pageFormat: format,
        build: (context) => pw.Column(
          crossAxisAlignment: pw.CrossAxisAlignment.start,
          children: [
            pw.Text(
              "Sample Table List",
              style: pw.TextStyle(fontSize: 16, fontWeight: pw.FontWeight.bold),
              textAlign: pw.TextAlign.center,
            ),
            pw.SizedBox(height: 10),
            pw.Table(
              border: pw.TableBorder.all(),
              columnWidths: {
                0: const pw.FlexColumnWidth(3),
                1: const pw.FlexColumnWidth(1),
                2: const pw.FlexColumnWidth(1),
                3: const pw.FlexColumnWidth(1),
              },
              children: [
                pw.TableRow(
                  decoration: const pw.BoxDecoration(color: PdfColors.grey300),
                  children: [
                    pw.Text("Item",
                        style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
                    pw.Text("Qty",
                        style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
                    pw.Text("Rate",
                        style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
                    pw.Text("Amount",
                        style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
                  ],
                ),
                ...data.map(
                  (item) => pw.TableRow(
                    children: [
                      pw.Text(item["Item"]),
                      pw.Text(item["Qty"].toString()),
                      pw.Text(item["Rate"].toString()),
                      pw.Text(item["Amount"].toString()),
                    ],
                  ),
                ),
              ],
            ),
            pw.SizedBox(height: 20),
            pw.Text(
              'Thank You, Visit Again!',
              style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold),
              textAlign: pw.TextAlign.center,
            ),
          ],
        ),
      ),
    );
    return pdf.save();
  }
}

Expected behavior

select the roll80 in the pdf preview it preview correctly, when print clicked then in the next page it shows like letter format,
click share and select print it shows the content in a smaller size aligned to left

Screenshots

Screenshot_1736422614
Screenshot_1736422620
Screenshot_1736422629

Flutter Doctor

Desktop (please complete the following information):

  • iOS
  • [ 10,12] Android
  • Browser
  • Windows
  • Linux

Smartphone (please complete the following information):

  • Device: [pocof1,pixel 6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

@MohammedNiyasK MohammedNiyasK added bug Something isn't working needs triage labels Jan 9, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant