Home>

I want to convert the currently displayed HTML display to PDF.

Even if you try with PHP "fpdf", it seems that it is impossible unless you declare the specified text or cell in PHP.
(That would be troublesome and meaningless ...)

What kind of method is there to enable PDF conversion of the displayed contents with one click?
If it is possible on the Javascript side, there is no particular method, thank you.

● Official page of fpdf
http://www.fpdf.org/

======================= Addendum=========================

I succeeded in pdf with mpdf.
I want to convert the page generated by PHP to pdf, but in that case it is still executed
Cannot be displayed.
I want to convert the displayed page, is there any way?

You can save any page to PDF with a print function such as Google Chrome, but instead, do you want to provide users with a PDF download function as a function of the website you are making?

unarist2021-11-04 14:39:48

Thank you very much. It is not a print function, but a specification that you want to install an arbitrary button and convert it to pdf when that button is clicked. I think that you should specify the PHP file at the time of clicking, but I do not know the description of the PHP file or what to use with the PHP plug-in. Sorry for the lack of words.

Blue bird2021-11-04 14:39:48

Teratai l. This m /kue s chion s /19400

htb2021-11-04 14:39:48
  • Answer # 1

    Java can realize such conversion from Html to PDF, Spire.PDF for JavaIt is easily completed using such components.

    import com.spire.pdf.graphics.PdfMargins;
    import com.spire.pdf.htmlconverter.qt.HtmlConverter;
    import com.spire.pdf.htmlconverter.qt.Size;
    public class HtmltoPDF
    {
        public static void main (String [] args)
        {
            //define the HTML link and result PDF
            String url= "https://www.xxxxxxx.com/";
            String fileName= "Result.pdf";
            //Set the plugin path
            String pluginPath= "D: /Qt /plugins_32";
            HtmlConverter.setPluginPath (pluginPath);
            //convert HTML to PDF and set the size of the result PDF page
            HtmlConverter.convert (url, fileName, true, 1000000, new Size (600f, 900f), new PdfMargins (0));
        }
    }
    

    That's all the code you need, and other formats can be converted.

  • Answer # 2

    In Javascript, jsPDFIt seems that the library called supports PDF generation from DOM elements. However, when I look at the "HTML Renderer" in the sample on the site, it seems that CSS is not applied.

    You can also use html2canvas etc. to convert it to an image and then embed it in PDF.

    In the case of PHP, there are two methods, one is to use a library such as dompdf and tcpdf that is performed from HTML analysis, and the other is to use PhantomJS and wkhtmltopdf that use the rendering engine of the browser. In the latter case, it may be difficult to use a rental server etc. because it is necessary to install the program separately from PHP.