導航:首頁 > 文檔加密 > net轉pdf

net轉pdf

發布時間:2025-08-05 13:45:10

『壹』 .NET中實現HTML生成圖片或pdf的幾種方式

在.NET中,實現HTML轉圖片或PDF的功能有多種途徑,但每種方案都有其優缺點。這里我們將探討WebBrowser、Wkhtmltox、PuppeteerSharp以及IronPdf這四種方法的對比。

首先,WebBrowser控制項是最基礎的實現方式,無需外部依賴,部署簡單。然而,它在非Winform項目中不穩定,數據量大時易卡死,且生成的圖片質量欠佳。清爽指數高,但功能有限。

Wkhtmltox是一個開源工具,通過命令行工具轉換,適合.NET項目,但部署前需要先安裝。它功能強大,但部署較為繁瑣,清爽指數略低,功能指數高。

PuppeteerSharp源於Puppeteer,是.NET版本的瀏覽器控制庫,功能極其強大,包括模擬用戶操作和指定設備。它依賴Chromium,安裝過程可能耗時,適合作為獨立服務。清爽指數一般,功能指數非常高。

IronPdf是一個商業軟體,提供免費試用版,功能全面,支持多種配置。通過DLL引用或NuGet安裝,但不如開源工具靈活。清爽指數和功能指數都較高。

最終,項目選擇了不用上述方案,而是通過正則解析HTML內容,手動繪圖生成圖片,因為需求簡單且頁面結構穩定。這種方式雖然簡單,但對HTML結構變化敏感。

總結,選擇哪種方法取決於具體需求、性能要求和部署環境,需根據實際場景權衡清爽度與功能性的折中。

『貳』 ASP.NET 網站,將word文檔轉換成PDF格式,然後上傳的系統所在的文件夾

你可以藉助Office的功能實現doc到pdf。這樣做需要需要office 2007 還有一個office2007的插件OfficeSaveAsPDFandXPS,然後藉助程序代碼就可以實現了!但是這樣做有個不好的地方就是必須安裝Office,可能會導致伺服器不是太安全!具體的實現代碼網上多的是比如:
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

...

// Create a new Microsoft Word application object
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

// C# doesn't have optional arguments so we'll need a mmy value
object oMissing = System.Reflection.Missing.Value;

// Get list of Word files in specified directory
DirectoryInfo dirInfo = new DirectoryInfo(@"\\server\folder");
FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");

word.Visible = false;
word.ScreenUpdating = false;

foreach (FileInfo wordFile in wordFiles)
{
// Cast as Object for word Open method
Object filename = (Object)wordFile.FullName;

// Use the mmy value as a placeholder for optional arguments
Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();

object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;

// Save document into PDF Format
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);

// Close the Word document, but leave the Word application open.
// doc has to be cast to type _Document so that it will find the
// correct Close method.
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}

// word has to be cast to type _Application so that it will find
// the correct Quit method.
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;

『叄』 如何用.NET將DWG文件列印為PDF

pdf是掃描件,這個需要列印之後,掃描就是PDF文件了

『肆』 急~急~~急~~~ ASP.NET 怎麼講圖片生成PDF文件,求代碼

我是藉助組件完成導出PDF文件的。在寫代碼之前,你要下載一個名為iTextSharp的組件,並將其引用到你的程序中。然後將生成的PDF文件通過流形式導出。

代碼如下:C#的

stringstrPDF_Nm=DateTime.Now.Year+"-"+DateTime.Now.Month+"-"+DateTime.Now.Day+"-"+DateTime.Now.Hour+"-"+DateTime.Now.Minute+".pdf";
iTextSharp.text.Documentdocument=newDocument();
iTextSharp.text.pdf.PdfWriterpdfwrite=PdfWriter.GetInstance(document,newFileStream(HttpContext.Current.Server.MapPath("~/img_Tmp/"+strPDF_Nm),FileMode.Create));
document.Open();
BaseFontbasefont=BaseFont.CreateFont(@"C:WindowsFontsSTKAITI.TTF",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
//解決PDF不能顯示中文的關鍵;創建一個中文楷體的字體對象
iTextSharp.text.Fontfont=newiTextSharp.text.Font(basefont,14);
iTextSharp.text.Tabletable=newiTextSharp.text.Table(4);
iTextSharp.text.Cellcells=newCell(newPhrase("不良報告",font));
cells.Colspan=4;
cells.HorizontalAlignment=1;
table.AddCell(cells);

iTextSharp.text.Imagejpg=iTextSharp.text.Image.GetInstance(Server.MapPath("~/img_Tmp/"+strSavePath));
document.Add(jpg);
document.Add(table);
document.Close();
pdfwrite.Close();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType="application/PDF";
HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath("~/img_Tmp/"+strPDF_Nm));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
閱讀全文

與net轉pdf相關的資料

熱點內容
教你一個解壓神器 瀏覽:399
壓垮程序員的bug 瀏覽:347
cad成面命令 瀏覽:913
php文件內容清空 瀏覽:867
伺服器管理為什麼要雲幫手 瀏覽:638
mac命令行粘貼 瀏覽:140
java17api中文下載 瀏覽:431
帶spi的單片機 瀏覽:94
node項目編譯桌面程序 瀏覽:319
163伺服器沒有響應什麼意思 瀏覽:964
怎麼看編譯器是32位還是64位 瀏覽:665
程序員試題百度雲 瀏覽:839
談論不同的解壓方法 瀏覽:572
如何透明加密 瀏覽:594
如何將電腦變成一台伺服器 瀏覽:251
秒學漢字app怎麼樣 瀏覽:517
中興r10路由器恢復出廠命令 瀏覽:1000
私密照放加密軟體 瀏覽:688
手機外接硬碟文件夾 瀏覽:419
手機應用放到文件夾消失 瀏覽:850