Generating PDF via AJAX using mpdf

前端 未结 2 779
盖世英雄少女心
盖世英雄少女心 2020-12-21 10:42

I\'m using the mpdf library to generate a PDF of user-generated html. I can get the PDF to save to the server successfully, but I want the PDF to open in the browser for the

相关标签:
2条回答
  • 2020-12-21 11:12

    To indicate to the browser that the file should be viewed in the browser

    Content-Type: application/pdf
    Content-Disposition: inline; filename.pdf
    

    To have the file downloaded rather than viewed

    Content-Type: application/pdf
    Content-Disposition: attachment; filename.pdf
    
    <meta http-equiv="Content-Type" content="application/pdf; charset=utf-8">  
    

    Or using php

    header('Content-Type: application/pdf'); 
    header('Content-Description: inline; filename.pdf'); 
    
    0 讨论(0)
  • 2020-12-21 11:37

    I ended up not using AJAX and instead added a hidden input on the form and populated it using the following script:

    $('#save').click(function() {
    
        event.preventDefault();
    
        var shelf_clone = $('#shelf').clone();
        var shelf = shelf_clone.prop('outerHTML');
    
        $('#save_shelf input[name=shelf]').val(shelf);
    
        $('#save_shelf').submit();
    
    });
    
    0 讨论(0)
提交回复
热议问题