How to use external css in tcpdf pdf generation

后端 未结 2 965
梦如初夏
梦如初夏 2021-02-13 10:35

I am trying to create a pdf of a web page with tcpdf. But it\'s not working. The page is a php with external css and javascript files.

Can anyone help me with this.

2条回答
  •  野的像风
    2021-02-13 11:09

    public byte[] GetPDF(string pHTML)
            {
                byte[] bPDF = null;
    
                MemoryStream ms = new MemoryStream();
                TextReader txtReader = new StringReader(pHTML);
    
                // 1: create object of a itextsharp document class
                Document doc = new Document(PageSize.A4, 25, 25, 25, 25);
    
                // 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file
                PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);
    
                // 3: we create a worker parse the document
                HTMLWorker htmlWorker = new HTMLWorker(doc);
    
                // 4: we open document and start the worker on the document
                doc.Open();
                htmlWorker.StartDocument();
    
                // 5: parse the html into the document
                htmlWorker.Parse(txtReader);
    
                // 6: close the document and the worker
                htmlWorker.EndDocument();
                htmlWorker.Close();
                doc.Close();
    
                bPDF = ms.ToArray();
    
                return bPDF;
            }
    

提交回复
热议问题