【C#】Spire將url頁面轉(zhuǎn)為PDF
當(dāng)前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
public static void SpireUrlToPDF(string url) { //創(chuàng)建PdfDocument對象 PdfDocument doc = new PdfDocument(); //創(chuàng)建PdfPageSettings對象 PdfPageSettings setting = new PdfPageSettings(); //設(shè)置頁面大小及邊距 setting.Size = new System.Drawing.SizeF(1010,1300); setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20); //創(chuàng)建PdfHtmlLayoutFormat對象 PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); //等待直至HTML內(nèi)容完全加載 htmlLayoutFormat.IsWaiting = true; //獲取URL地址 //string url = "http://www.e-iceblue.cn/"; //獲取HTML代碼 //string htmlCode = File.ReadAllText(@"C:\Users\Administrator\Desktop\sample.html"); //使用LoadfromHTML方法加載URL Thread thread = new Thread(() => { doc.LoadfromHTML(url, false, false, false, setting, htmlLayoutFormat); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); //保存并打開文檔 doc.SaveToFile("output.pdf"); System.Diagnostics.Process.Start("output.pdf"); } 該文章在 2023/5/15 12:24:22 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |