We have a list, which uses an InfoPath form for data entering and viewing. In here, we created a Print view, which is basic black text on white background, and read-only.
However, when trying to print this view, the rest of our SharePoint master page and branding is printed with it, and it doesn't look very professional. So we needed to create a printable version of this Print view.
Some suggestions online included using jQuery to remove everything BUT the InfoPath form, but this sounded like a messy way of doing things. Instead, I figured I could just create a new blank page in SharePoint Designer and grab the item ID from the URL.
My first attempt failed. I tried using a Query String Filter Web Part, but then realised that sending an ID to an InfoPath Web Part doesn't do what you'd think it would do. It doesn't magically open the item you're referencing with the ID, it simply changes the InfoPath form item ID. You could use this method for pre-populating an InfoPath form based on parameters in your query string, but not for actually loading an already-existing form.
I figured that you could instead use that ID to filter a List View of your list, and then send that single item to the InfoPath web part. This would also mean I wouldn't need the Filter Web Part, as a List View has its own Filter and Parameter settings. So, here's what I did.
- Using SharePoint Designer, create an ASPX page in your site called PrintForm.aspx.
- In the ASPX page, add an InfoPath form web part, and configure the web part to use the list you're trying to print items from. Configure this web part to use the correct Print view that you've already created in InfoPath Designer.
- Somewhere else on the page, add a Data View, and again configure to use the list you're trying to print items from. Configure this web part to be hidden or not visible (unless you want to see the list view as well).
- With the List View web part selected, add a Parameter. This will be a query string parameter with the name ID, and the Query String Variable of ID as well. (You can change this to ItemID or something else if you want)
- Next, add a Filter for the List View web part. This will get the Field Name ID to equal the parameter you just created, which will be displayed as [ID] or [ItemID] or whatever you chose in the previous step.
- Finally, Add a Connection from the List View to the InfoPath web part. You want to Send Row of Data To the InfoPath web part, using the Target Action "Get Form From".
- Save and check in the file as appropriate.
Now, if you try to access the URL of this page with an ID added to the end, you will get a nice, basic printable view of your data. You'll want the URL to look like this:
What you'll need to do then is add a Print button to the normal Read or Edit view of the InfoPath form, which will send the user to that URL above, with the current item ID after the ID= (in the example above, the item ID is 25).
Edit: added a setTimeout before printing, because it was printing a blank page, even though print preview was working correctly.