Implementing Custom Print Functionality in Android

PSPDFKit for Android provides built-in printing capabilities, but sometimes you may need to implement custom print functionality.

Triggering a Custom Print Flow

When you need to disable the default printing option and add a custom menu item for printing, you’ll need a way to initiate the printing process programmatically. Here’s how to do it:

  • PSPDFKit provides a public API for this purpose called DocumentPrintManager.

  • This API allows you to trigger the printing process with custom options.

Solution

To implement a custom print flow, follow these steps:

  1. Disable the default print option:

    pdfActivityConfiguration.disablePrinting()
  2. Add a custom menu item for printing in your UI.

  3. In your onOptionsItemSelected() method, or wherever you handle the custom print menu item click, use the following code:

    DocumentPrintManager.get().print(context, document, printOptions)
  • Where:

    • context is your Android context

    • document is your PdfDocument object

    • printOptions is an optional parameter to specify printing preferences

Important Notes

  • This API only shows the operating system (OS) printing UI, and not PSPDFKit’s own UI where you can choose if annotations should be printed.

  • You can still specify annotation printing preferences through the printOptions parameter.

  • Currently, there’s no exposed API to show PSPDFKit’s own print options dialog before switching to OS printing.

Conclusion

By using the DocumentPrintManager API, you can easily implement a custom print flow in your PSPDFKit-powered Android application. This approach gives you control over when and how the print dialog is triggered, while still leveraging PSPDFKit’s powerful printing capabilities.

Remember to test your implementation thoroughly to ensure it meets your specific requirements and provides a smooth user experience.

If you need further assistance or have questions about customizing the printing process, don’t hesitate to reach out to our Support team.