none
Convert PDF working in On premise and Not showing images/videos after move to Cloud ? 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 env. We used third party tool for help. 

    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)
                {
                }
            }


    Thursday, August 9, 2018 10:13 AM

All replies

  • Hi,

    The Images and Video files store in SharePoint Online?

    Did you get some errors from your code?

    If you want to convert HTML to PDF file in SharePoint Online, please try to use jsPDF plugin to achieve it.

    https://github.com/MrRio/jsPDF

    https://social.technet.microsoft.com/wiki/contents/articles/31695.sharepoint-2013-generating-a-pdf-document.aspx

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, August 10, 2018 7:33 AM
    Moderator
  • Hi,

    I downloaded the plugin. But No idea how to use this.

    Can you give me an idea how to add it to my Visualstudio. where i have to add this plugin.

    Provide step by step approach in Visual Studio Userconrol .ascx page please?


    Friday, August 10, 2018 7:45 AM
  • Hi,

    This plugin is a JavaScript Library, we can use it in client side.

    I suggest you provider more information about your basic requirement for further research.

    Do you want to create a SharePoint Add-in for SharePoint Online to convert HTML to PDF?

    Or do you want to convert HTML page from SharePoint Online to PDF?

    In SharePoint On-Premise, we can create farm solution and create a visual web part with a button to achieve it.

    For SharePoint Online, the farm solution will not works. We need create client solution to achieve it.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, August 10, 2018 8:00 AM
    Moderator
  • I need a PDF tool which works fine in Share point 2013 cloud environment. wkhtmltopdf.exe is having issues while download the web part content having images and videos are not loading properly. images are shown as one rectangle box with no image. 

    Please provide the .net code for sp2013 which work for all types to download.

    Monday, August 13, 2018 5:48 AM
  • Hi,

    For SharePoint Online, we can use CSOM C# code to download files.

    Code: https://code.msdn.microsoft.com/office/file-from-SharePoint-Online-cc418dba

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Tuesday, August 14, 2018 10:21 AM
    Moderator