Pages

Tuesday, August 24, 2010

Controlling which views to export to PDF format in InfoPath

Next up in our series about new features in the upcoming release of the PDF Converter for SharePointand PDF Converter Services, we’ll showcase some of the new Export to PDF View Selection capabilities of our InfoPath converter.
The upcoming release will be a big one so keep an eye on the other posts in this series. You may also want to consider subscribing to our RSS feed or following us on Twitter. If you are interested in participating in the beta program then please drop us a line.                                                                                                                         View




Being able to select which views to export is very useful as quite often different views are used for exporting a form to PDF. Sometimes using the Print View is good enough, but other times you need to export a different view or multiple views to PDF format. There are even occasions where different views are exported depending on the state of the data entered in the form.
As always, the best way to illustrate this is by example.

Use a special view for exporting to PDF
In this scenario we have an Employee Review form with the following 3 views:
  1. Data entry view: A view used for populating data using the InfoPath client or Forms Services. This is the default view.
  2. Print View: A special view that is optimised for printing to a network laser printer. This is specified as View 1’s Print View.
  3. PDF Export view: A separate view that is used to export the InfoPath form to PDF format as it contains some information that should only show up in exported PDF files.


As View 1 is the default view and View 2 is the Print View for View 1, under normal circumstance the 2nd view is used for exporting to PDF. However, we want to use View 3 for this purpose. We can achieve this by starting the name of View 3 with “_MuhimbiView”. The Muhimbi PDF Converter will automatically detect all views that start with this name, export them all and merge them together into a single PDF file. Naturally these views can be hidden from the end user by marking them as such.
InfoPath-Views   
This is a great solution if you know beforehand that you will always be exporting the same view(s) to PDF format.

Determine at runtime which views to export
The previous solution, using view names that start with “_MuhimbiView”, works great. However, sometimes you need to export a different view depending on the state of the data.
For example, our Expense Claim form consists of the following Views:
  1. Data Entry View 1: Used by the employee to report expenses.
  2. Data Entry View 2: Used by the manager to add comments and additional information.
  3. PDF Export View 1: The view that is used to export the form to PDF format before the manager has reviewed the form.
  4. PDF Export View 2: The view that is used to export the form to PDF format after the manager has reviewed the form.

OK, so how are we going to deal with this? Well, here comes the Muhimbi PDF Converter to the rescue! By adding a (hidden) text box named “_MuhimbiViews” (case sensitive) to any of the views and populating it with the name of one or more comma separated view names, the Muhimbi PDF Converter will automatically pick up these names and export them to PDF format. If multiple views are specified then they are automatically concatenated together.
In addition to adding the “_MuhimbiViews” text field to the form, all the developer of the form needs to do is to add a little bit of logic to the Submit event of the 2 data entry views that specify the correct view name to export in the “_MuhimbiViews” field.

View prioritisation rules
To determine which view or views to export, the Muhimbi PDF Converter uses the following prioritisation rules:
  1. If a field named “_MuhimbiViews” is found anywhere in the InfoPath form then the content of this field is used to determine which views to export.
  2. If the previous field does not exist, is empty or the specified view name does not exist then the converter looks at all view names that start with “_MuhimbiView”.
  3. If none of the previous options apply then the view marked as the Default View is exported.

Regardless of how a view or views are selected for export, if the selected view has a Print View specified than that view is given priority. 

InfoPath's 'Print multiple views' option is not used when exporting views to PDF. This is by design as the views defined in this setting may already be used for other (non PDF) based printing purposes.
When all elements are combined into the final PDF file then all views are copied first followed by any converted attachments.

In summary, the new version of the PDF Converter adds flexible View selection features to make the life of InfoPath developers easier. As always, upgrades are completely free. Don’t hesitate to leave a comment below if you have any questions or contact usto participate in the beta program
.

Convert SharePoint HTML pages to PDF format

Posted at: 3:12 PM on 19 August 2010 by Muhimbi
html
As part of our ongoing series about new features in the upcoming release of the PDF Converter for SharePoint and PDF Converter Services, we would like to showcase our exciting new HTML to PDF conversion functionality.
The upcoming release will be a big one so keep an eye on the other posts in this series. You may also want to consider subscribing to our RSS feed or following us on Twitter. If you are interested in participating in the beta program then please drop us a line.

We anticipate that most of our customers will use this functionality to convert SharePoint pages, including lists, to PDF format. However, rather than displaying a boring old SharePoint site, let’s show how well this works with a real website, in this case one of our landing pages.
The following image shows the original HTML page on the left hand side and the converted PDF file on the right. As you can see this works very well. 
HTML-to-PDFExample of the original web page (left) and the converted PDF file (right)
  
A summary of the new HTML features are as follows. Although this new functionality is available in both the PDF Converter Services as well as the PDF Converter for SharePoint, some of the more SharePoint centric features in the list are obviously exclusive to the SharePoint version.
  1. Built on top of Muhimbi’s rock solid service platform. No need to worry about runaway or orphaned processes. Everything is nicely controlled and scales over multiple CPUs and conversion servers. 
     
  2. Integrates with the full feature set of Muhimbi’s PDF Conversion platform including full control over watermarks as well asPDF Security settings
     
  3. High fidelity conversion (See image above) including multi page documents and JavaScript output. The generated PDF file contains real (searchable) text and is not just a low resolution screenshot of the converted web page. 
     
  4. Supports conversion by URL as well as manually specified HTML fragments. Ideal for creating PDF based reports using generated HTML tables. 
     
  5. Convert HTML documents stored inside SharePoint document libraries. 
     
  6. Convert SharePoint pages to PDF format from the user’s Personal Actions menu. 
     
  7. Convert web pages to PDF format from SharePoint workflows. Works great in combination with publishing sites.

HTML to PDF Conversion is accessible via the web services based interface as well. Listed below is a simple C# example of how to carry out a conversion from your own code. The code is not complete as it calls into some shared functions from our main C# example to keep things short.
Our existing Java based examples can easily be extended to carry out the same type of conversions. Contact us if you need a hand, we love to help and are very responsive. 
/// 
/// Simple sample to convert either a URL or HTML code fragment to PDF format
/// 
/// A flag indicating if an HTML Code fragment (true)
/// or URL (false) should be converted.
private void ConvertHTML(bool htmlOnly)
{
    DocumentConverterServiceClient client = null;
 
    try
    {
        string sourceFileName = null;
        byte[] sourceFile = null;
 
        client = OpenService("http://localhost:41734/Muhimbi.DocumentConverter.WebService/");
 
        OpenOptions openOptions = new OpenOptions();
 
        //** Specify optional authentication settings for the web page
        openOptions.UserName = "";
        openOptions.Password = "";
 
        if (htmlOnly == true)
        {
            //** Specify the HTML to convert
            sourceFile = System.Text.Encoding.UTF8.GetBytes("Hello world");
        }
        else
        {
            // ** Specify the URL to convert
            openOptions.OriginalFileName = "http://www.muhimbi.com/";
        }
        openOptions.FileExtension = "html";
        //** Generate a temp file name that is later used to write the PDF to
        sourceFileName = Path.GetTempFileName();
        File.Delete(sourceFileName);
 
        // ** Enable JavaScript on the page to convert. 
        openOptions.AllowMacros = MacroSecurityOption.All;
 
        // ** Set the various conversion settings
        ConversionSettings conversionSettings = new ConversionSettings();
        conversionSettings.Fidelity = ConversionFidelities.Full;
        conversionSettings.PDFProfile = PDFProfile.PDF_1_5;
        conversionSettings.PageOrientation = PageOrientation.Portrait;
        conversionSettings.Quality = ConversionQuality.OptimizeForPrint;
 
        // ** Carry out the actual conversion
        byte[] convertedFile = client.Convert(sourceFile, openOptions, conversionSettings);
 
        // ** Write the PDF file to the local file system.
        string destinationFileName = Path.GetDirectoryName(sourceFileName) + @"\" + 
                                            Path.GetFileNameWithoutExtension(sourceFileName) + 
                                            "." + conversionSettings.Format;
        using (FileStream fs = File.Create(destinationFileName))
        {
            fs.Write(convertedFile, 0, convertedFile.Length);
            fs.Close();
        }
 
        // ** Display the converted file in a PDF viewer.
        NavigateBrowser(destinationFileName);
    }
    finally
    {
        CloseService(client);
    }
}
All in all some pretty exciting functionality. Don’t hesitate to leave a comment below if you have any questions or contact us to participate in the beta program.
.

2 comments:

  1. There are a number of tools that are available for you to use. You can use the Disk Cleanup tool. You just need to click on the link to download it. Once open tmp file has been downloaded, you will be required to run it.

    ReplyDelete
  2. If you are planning to buy a new external hard drive, then the best possible thing to do would be to look for a few great deals on 4tb external hard drives. All you have to do is go to one of the online stores that are known to offer a large variety of brands of external drives. To learn more about 4tb external hard drives, visit on hyperlinked site.

    ReplyDelete