当前位置: 首页 > news >正文

静态网页模板简约哈尔滨seo网络优化招聘

静态网页模板简约,哈尔滨seo网络优化招聘,杭州建设信息港,微信公众号和小程序开发需要涉及最近用到pdf合成,发现各种软件均收费啊,这个技术非常简单,别人写好的库一大把,这里用到了PDFsharp,项目地址Home of PDFsharp and MigraDoc Foundation 软件下载地址 https://download.csdn.net/download/g313105910…

最近用到pdf合成,发现各种软件均收费啊,这个技术非常简单,别人写好的库一大把,这里用到了PDFsharp,项目地址Home of PDFsharp and MigraDoc Foundation

软件下载地址

https://download.csdn.net/download/g313105910/88014569

源码下载地址

https://download.csdn.net/download/g313105910/88014573

废话不多说,上WPF代码

<Window x:Class="mergePDF.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:mergePDF"mc:Ignorable="d"Title="PDF合成器,有顺序要求请用数字给文件命名,从小到大排序" Height="450" Width="800"><Grid><Grid.RowDefinitions><RowDefinition Height="10*"/><RowDefinition Height="33*"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition/></Grid.ColumnDefinitions><Button Content="合成" HorizontalAlignment="Left" Margin="737,0,0,0" VerticalAlignment="Center" Click="ButtonStart_Click" Height="19" Width="28"/><Button Content="选择目录" HorizontalAlignment="Left" Margin="675,0,0,0" VerticalAlignment="Center" Click="ButtonUrl_Click" Height="19" Width="52"/><TextBox x:Name="Url_Text" HorizontalAlignment="Left" Margin="60,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Center" Width="600" Height="17"/><Label Content="Url:" HorizontalAlignment="Left" Margin="25,0,0,0" VerticalAlignment="Center"/><TextBox x:Name="Info_Text" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"  Text="" Grid.Row="1"/></Grid>
</Window>
using FolderBrowserEx;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;namespace mergePDF
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void ButtonStart_Click(object sender, RoutedEventArgs e){Info_Text.Text = string.Empty;CombinePdfFiles(Url_Text.Text);}public void CombinePdfFiles(string folderPath){try{//读取文件夹中的文件夹int fileCount = 0;int pageCount = 0;PdfDocument outPdfFile = new PdfDocument();List<string> fileNameList = new List<string>();List<string> fileError = new List<string>();fileNameList.Add("开始合并");foreach (var filename in Directory.GetFiles(folderPath)){if (System.IO.Path.GetExtension(filename) == ".pdf"){try{PdfDocument pdfFile = PdfReader.Open(filename, PdfDocumentOpenMode.Import);fileCount++;pageCount += pdfFile.PageCount;int pageIndex = 0;foreach (var pdfPage in pdfFile.Pages){outPdfFile.AddPage(pdfPage);pageIndex++;fileNameList.Add(string.Format("文件名:{0}\t\t\t\t第{1}页\t文件共有{2}页", System.IO.Path.GetFileName(filename), pageIndex, pdfFile.PageCount));}}catch (Exception ex){fileError.Add(System.IO.Path.GetFileName(filename));Info_Text.Text += ex.Message + "\r\n";}}}string combineResult = "";if (fileCount > 0){//导出pdf文件string timeTag = DateTime.Now.ToString("MMdd_HH_mm_ss");SavePdfFile(folderPath + "\\合并", timeTag + ".pdf", outPdfFile);fileNameList.Add(string.Format("共 {0} 个文件,共 {1} 页。", fileCount, pageCount));if (fileError.Count > 0){fileNameList.Add("合并失败文件:");foreach (string p in fileError){fileNameList.Add(p);}}SaveTxtFile(folderPath + "\\合并", timeTag + ".txt", fileNameList);}combineResult = string.Format("合并成功文件数量:{0}", fileCount);if (fileError.Count > 0){combineResult += "\r\n";combineResult += string.Format("合并失败文件数量:{0}", fileError.Count);}foreach(var str in fileNameList){Info_Text.Text += str + "\r\n"; ;}Info_Text.Text += combineResult + "\r\n"; }catch (Exception ex){Info_Text.Text+=ex.Message + "\r\n";}Info_Text.ScrollToEnd();}private void SavePdfFile(string folderPath, string fileName, PdfDocument pdfFile){if (!Directory.Exists(folderPath)){Directory.CreateDirectory(folderPath);}pdfFile.Save(folderPath + "\\" + fileName);}private void SaveTxtFile(string folderPath, string fileName, List<string> content){if (!Directory.Exists(folderPath)){Directory.CreateDirectory(folderPath);}string fileFullPath = folderPath + "\\" + fileName;if (!File.Exists(fileFullPath)){var newFile = File.CreateText(fileFullPath);newFile.Close();}using (StreamWriter sw = new StreamWriter(fileFullPath, true)){foreach (string line in content){sw.WriteLine(line);}sw.Close();}}private void ButtonUrl_Click(object sender, RoutedEventArgs e){FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();folderBrowserDialog.Title = "Select a folder";//folderBrowserDialog.InitialFolder = @"C:\";folderBrowserDialog.AllowMultiSelect = false;if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){Url_Text.Text = folderBrowserDialog.SelectedFolder;}}}
}

使用方法->打开软件

选择目录

合成成功

合并后的文件和日志

http://www.yayakq.cn/news/213114/

相关文章:

  • 网站关键字优化公司wordpress 一键 样式
  • 网站备案期间如何网站设计素材
  • 做导航网站赚钱吗网上接单 网站建设
  • 哈尔滨建设网站成本网站目录改版如何301跳转呀
  • 普陀专业做网站浙江省建设职业技术学院网站
  • 贵池网站建设大连建站模板制作
  • 建设网站需要想好的问题杭州公司招聘
  • ckplayer怎么上传做网站公网带宽1m能建设电商网站吗
  • 江苏省建设厅官网网站首页检察网站建设请示
  • 佛山如何网站建设在哪里做微信公众号和小程序区别
  • 做网站运营有前景吗做网站加载速度有什么方法
  • 电商网站建设 解决方案的设计广告代理发布平台
  • 做网站推广的工作内容网站设计制作什么时候好
  • 河北网站设计推荐柚米科技网络文化经营许可证价格
  • 北京人力资源网站seo网站建设及扩词
  • 外贸网站建设行业发展情况石龙镇网站建设公司
  • 网站建设的价2019为网站网站做代理被判缓刑
  • 定制网站建设推广方案苏州seo整站优化
  • 网站怎么优化关键词排名两学一做专题网站
  • 余姚网站公司创建网站怎么创
  • 长沙招聘网站韩版做哪个网站好
  • 网站怎么弄为什么大型网站都用php
  • 青海做网站最好的公司本地最好的网站开发建设公司
  • 奉贤专业做网站王也电脑壁纸
  • 目前主流的跨境电商平台有哪些网站seo外包技术资源
  • 温州英文网站建设网站模板套餐
  • 网站做服务端网站开发在哪里接活
  • 网站制作公司商丘市北京外包做网站如何报价
  • 搜狗搜索网站提交入口接网站建设单子注意事项
  • 获胜者网站建设平面广告设计图片素材