使用方法:
1.找到exe所在的路径url,解决方案名称为ImagesToPDF
在命令行中输入 url/ImagesToPDF.exe 导出PDF路径 图片1路径 图片2路径 ...
右键点击【项目】--》【属性】,弹出配置界面。选择【调试】--》【启动选项】--》【命令行参数】文本框中输入任意的参数,多个之间用空格分隔,按F5可直接看到结果
3.通过在程序的快捷方式中增加参数【推荐】
程序编译后,创建快捷方式程序。右键点击【ImagesToPDF.exe】--》【创建快捷方式】
右键点击【ImagesToPDF.exe 快捷方式】--》【属性】--》【快捷方式】--》【目标】,在文本框的最后输入任意参数,多个之间用空格分开
双击双击【ImagesToPDF.exe 快捷方式】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | static void Main( string [] args) { var outputurl = "" ; List< string > filePath = new List< string >(); if (args != null ) { Console.WriteLine( "参数长度" + args.Length); for ( int i = 0; i < args.Length; i++) { Console.Write( "第" + (i + 1) + "个参数是" ); Console.WriteLine(args[i]); if (i == 0) { string dire = args[i].Substring(0, args[i].LastIndexOf( "/" )); if (!Directory.Exists(dire)) { Directory.CreateDirectory(dire); } outputurl = args[i]; } else { filePath.Add(args[i]); } } } Console.ReadLine(); ToPDF(outputurl, filePath); } public static void ToPDF( string outputurl, List< string > filePath) { float [] xy = new float [2]; using (FileStream fs = new FileStream(filePath[0], FileMode.Open)) { System.Drawing.Image img = System.Drawing.Image.FromStream(fs); int w = img.Width; int h = img.Height; float w_dpi = img.HorizontalResolution; float h_dpi = img.VerticalResolution; xy[0] = ( float )(w * 25.4 / w_dpi * 2.83462677); xy[1] = ( float )(h * 25.4 / h_dpi * 2.83462677); } iTextSharp.text.Document document = new iTextSharp.text.Document( new iTextSharp.text.Rectangle(0, 0, xy[0], xy[1]), 0, 0, 0, 0); using (FileStream fs = new FileStream(outputurl, FileMode.Create)) { iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs); document.Open(); for ( int i = 0; i < filePath.Count; i++) { string imgPath = filePath[i]; using (FileStream imgFs = new FileStream(imgPath, FileMode.Open)) { iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgFs); img.ScaleAbsolute(xy[0], xy[1]); document.NewPage(); document.Add(img); imgFs.Close(); } } document.Dispose(); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)