Class NetworkSave

  • All Implemented Interfaces:
    DocumentPanelListener

    public class NetworkSave
    extends ViewerWidget
    implements DocumentPanelListener
    Create a button that will submit a PDF to a network URL. By default this feature is disabled - to enable it in an application,: you would add a new NetworkSave instance to the list of features passed in to the PDFViewer(java.util.Collection) constructor:
     ArrayList f = new ArrayList(ViewerFeature.getAllEnabledFeatures());
     NetworkSave save = new NetworkSave();
     save.setURL(new URL("http://localhost:8080/savepdf"));
     f.add(save);
     PDFViewer viewer = new PDFViewer(f);
     

    The URL attribute must be set on this feature before it can be used, either via the url initialization parameter or by calling the setURL(java.net.URL) method. It may contain a Base64-encoded username and password if necessary. The PDF will be rendered and sent directly to the URL connection's OutputStream. If the filename of the PDF is known, it will be submitted via the X-BFOPDF-File HTTP header - if more customization is required you can override the setAdditionalHeaders(java.net.URLConnection, org.faceless.pdf2.viewer2.DocumentPanel) method to modify the PDF and/or the connection headers before the PDF is submitted

    The following initialization parameters can be specified to configure this feature.
    urlThe URL to submit the save action to
    premessageThe message to display to the user before submission. If not null, the value will be displayed to the user with an "OK" or "Cancel" prompt before saving
    postmessageThe message to display to the user after submission. If not null, the value will be displayed to the user with an "OK" prompt after saving. The special value "response" can be used to display the HMTL response from the server
    fieldnameIf set, the PDF will be sent as if submitted via an HTTP Form - "fieldname" would be the name of the field. It null, the PDF will simply be written as the body of the HTTP content (since 2.11.19).
    filenameThe filename parameter to send in the submission (defaults to the PDF filename)
    timeoutThe connection timeout value in milliseconds (0 is infinite)
    readTimeoutThe read timeout value in milliseconds (0 is infinite)
    The name of this feature is NetworkSave

    This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.

    Since:
    2.11.17
    • Constructor Detail

      • NetworkSave

        public NetworkSave()
    • Method Detail

      • createActionListener

        protected ActionListener createActionListener()
        Description copied from class: ViewerWidget
        Return an ActionListener that will be called when this Widget is activated. Subclasses will typically not need to override this method except in special cases.
        Overrides:
        createActionListener in class ViewerWidget
        Returns:
        ActionListener the ActionListener to be notified when an event fires
        See Also:
        Quit.createActionListener()
      • setTimeout

        public void setTimeout​(int timeout)
        Set the timeout in milliseconds that should be used when connecting to a URL. A value of 0 (the default) means infinite.
        Parameters:
        timeout - the number of milliseconds to wait while connecting to a URL before timing out
      • setReadTimeout

        public void setReadTimeout​(int timeout)
        Set the timeout in milliseconds that should be used when reading from a URL. A value of 0 (the default) means infinite.
        Parameters:
        timeout - the number of milliseconds to wait while reading from a URL before timing out
      • setURL

        public void setURL​(URL url)
        Set the URL the PDF will be submitted to. This must be set for this feature to work.
        Parameters:
        url - the URL
      • setPreMessage

        public void setPreMessage​(String message)
        Set the message which will be displayed to the user before saving as a prompt - the save will only continue if the user selects "OK". Setting this value to null (the default) means no prompt will be given before saving.
        Parameters:
        message - the message to display
      • setPostMessage

        public void setPostMessage​(String message)
        Set the message which will be displayed to the user after a successful save. If this is null (the default) no message will be displayed. The special value "response" can be used to display the HTML response from the server.
        Parameters:
        message - the message to display
      • setFieldName

        public void setFieldName​(String fieldname)
        Set the field name which the PDF will be submitted as (as if it were sent from an HTML Form). If null (the default), the PDF will simply be written to the HTTP stream.
        Parameters:
        fieldname - the field name
        Since:
        2.11.19
      • setFileName

        public void setFileName​(String filename)
        Set the file name which the PDF will be submitted as (as if it were sent from an HTML Form). If null (the default), the filename of the PDF will be used.
        Parameters:
        filename - the file name
        Since:
        2.11.19
      • save

        public void save​(ViewerEvent event,
                         Exporter exporter,
                         URL url)
        Save the Document to the network
        Parameters:
        event - the ViewerEvent that launched this action
        exporter - the Exporter to use, or null to default to a PDFExporter
        url - the URL to submit the PDF to