Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marianne Larsen 22 posts 94 karma points
    Sep 07, 2015 @ 07:22
    Marianne Larsen
    0

    Best and most flexible PDF generator?

    I'm looking for the best and most flexible way to generate PDF from a website.

    From the website, i want to make it possible to generate a PDF from selections on a webpage and then print/send it to an email recipient.

    Are there any recommendations?

    Best Regards Marianne

  • Benas Brazdziunas 34 posts 156 karma points c-trib
    Oct 01, 2015 @ 14:14
    Benas Brazdziunas
    100

    We use wkhtmltopdf its fine for document generator. Code int our PDF template.

    @using Umbraco.Web
    @{
        Layout = null;
    string PDF_CONVERTER = Server.MapPath("/App_data/wkhtmltopdf/wkhtmltopdf.exe");
    
    var filename = Model.Content.UrlName + ".pdf";
    var path = Server.MapPath("/App_Data/wkhtmltopdf/pdfs/" + filename);
    var url = Request.Url.Scheme + "://" + Request.Url.Host + Model.Content.Url;
    // Create directory if needed
    var di = new DirectoryInfo(Path.GetDirectoryName(path));
    if (!di.Exists){ di.Create(); }
    
    // Connect to process
    var process = new System.Diagnostics.Process();
    process.StartInfo.FileName = PDF_CONVERTER;
    process.StartInfo.Arguments = string.Format("-T 7 -R 0 -B 40 -L 0 --page-width 1024px --dpi 600 --footer-html {2} --header-html {3} --page-width 992 --zoom 0.7 --no-stop-slow-scripts --disable-smart-shrinking cover {4} {0} {1}",
        url,
        path,
        Model.Content.Children.LastOrDefault(c=>c.DocumentTypeAlias == "DocumentHeaderFooter").UrlWithDomain(),
        Model.Content.Children.FirstOrDefault(c => c.DocumentTypeAlias == "DocumentHeaderFooter").UrlWithDomain(),
        Model.Content.Children.FirstOrDefault(c => c.DocumentTypeAlias == "DocumentCover").UrlWithDomain());
    process.Start();
    process.WaitForExit();
    
    Response.Clear();
    Response.AddHeader("content-disposition", "attachment; filename=" + filename);
    Response.ContentType = "application/pdf";
    Response.WriteFile(path);
    Response.Flush();
    Response.End();
    }
    
  • Marianne Larsen 22 posts 94 karma points
    Oct 05, 2015 @ 07:58
    Marianne Larsen
    0

    Thanks :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies