How to get the printview and the XSLT file for it? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to get the printview and the XSLT file for it?

Last post 01-12-2017 07:48 AM by Hilary Stoupa. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 01-02-2017 06:57 AM

    How to get the printview and the XSLT file for it?

    Hi!

    I'd like to be able to automate converting an InfoPath Filler form (with checkboxes) to PDF, without the user having to do anything. The forms are located in SharePoint Online library.

    As Export to pdf doesn't work with checkboxes, I thought about using the PrintDocument class (C#) and printing to the "Microsoft Print to PDF" printerdriver. The reason for using PrintDocument is to be able to set the filename in the code. So what I need to do is convert the xml to PrintDocument, but the problem lies with getting hold of the xsl file to get the transformation correct.

    So the question is: how can I get the view that is set as the print view, and the corresponding xsl for that view?

    Of course, I'll also listen to alternate ways to do this. :)

    Thanks! 

    Kind Regards,

    Hans Erik Storeide 

  • 01-02-2017 07:55 AM In reply to

    Re: How to get the printview and the XSLT file for it?

     So - to answer how to get the XSL - if you save the form as source files, you'll see the XSL in the files.

    However, what I did recently to get checkboxes and option buttons to display properly in my print view was I used chars from one of the Wingdings fonts with conditional formatting to show / hide based on what was selected. It was a bit of a pain to set up, and if I make changes to the form, the maintenance burden is a bit higher.... but it does work.

    I think you might also be able to leverage Word Automation in SharePoint for this.... InfoPath > Word > PDF. I know we have this webinar, which may get you on the path there. 

      

    Hilary Stoupa

  • 01-02-2017 11:31 PM In reply to

    Re: How to get the printview and the XSLT file for it?

    Thanks for your response, Hilary! I know how to get a peek at the source files manually, but I was hoping there's a way to do it programmatically, on the fly. I can get the filename for the view's xsl from the manifest, but I haven't been able to find a way to get to it with the Infopath object model... The Windings technique, as you say, sounds like a high maintenance solution. I have at least a dozen forms, so I'd like it to be a bit simpler to maintain. As this is SharePoint Online/Office 365, the Word Automation Services does no longer exist in SharePoint Online (https://technet.microsoft.com/en-us/library/sharepoint-online-content-service-description.aspx). I went a long way down that road before realizing this :( //Hans Erik
  • 01-03-2017 07:38 AM In reply to

    Re: How to get the printview and the XSLT file for it?

    Euw, sorry about the mislead on the Word Automation, and thanks for letting me know that it isn't supported in O365. You can use Microsoft.Deployment.Compression.Cab to extract the source files programmatically. I don't believe the InfoPath OM will give you the name of the print view - I think you'll have to extract the form's source files, then read the manifest to get info on the view you need, then grab the view from the extracted source files.
    Hilary Stoupa

  • 01-09-2017 11:39 PM In reply to

    Re: How to get the printview and the XSLT file for it?

     No, I meant I had already tried the Word technique earlier!

    I'll try using ..Compression.Cab... I saw an article on how to do that a while back.

    I'm now trying to produce the pdf with the combination of PdfSharp and HtmlRenderer. I'll let anyone interested know how it goes...

    //Hans Erik 

  • 01-10-2017 07:52 AM In reply to

    Re: How to get the printview and the XSLT file for it?

     Please do post back & let us know how that goes as far as proper rendering.

    Here's some sample code for using the compression lib (which I just snagged directly from another project, so solutionPath is a variable passed into the method, but this should give you the general idea):

    string tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
    DirectoryInfo dir = Directory.CreateDirectory(tempFolder);

    string newFileName = Path.GetRandomFileName() + ".cab";

    //copy to rename .xsn to .cab
    //will need cab location for repacking
    CabLocation = Path.Combine(tempFolder, newFileName);
    File.Copy(solutionPath, CabLocation);

    CabInfo cab = new CabInfo(CabLocation);

    //add folder to unpack to
    string destFolder = Path.Combine(tempFolder, Path.GetRandomFileName());
    Directory.CreateDirectory(destFolder);

    cab.Unpack(destFolder); 

    Hilary Stoupa

  • 01-11-2017 11:59 PM In reply to

    Re: How to get the printview and the XSLT file for it?

     Amazingly, I found a simple way to get a file out of the .xsn package!

    There's actually a function in the object model to do it:

    this.Template.OpenFileFromPackage(fileName) 

    There's a good example here:

     http://theressomethingaboutsharepoint.blogspot.no/2013/01/infopath-managed-code-c-to-convert-view.html

    When it comes to the problems I'm having with the rendering, I'll probably come full circle and try to make  this.CurrentView.Export(@"Export.pdf", ExportFormat.Pdf) work.

    It's unbelievable fickle though, with borders disappearing if the width or height is somehow off (or maybe it's the weather or cosmic radiation that's the culprit... :) ) If anyone have any guidelines on that, I'll be happy to read it...

    Hilary, could you show me how you did that conditional thing with replacing checkboxes with Wingdings? 

  • 01-12-2017 07:48 AM In reply to

    Re: How to get the printview and the XSLT file for it?

     Oh man - that hadn't even occurred to me. Usually when I'm extracting form files I need to modify them and pack them back up. :)

    So - for using wingdings (or other symbol font) - I've attached a simple sample. This approach combined with ExportFormat.Pdf has been working OK for my project, with the caveat that on different user machines (with different versions of IP) we have sometimes seen different results - mainly related to page sizing, margins, printable area, etc. So be sure to check that if you have different versions of InfoPath floating around. Save the file locally, right click & select design to open in design mode, then preview.

    Hilary Stoupa

Page 1 of 1 (8 items)
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.