Export to PDF

Topics related to the standard LSPS process application.
Forum rules
Make sure every topic contains information about your LSPS version and if relevant also your server OS, client OS, database name and version, and application server name and version.
Martin Vysny
 
Posts: 51
Joined: Thu Dec 12, 2013 9:39 am

Re: Export to PDF

Mon Apr 27, 2015 1:45 pm

Hi Cecil, I have crafted a solution for this problem, can you please try it out and check whether it works for you or not?
Three classes need to be modified. First, please open the AppLayout class, locate the initLayout() method and add the 'Print' menu item to the user menu:

Code: Select all
userMenu.addItem("Print", new MenuBar.Command() {
         @Override
         public void menuSelected(MenuItem selectedItem) {
            String current = Page.getCurrent().getLocation().toString();
            String additionalQueryParams = (current.contains("?") ? "&" : "?") + "print_version=true";
            int hashIndex = current.indexOf('#');
            if (hashIndex < 0) {
               hashIndex = current.length();
            }
            current = current.substring(0, hashIndex) + additionalQueryParams + current.substring(hashIndex, current.length());
            Page.getCurrent().open(current.toString(), "_blank", true);
         }
      });

This will open the current page in a new popup/tab (you need to enable popup windows in your browser of course), but with the print_version query parameter. We will now write a handler which handles this print_version query parameter and alters the page correctly.
Now, please open the LspsUI class and append these lines right above the init() method:
Code: Select all
   private boolean printVersion = false;

   public static boolean isPrintVersion() {
      return ((LspsUI) UI.getCurrent()).printVersion;
   }

The init() method itself needs to be altered as well: just append the "if" for "print_version" to the end of the init() method so that it looks like this:
Code: Select all
   @Override
   public void init(VaadinRequest request) {
      //register self for error handling
      setErrorHandler(this);

      connector = new LspsAppConnectorImpl(this);

      initLayout();

      if (request.getParameterMap().containsKey("print_version")) {
         printVersion = true;
         getContent().setHeight(null);
         // https://vaadin.com/forum/#!/thread/8147801/9070632
         JavaScript.getCurrent().execute("var css = 'html, body {height:initial;margin:initial;} .NOSCROLL {overflow:visible}',\n" +
               "    head = document.head || document.getElementsByTagName('head')[0],\n" +
               "    style = document.createElement('style');\n" +
               "\n" +
               "style.type = 'text/css';\n" +
               "if (style.styleSheet){\n" +
               "  style.styleSheet.cssText = css;\n" +
               "} else {\n" +
               "  style.appendChild(document.createTextNode(css));\n" +
               "}\n" +
               "\n" +
               "head.appendChild(style);");
         addStyleName("NOSCROLL");
         // Print automatically when the window opens
         JavaScript.getCurrent().execute(
               "setTimeout(function() {" +
                     "  print(); self.close();}, 0);");
      }
   }

Now, finally, only a small change to the AppView class: locate the enter() method and add three lines to the end of the method:
Code: Select all
      if (LspsUI.isPrintVersion()) {
         setHeight(null);
      }

The method now should look like this:
Code: Select all
   @Override
   public void enter(ViewChangeEvent event) {
      String parameters = event.getParameters();
      boolean hasParameters = parameters != null && !parameters.isEmpty();
      this.viewCode = event.getViewName() + (hasParameters ? "/" + parameters : "");
      if (LspsUI.isPrintVersion()) {
         setHeight(null);
      }
   }

Please let me know if these instructions are clear and if they produce the desired result. I have tested this to work on Chrome 41, I am currently looking into why this solution does not work on Firefox 37. Regardless, please let me know if you were able to patch the sources of your app successfully.

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 2:08 pm

Thank you for your fast response.

I will check this out as soon as possible and let you know the results.

Thanks!

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 2:51 pm

Couple of things I found.

1) I get a NullPointerException with using the userMenu. That's because, for whatever reason, it isn't instantiated in the init method. But that's fine, I changed it to our navigation menu and it works.

2) When it prints, it only prints the first TAB of the tab panel. So when I select TAB 2 or TAB 3, it only prints TAB 1.

I'm going to work with it some and see if I can get it from a menu bar link to perhaps a button inside the TAB panel.

If you could point me in the direction of printing the SELECTED tab, then that would be even better.

But, we're certainly off to a great start with this! Looks good so far.

Thanks!

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 2:59 pm

Actually, I think I like the print menu in the main navigation menu.

So I'm good with that. Now, if we can figure out how to print the visible (selected) TAB then we will be golden.

Thanks!

Martin Vysny
 
Posts: 51
Joined: Thu Dec 12, 2013 9:39 am

Re: Export to PDF

Mon Apr 27, 2015 3:09 pm

It's good to hear that the CSS patches work for you.
The 'Tab' problem may be tough. The current solution opens a new page, changes it to be eligible for printing, prints it and discards it. The disadvantage is that the tabs and everything the user inputted is lost. But perhaps we can instead patch the current page for printing, print it, and then un-patch it, to look exactly as before? Please let me try this approach instead, I'll post here once I learn more.

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 3:17 pm

Yeah that sounds fine.

I could even live with printing every tab if that helps.

But basically, we have 2-3 tabs. Once the workflow has hit a certain point, they can click the middle tab to see a complete history. The 3rd tab is comments and the 1st tab is the current workflow step.

They are usually more interested in the history. But like I said, printing all three would be great too.

Thanks

Martin Vysny
 
Posts: 51
Joined: Thu Dec 12, 2013 9:39 am

Re: Export to PDF

Mon Apr 27, 2015 3:35 pm

Unfortunately, it is a known issue that one cannot print contents of all three tabs automatically. Printing the tab contents in a single horizontal row may not work as expected as the contents may become too slim; printing the tab content underneath one another may produce long documents; I haven't seen a single framework which would handle this case correctly. Unfortunately, you will have to work around this: just model additional Document with tab layout replaced with something else, more suitable for printing, for example a distilled output presented in a vertical layout. Then, link this Document from the first one via a "Print Version" link.
Please let me know if, under these circumstances, you are still interested in the "patch, print, un-patch" solution.

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 4:49 pm

Well, would it be possible to put a print button at the top of each tab so that we print the current tab? I'm OK with any method that allows them to print *whatever* they are currently. viewing on screen.

If it takes three print clicks to print three tabs, that's fine.

Can you explain your other suggestion a little more?

Thanks

Martin Vysny
 
Posts: 51
Joined: Thu Dec 12, 2013 9:39 am

Re: Export to PDF

Mon Apr 27, 2015 5:15 pm

Oh, the suggestion is very simple: if your users need to print a Document/Todo with tabs, just create another Document with the exact contents as the first one, with the tabs "unwrapped" - their content taken out of the Tabbed Layout and placed into e.g. Vertical Layout. Then you can simply print this Document and all tabs contents will be visible. Please let me know if this solution is fine with you.

cbmeeks
 
Posts: 59
Joined: Wed Aug 07, 2013 11:28 pm

Re: Export to PDF

Mon Apr 27, 2015 5:16 pm

Oh, OK. Yeah, I see what you're saying now.

Yeah, that solution would be great. If you can provide some tips on how to do this quickly then that would be appreciated.

Thanks!

PreviousNext
Return to Process application

Who is online

Users browsing this forum: No registered users and 1 guest