Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-1654

[PATCH] A PrintRenderer using Java Print Service API

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Resolution: Unresolved
    • 2.5
    • None
    • unqualified
    • None
    • Operating System: All
      Platform: All
    • 47093

    Description

      The attached PrintRenderer uses the Java Print Service API, introduced in Java 1.4.
      It allows to programmatically set print options, like the destination printer and media tray. I use it like this:

      // Construct a FopFactory
      FopFactory fopFactory = FopFactory.newInstance();
      FOUserAgent userAgent = fopFactory.newFOUserAgent();

      // Setup FOP print renderer
      PrintRenderer renderer = new PrintRenderer();
      renderer.setUserAgent(userAgent);
      userAgent.setRendererOverride(renderer);

      // Construct fop with desired output format
      Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, userAgent);
      ContentHandler handler = fop.getDefaultHandler();

      // lookup a printer
      PrintService service = PrintServiceLookup.lookupDefaultPrintService();
      DocPrintJob job = service.createPrintJob();
      PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
      // set print request attributes here, like the media tray

      // print
      job.print(renderer, attributes);

      If this PrintRenderer replaced the current one (hint, hint), I could skip the "Setup FOP print renderer" section.

      Attachments

        1. PrintRenderer.java
          3 kB
          Martin Voelkle

        Activity

          People

            Unassigned Unassigned
            marv Martin Voelkle
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: