locked
Creating PDF in a desktop soultion works but not from the Web client! RRS feed

  • Question

  • Dear All,

    I have the follwoing code which work 100% on the desktop client (I am using Light switch 2010 version):

    using System;
    using System.Linq;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Framework.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;
    using LightSwitchApplication.HRS;
    using System.Runtime.InteropServices.Automation;
    using System.Windows.Browser;

    namespace LightSwitchApplication
    {
        public partial class Part_2_CustomerItemDetail
        {
           

            partial void PDF_Execute()
            {
                
                vw_CustLedgerEntryItem1 entryItem = this.vw_CustLedgerEntry.SelectedItem;
                InvGetPDF2RequestBody reqBody = new InvGetPDF2RequestBody(
                    entryItem.Document_No_
                , Int16.Parse(entryItem.Report_Type)
                , "DynNavHRS"
                , @"\\p-nav-as-1\NavUserTemp\tma04"
                , false
                , false
                , "DE"
                , false
                , ""
                , ""
                , entryItem.Company
                , 1
                , false);
                InvGetPDF2Request req = new InvGetPDF2Request(reqBody);
                HRSReportServiceSoapClient wsHRS = new HRSReportServiceSoapClient();
                wsHRS.InvGetPDF2Completed += new EventHandler<InvGetPDF2CompletedEventArgs>(wsHRS_InvGetPDF2Completed);
                wsHRS.InvGetPDF2Async(req);
            }
            static void wsHRS_InvGetPDF2Completed(object sender, InvGetPDF2CompletedEventArgs e)
            {
                if (System.IO.File.Exists(@e.Result.Body.InvGetPDF2Result.ToString()))
                {
                    if (AutomationFactory.IsAvailable)
                    {
                        dynamic app = AutomationFactory.CreateObject("Shell.Application");
                        app.Open(@e.Result.Body.InvGetPDF2Result.ToString());
                    }
                    else
                    {
                        Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke((Action)(() =>
                        {
                            HtmlPage.Window.Navigate(new Uri(@e.Result.Body.InvGetPDF2Result.ToString(), UriKind.Absolute), "_blank");
                        }));

                    }
                }
            }

    when I deploy my soultion on the web client and I press the button PDF it fires an Error :(

    can any one help?

    Thanks a lot,

    Zayed

    Monday, July 7, 2014 1:41 PM

Answers

All replies

  • Zayed,

    Remember that COM objects are not accesible from the web client. Tell us a bit more about what you are using to generate the PDF, post the error message(s) and please use the insert code block snippet so it makes it more readable.

    thanks.

    Monday, July 7, 2014 5:03 PM
  • using System;
    using System.Linq;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Framework.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;
    using LightSwitchApplication.HRS;
    using System.Runtime.InteropServices.Automation;
    using System.Windows.Browser;
    
    namespace LightSwitchApplication
    {
        public partial class Part_2_CustomerItemDetail
        {
           
    
            partial void PDF_Execute()
            {
                
                vw_CustLedgerEntryItem1 entryItem = this.vw_CustLedgerEntry.SelectedItem;
                InvGetPDF2RequestBody reqBody = new InvGetPDF2RequestBody(
                    entryItem.Document_No_
                , Int16.Parse(entryItem.Report_Type)
                , "DynNavHRS"
                , @"\\p-nav-as-1\NavUserTemp\tma04"
                , false
                , false
                , "DE"
                , false
                , ""
                , ""
                , entryItem.Company
                , 1
                , false);
                InvGetPDF2Request req = new InvGetPDF2Request(reqBody);
                HRSReportServiceSoapClient wsHRS = new HRSReportServiceSoapClient();
                wsHRS.InvGetPDF2Completed += new EventHandler<InvGetPDF2CompletedEventArgs>(wsHRS_InvGetPDF2Completed);
                wsHRS.InvGetPDF2Async(req);
            }
            static void wsHRS_InvGetPDF2Completed(object sender, InvGetPDF2CompletedEventArgs e)
            {
                if (System.IO.File.Exists(@e.Result.Body.InvGetPDF2Result.ToString()))
                {
                    if (AutomationFactory.IsAvailable)
                    {
                        dynamic app = AutomationFactory.CreateObject("Shell.Application");
                        app.Open(@e.Result.Body.InvGetPDF2Result.ToString());
                    }
                    else
                    {
                        Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke((Action)(() =>
                        {
                            HtmlPage.Window.Navigate(new Uri(@e.Result.Body.InvGetPDF2Result.ToString(), UriKind.Absolute), "_blank");
                        }));
    
                    }
                }
            }

    Error Message:

    Tuesday, July 8, 2014 6:50 AM
  • Have you already considered using another library which would not require interoperability with COM components, e.g. using iTextSharp or iTextPDF library which is also Web friendly?

    I must say, not yet tried in the context of LightSwitch, but in the context of Asp.NET web sites (even hosted in Azure) we had great results. Example here http://www.aspsnippets.com/Articles/Export-HTML-DIV-contents-to-PDF-using-iTextSharp-in-ASPNet.aspx or (older, using VS 2008 ) http://www.codedigest.com/Articles/ASPNET/344_Export_to_PDF_file_in_ASPNet-Gridview_to_PDF_ASPX_Page_Content_to_PDF.aspx

    Let us know if you give it a try,
    C:\>Marius

    • Marked as answer by Angie Xu Monday, July 21, 2014 7:42 AM
    Tuesday, July 8, 2014 1:23 PM