1. 急~急~~急~~~ 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();
2. 在ASP.NET中怎麼把網頁形式轉換為pdf格式
將htm轉換為pdf的任務,這是一個有很有用的功能塊,然而很遺憾,網上沒有現成可行(包括開源/免費、易用和可維護性的考慮)方案。既然沒有現成的解決方案就自己著手解決吧。 從htm生成pdf大概可以分兩步實現,第一步,解析htm,就是將htm源文件中那一對文本轉換為瀏覽器最終呈現給我們那種圖文並茂的結果。這是一個不可完成的任務,因為目前為止業界的軟體巨頭也沒有誰把htm解析做得很好的。對比ie、firefox等瀏覽器的顯示結果便可想而知。既然業界難題,我也就不去鑽牛角尖做技術攻關了,先跳過這步,考慮下一步的事情。 第二步,繪制pdf,這個簡單,網上有很多資料,有興趣的朋友可以研究pdf的文件格式,安裝二進制組裝pdf。我有興趣,然而沒有時間,我覺得軟體從業者時刻都應該關注最有價值的事情。軟體從業者要提高效率的第一法門便是重用,網上有一個叫itextsharp的東西是用來繪制pdf的,可以免費使用而且開源。 下載itextsharp,試著用itextsharp繪制htm看看效果,如您所料,繪制出的是htm的源代碼。因為第一步的事情我們還沒有解決,下面來解決第一步的事情。 記得很久以前見過一個.net寫的網頁snap工具,大概思路是利用webbrowser的DrawToBitmap方法將ie的顯示結果輸出到Sytem.Drawing.Bitmap對象。大概代碼如下: //WebBrowser wb=null; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h); wb.DrawToBitmap(bmp, new System.Drawing.Rectangle(0,0, w, h));ok,htm可以解析了,現在重組剛才的代碼,思路如下: 使用webbrowser將htm解析並轉換為圖片,使用itextsharp將剛才的圖片繪製成pdf。 有用是給公司開發的功能,暫時不便公開源碼,提供我編譯後的工具供下載使用,您也可以根據上面的思路定製: 使用方法, 1.將單個url轉換為pdf:PageToPDF.exe "http://www.g.cn/" "google.jpg" 2.將多個url轉換為pdf:pagetopdf.exe task.txt "C:\pdfdir\" task.txt是任務里表,裡面提供多行url,每個url以#文件名為後綴,如:http://www..com/#b表示將http://www..com/轉換為pdf文件名為b(擴展名系統自己會追加) 在asp.net環境下使用 將pagetopdf上傳至網站中,設定好目錄許可權,示例代碼: Code public static bool CreatePPDF(string url,string path) { try { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) return false; Process p = new Process(); string str = System.Web.HttpContext.Current.Server.MapPath("~/afafafasf/PageToPDF.exe "); if (!System.IO.File.Exists(str)) return false; p.StartInfo.FileName = str; p.StartInfo.Arguments = " \"" + url + "\" " + path; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); System.Threading.Thread.Sleep(500); return true; } catch(Exception ex) { Sys.Log.error("Pdf create err.",ex); } return false; } 特性 在使用任務形式工作時,系統會啟動多個進程,即任務管理器中會有多個pagetopdf.exe的進程,這是系統調度程序自己啟動的,為了加個任務處理速度。進程數由調度程序自己控制,最多不會超過十個。
記得採納啊
3. .net列印pdf文件
方法一(web):window.print()
print()方法是瀏覽器列印功能的一種程序調用。print方法用於列印當前窗口的內容。
列印當前頁:
function printPage(){
window.print();
}
列印局部頁面:
前端頁面:<iframe style="width:100%;height:100%;" id="fileId" src="文件路徑">
</iframe>
<input type="button" name="print" id="print" value="列印" />
js:$("#print").click(function () {
var iframe = document.getElementById("fileId");
iframe.contentWindow.print();
});
方法二:調用系統API(得保證本地裝有相關的軟體)
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
FileName = filePath,//文件路徑
Verb = "print",
Arguments = @"/p /h \" + filePath + "\"\"" + pd.PrinterSettings.PrinterName + "\""
}
};
p.Start();
p.WaitForExit();
方法三:spire列印方式(收費)下面是簡單的使用例子
var pdf = new PdfDocument(filePath);
//設置列印機
pdf.PrintSettings.PrinterName = "Microsoft Print to PDF";
pdf.print();
方法四:安裝RawPrint
var printer = new Printer();
var file = File.Open(filePath, FileMode.Open);
byte[] array = new byte[file.Length];
file.Read(array, 0, array.Length);
printer.PrintRawStream(printerName, file, "列印機上顯示的任務名");
file.Close();
printer.PrintRawFile(printerName, fileFullPath, "列印機上顯示的任務名");
這個測試時虛擬列印機上正常,使用公司列印機時出現亂碼問題以及列印任務不停的問題
4. ASP.Net網站 Word轉pdf
1.使用iText導出PDF報表文件示例代碼
/**
* 導出PDF示例
* @author RainTion
* @param args
*/
publicstaticvoid main(String[] args) {
try {
Document document = new Document();
PdfWriter. getInstance(document, new FileOutputStream("F:\\test.pdf" ));
document.open();
document.add(new Paragraph( "pride in me!" ));
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
2.使用iText導出Word報表文件示例代碼
/**
* 導出Word示例
* @author RainTion
* @param args
*/
publicstaticvoid main(String[] args) {
try {
Document document = new Document(PageSize.A4);
RtfWriter2. getInstance(document, new FileOutputStream("F:\\test.doc" ));
document.open();
Paragraph title = new Paragraph("你好 地球人..." );
document.add(title);
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
5. 如何用.NET將DWG文件列印為PDF
pdf是掃描件,這個需要列印之後,掃描就是PDF文件了
6. .net實現excel2010轉成pdf
迅捷Excel轉換成pdf轉換器可將掃描文檔、圖像、文本照片和PDF文檔轉換為最通用的編輯格式 (DOC, XLS, PPT, HTML, PDF, ePub)
步驟一、 選擇轉換模式。excel轉pdf轉換軟體目前支持八大轉換模式,包括常見的excel轉pdf、excel轉pdf、PDF轉圖片等,點擊圖標勾選即可。
步驟二 、添加文件。點擊excel轉pdf轉換軟體的"添加文件"按鈕,將PDF文件添加到程序界面,軟體支持添加多個PDF文件。
步驟三 、輸出選項。excel轉pdf轉換器默認將轉換出來的文件保存在原文件夾內,或者自定義文件夾存儲路徑,最後點擊右側"開始轉換"即可順利完成轉換。
7. VB.NET 如何實現圖片轉PDF呢
你說的不太滿意是什麼意思,你莫非是希望圖片轉換成的pdf能被選中文字並復制粘貼?
8. vb.net 導出PDF
這是MSDN給出的一些答案:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/e79afbe3-70d8-4d4e-b651-a864b7e5e7d9/read-parse-a-pdf-file-using-vbnet
http://social.msdn.microsoft.com/Forums/vstudio/en-US/4ca6b6fc-b483-44b3-bce0-eeb2f159c879/how-to-read-a-pdf-text-in-vbnet
http://social.msdn.microsoft.com/Forums/vstudio/en-US/83dd4a50-ee2a-4a57-a71b-7d2f5e06d024/how-to-read-pdf-file-line-by-line-like-text-file
9. 怎樣把.net頁面中的表格轉換成pdf
安裝Adobe
Acrobat軟體,安裝成功後網頁有個「將網頁轉換為PDF」的插件功能,能將任何網頁及文檔轉成PDF文檔。