資源簡介
通過url 或者本地文件夾 將每個HTML 頁面轉換成相應PDF格式
小工具 bin下直接打開。
C# 源碼,VS直接運行。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Diagnostics;
using?System.Drawing;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?HtmlToPDF
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????string?pdf?=?System.Environment.CurrentDirectory?+?“\\wkhtmltopdf.exe“;
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????string?url?=?textBox1.Text;
????????????pdf?=?System.Environment.CurrentDirectory+“\\wkhtmltopdf.exe“;
????????????if?(textBox2?.Text.Trim().Length==0)
????????????{
????????????????MessageBox.Show(“PDF文件名不能為空“);
????????????????return;
????????????}
????????????string?filename?=?textBox2.Text.Trim();
????????????string?pdfpath?=?filename?+?“.pdf“;
????????????Process?p?=?System.Diagnostics.Process.Start(pdf?url?+?“?\““?+?pdfpath+“\““);
????????????p.WaitForExit();?
???????
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????string?v_OpenFolderPath?=?System.Environment.CurrentDirectory;
????????????System.Diagnostics.Process.Start(v_OpenFolderPath);
????????}
????????///?
????????///?批量生成目標文件夾
????????///?
????????string?PDFPath?=?““;
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????if?(textBox3.Text.Trim().Length?==?0)
????????????{
????????????????MessageBox.Show(“根目錄路徑不能為空“);
????????????????return;
????????????}
????????????if?(this.folderBrowserDialog1.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????if?(this.folderBrowserDialog1.SelectedPath.Trim()?!=?““)
????????????????????PDFPath?=?this.folderBrowserDialog1.SelectedPath.Trim();
????????????????folder?=?0;
????????????????file?=?0;
????????????????string?path?=?textBox3.Text;
????????????????FindFile(new?DirectoryInfo(path));
????????????????MessageBox.Show(“文件夾“?+?folder?+?“個,HTML文件“?+?file?+?“個“);
????????????}
????????}
????????public?int?folder?=?0;
????????public?int?file?=?0;
????????void?FindFile(DirectoryInfo?di)
????????{
????????????FileInfo[]?fis?=?di.GetFiles();
????????????for?(int?i?=?0;?i?????????????{????????????????
????????????????WriteLog(fis[i].FullName?“1“);
????????????}
????????????DirectoryInfo[]?dis?=?di.GetDirectories();
????????????for?(int?j?=?0;?j?????????????{?????????????
????????????????WriteLog(dis[j].FullName?“2“);
????????????????FindFile(dis[j]);
????????????}
????????}
????????public?void?WriteLog(string?msg?string?type)
????????{
????????????if?(type?==?“1“)
????????????{//文件
????????????????try
????????????????{???????????????????
????????????????????string?logFileName?=?Application.StartupPath.ToString()?+?“\\file.log“;
????????????????????if?(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????187??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\App.config
?????文件??????12800??2019-03-19?17:45??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.exe
?????文件????????187??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.exe.config
?????文件??????28160??2019-03-19?17:45??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.pdb
?????文件??????22984??2019-03-19?17:46??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.vshost.exe
?????文件????????187??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.vshost.exe.config
?????文件????????490??2012-06-06?02:06??HtmlToPDF\HtmlToPDF\bin\Debug\HtmlToPDF.vshost.exe.manifest
?????文件???29786112??2018-06-12?15:30??HtmlToPDF\HtmlToPDF\bin\Debug\wkhtmltoimage.exe
?????文件???29837312??2018-06-12?15:29??HtmlToPDF\HtmlToPDF\bin\Debug\wkhtmltopdf.exe
?????文件???29702144??2018-06-12?15:29??HtmlToPDF\HtmlToPDF\bin\Debug\wkhtmltox.dll
?????文件???????4774??2019-03-19?17:45??HtmlToPDF\HtmlToPDF\Form1.cs
?????文件???????7166??2019-03-19?17:38??HtmlToPDF\HtmlToPDF\Form1.Designer.cs
?????文件???????6025??2019-03-19?17:38??HtmlToPDF\HtmlToPDF\Form1.resx
?????文件???????3797??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\HtmlToPDF.csproj
?????文件????????863??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6975??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????717??2019-03-19?17:46??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.csproj.FileListAbsolute.txt
?????文件????????975??2019-03-19?17:38??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.csproj.GenerateResource.Cache
?????文件???????2209??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.csprojResolveAssemblyReference.cache
?????文件??????12800??2019-03-19?17:45??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.exe
?????文件????????180??2019-03-19?17:38??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.Form1.resources
?????文件??????28160??2019-03-19?17:45??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.pdb
?????文件????????180??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\HtmlToPDF.Properties.Resources.resources
?????文件??????????0??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件????????521??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\Program.cs
?????文件???????1356??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\Properties\AssemblyInfo.cs
?????文件???????2870??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\Properties\Resources.Designer.cs
?????文件???????5612??2019-03-19?15:42??HtmlToPDF\HtmlToPDF\Properties\Resources.resx
............此處省略15個文件信息
- 上一篇:ASP.NET MVC4 增刪改查
- 下一篇:C#實現BP神經網絡數字圖像識別源碼
評論
共有 條評論