The following forum(s) have migrated to Microsoft Q&A (Preview): Azure Virtual Machines!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Convert PDF working in On premise and Not showing images/videos after move to Cloud using wkhtmltopdf.exe RRS feed

  • Question

  • I have provide my PDF button code. This code working fine in onpremise environment but not working properly for cloud environment.

    Content and styles are loading fine But Images and Video files are not downloading into PDF file in Cloud environment  We used third party tool called wkhtmltopdf

    Please help to resolve ?

     protected void btnConver_Click(object sender, EventArgs e)
            {
                try
                {
                    #region file download code
                    string wkhtmlToPdfExePath = HttpContext.Current.Server.MapPath(@"~\bin\wkhtmltopdf.exe");
                    string expPdfFname = Request.Url.Segments.Last().Contains('.') ? Request.Url.Segments.Last().Split('.')[0] + ".pdf" : ConfigurationManager.AppSettings["expPdfFname"];
                    // byte[] buffer = GetFileInBytes(divContent.Text.Replace("\"","'").Replace("src=\"/", "src=\"" + SPContext.Current.Web.Url + "/").Replace("src='/", "src='" + SPContext.Current.Web.Url + "/").Replace("src='../", "src='" + SPContext.Current.Web.Url + "/").Replace("src=\"../", "src=\"" + SPContext.Current.Web.Url + "/"), wkhtmlToPdfExePath);
                    //String pdfFile = divContent.Text.Replace("http:", "https:");
                    byte[] buffer = GetFileInBytes(divContent.Text, wkhtmlToPdfExePath);
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ContentType = "application/pdf";
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + expPdfFname);
                    HttpContext.Current.Response.Buffer = true;
                    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    HttpContext.Current.Response.BinaryWrite(buffer);
                    HttpContext.Current.Response.End();
                    HttpContext.Current.Response.Close();
                    #endregion
                }
                catch (Exception ex)
                {
                }
            }
    Friday, August 10, 2018 6:40 AM

All replies

  • Just to confirm, how exactly have you hosted the app?  When you create a Cloud Service, Azure assigns it to a subdomain of cloudapp.net. Whereas Azure WebApps, assigns a subdomain of azurewebsites.net. Could you confirm if you have hosted your app on Azure Cloud Service or Azure WebApps? Or have you hosted your app on an Azure VM?

     

    If this is on Azure App Service WebApps; just to highlight, all Azure Web Apps run in a secure environment called a sandbox. Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available.

     

    As mentioned in this document https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox - The following PDF generators are supported:

    • SQL Reporting framework: requires the site to run in Basic or higher (note that this currently does not work in Functions apps in Consumptions mode)
    • EVOPDF: See http://www.evopdf.com/azure-html-to-pdf-converter.aspx for vendor solution
    • Telerik reporting: requires the site to run in Basic or higher.
    • Rotativa / wkhtmltopdf: requires the site to run in Basic or higher.
    • NReco PdfGenerator (wkhtmltopdf): requires subscription plan Basic or higher.

     

    Disclaimer: This response contains a reference to a third-party World Wide Web site.

    Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    Friday, August 10, 2018 11:29 AM
    Moderator
  • Checking in to see if the above answer provided by Ajay Kumar .N helped to resolve your issue. If not, we need previously asked information to investigate this issue further.

    Sunday, August 12, 2018 6:08 AM
  • The above one is not help.

    Please provide the alternate. I have Deployed the Database into Azure server.Not having any apps.Its sp2013 on premise environmennt previously.Now moved to Azure only DB was in cloud.

    Please provide the steps what can i do?

    i tried with wkhtmltopdf as latest June version 12. But no luck.

    Monday, August 13, 2018 4:15 PM
  • To understand the issue better and for providing better guidance on your scenario/issue, I would like to know the following:

    Have you deployed a database server on an Azure VM? Could you provide more details on your database server? How exactly did you migrate it to Azure? Kindly do share any documentation that you referred to for the process and also share a screenshot of the issue after concealing private details.

     

    You may wish to know about Azure SQL (PaaS) Database vs SQL Server on Azure VMs (IaaS)

    Tuesday, August 14, 2018 10:30 AM
    Moderator
  • yes.I deployed DB server in Azure VM.Remaining all as it is same.

    No apps in my solution.

    All are usercontrols having .net code.

    We added wkhtmltopdf.exe in intepub bin and refer like below.

    string wkhtmlToPdfExePath = HttpContext.Current.Server.MapPath(@"~\bin\wkhtmltopdf.exe");

    I passed my total Div content to this exe.But images and vidos are not loaded into PDF.

    Wednesday, August 15, 2018 6:55 AM
  • Thanks for the update. For a specialized assistance on this issue you may post your query on ASP.NET Forums for receiving inputs from the right set of experts. Also, for IIS specific questions you could post them on IIS.NET Forums.

    Thursday, August 16, 2018 11:22 AM
    Moderator
  • @Sudhir, Just checking to see if you have contacted the IIS.NET forums and received help on this issue.

    Friday, August 31, 2018 7:19 PM
    Moderator