Git Product home page Git Product logo

Comments (4)

DavBfr avatar DavBfr commented on June 3, 2024

The layoutPdf function's documentation is:

/// Prints a Pdf document to a local printer using the platform UI
/// the Pdf document is re-built in a [LayoutCallback] each time the
/// user changes a setting like the page format or orientation.
///
/// returns a future with a bool set to true if the document is printed
/// and false if it is canceled.
/// throws an exception in case of error

so you would do:

import 'package:pdf/pdf.dart' as pw;
import 'package:printing/printing.dart';

final pdf = pw.Document();
// ... add content to the pdf ...

try {
final result = await Printing.layoutPdf(
  onLayout: (PdfPageFormat format) async {
    try {
      final result = await pdf.save();
      return result;
    } catch (e) {
      return null; // Handle error gracefully
    }
  });
    if (result) {
      // Handle successful print
      return PrintStatus.success;
    } else {
      // Handle print canceled
      return PrintStatus.canceled;
    }
} catch (e) {
// handle print error
      return PrintStatus.failure;
}

from dart_pdf.

alejantab avatar alejantab commented on June 3, 2024

The layoutPdf function's documentation is:

/// Prints a Pdf document to a local printer using the platform UI /// the Pdf document is re-built in a [LayoutCallback] each time the /// user changes a setting like the page format or orientation. /// /// returns a future with a bool set to true if the document is printed /// and false if it is canceled. /// throws an exception in case of error

so you would do:

import 'package:pdf/pdf.dart' as pw;
import 'package:printing/printing.dart';

final pdf = pw.Document();
// ... add content to the pdf ...

try {
final result = await Printing.layoutPdf(
  onLayout: (PdfPageFormat format) async {
    try {
      final result = await pdf.save();
      return result;
    } catch (e) {
      return null; // Handle error gracefully
    }
  });
    if (result) {
      // Handle successful print
      return PrintStatus.success;
    } else {
      // Handle print canceled
      return PrintStatus.canceled;
    }
} catch (e) {
// handle print error
      return PrintStatus.failure;
}

Hello.

This is working great on Android and iOS devices, but in Web platform It always return true, even without show the Preview Screen to print. So, with no users interaction to Print or Cancel I always get 'true' from the future.

from dart_pdf.

dcaldr avatar dcaldr commented on June 3, 2024

The layoutPdf function's documentation is:

/// Prints a Pdf document to a local printer using the platform UI /// the Pdf document is re-built in a [LayoutCallback] each time the /// user changes a setting like the page format or orientation. /// /// returns a future with a bool set to true if the document is printed /// and false if it is canceled. /// throws an exception in case of error

so you would do:

import 'package:pdf/pdf.dart' as pw;
import 'package:printing/printing.dart';

final pdf = pw.Document();
// ... add content to the pdf ...

try {
final result = await Printing.layoutPdf(
  onLayout: (PdfPageFormat format) async {
    try {
      final result = await pdf.save();
      return result;
    } catch (e) {
      return null; // Handle error gracefully
    }
  });
    if (result) {
      // Handle successful print
      return PrintStatus.success;
    } else {
      // Handle print canceled
      return PrintStatus.canceled;
    }
} catch (e) {
// handle print error
      return PrintStatus.failure;
}

Hello.

This is working great on Android and iOS devices, but in Web platform It always return true, even without show the Preview Screen to print. So, with no users interaction to Print or Cancel I always get 'true' from the future.

I think that always true is happening in windows as well. Even if you don't finish the dialog, it returns true

from dart_pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.