这个小工具软件主要针对两个文件格式的转换,一个是针对KML文件对KML文件里面的经纬度的提取和生成,另一个是对PDF文件的格式转换,相信大家用过WPS,WPS的PDF转换是需要开会员才能转,所以我想自己写一个小工具软件,给大家白嫖一下,由于第一次做这种软件有个别考虑不周到的地方,希望大家谅解,我继续学习给大家做更好更优质的小工具给大家使用。文章最后贴了源码和软件安装包大家下载安装就可以用了,源码在后面大家想要继续增加功能也可以,这个小工具是用C#开发的,有一点点小bug不影响使用。家人们建议点赞收藏,你的点赞是我更文的动力。
选择你需要提取经纬度的KMl文件的位置,勾选你需要的功能,没勾选不会生成,提取之后会展示在界面,也可以一提取到TXT文件中,方便你查看。
没有勾选导出文本文件时不会导出的,只会展示经纬度的内容如下图所示
选择导出文本文件,你需要选择你的保存路径和文件名,如下图所示
选择你需要的生成KML经纬度文件的TXT文本文件,选择之后点生成,会让你选择保存路径,输入文件名即可,具体操作如下图
除了使用TXT文件生成也可使用输入框,输入你想要生成的点,你输入多少经纬度的点就会生成多少,具体操作如下
因为我只做了对KML文件中Point中的coordinates生成和提取,其他的没有做,看后期有时间了再完善
选择你需要转换文档格式,PDF转Word,选择你需要转的PDF文档位置,点击生成,会弹出保存路径和需要保存的文档名
效果展示:
效果如下图,步骤同上图一样
选择你需要的转换的PDF文档,选择你需要转出图片的格式,有八个格式可以选择,不选会有提示,然后将PDF文档中的每一页都会生成一个图片,选择你需要保存的位置,保存即可。
PDF转的文档会有一个注解删除即可,文档比较大可以使用替换将那条注解删除,在生成的时候需要注意稍微要等一会才会生成。
使用的时C#Winform设计,用了三个Panel作为容器,通过按钮对三个panel隐藏展示处理实现切换功能。
using PdfiumViewer;
using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FileConversion
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string KmlPath="";
public string txtPath = "";
public string PDFPath = "";
public string PDFPhotoPath = "";
public bool flag = false;
private void button6_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "KML文件(*.kml)|*.kml|所有文件|*.*";
if (openFile.ShowDialog() != DialogResult.OK)//打开文件是否点击了取消
return ;
KmlPath = openFile.FileName;
textBox1.Text = KmlPath;
}
private void button7_Click(object sender, EventArgs e)
{
DataExtract data = new DataExtract();
if(KmlPath.Equals("")==true)
{
MessageBox.Show("选择文件之后才能导出");
}
else
{
if (checkBox1.Checked == true && checkBox2.Checked == false|| checkBox1.Checked == true && checkBox2.Checked == true)
{
List list = data.MapConfigs(KmlPath);
string localFilePath = "";//文件路径
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Txt(*.txt)|*.txt"; //设置文件类型
save.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
if (save.ShowDialog() == DialogResult.OK)//点了保存按钮进入
{
localFilePath = save.FileName.ToString(); //获得文件路径
string fileName = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
//FileStream file = new FileStream(localFilePath, FileMode.Create);
foreach (string kml in list)
{
textBox2.Text += kml + "\r\n";
File.AppendAllText(localFilePath, kml+"\r\n");
}
}
}
else if (checkBox1.Checked == false && checkBox2.Checked == true)
{
List list = data.MapConfigs(KmlPath);
foreach (string kml in list)
{
textBox2.Text += kml + "\r\n";
}
}
else
{
MessageBox.Show("选择你需要的项");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
panel3.Visible = true;
panel4.Visible = false;
panel5.Visible = false;
}
private void button9_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "Txt(*.txt)|*.txt";
if (openFile.ShowDialog() != DialogResult.OK)//打开文件是否点击了取消
return;
txtPath = openFile.FileName;
textBox4.Text = txtPath;
}
private void button8_Click(object sender, EventArgs e)
{
AddKmlFile addKml = new AddKmlFile();
List list = new List();
if (txtPath.Equals("") == true && richTextBox1.Text.Equals("") == true)
{
MessageBox.Show("不能生成空KMl,导入txt文件或者在文本框粘贴");
}
else if(txtPath.Equals("")==false&& richTextBox1.Text.Equals("") == true)
{
list.Clear();
string[] stringlines = File.ReadAllLines(txtPath, Encoding.Default);
for (int i = 0; i < stringlines.Length; i++)
{
list.Add(stringlines[i]);
}
addKml.addKmlFile(list);
}
else
{
string str = "";
list.Clear();
TextReader read = new System.IO.StringReader(richTextBox1.Text);
str= read.ReadLine();
while(str!=null)
{
list.Add(str);
str = read.ReadLine();
}
addKml.addKmlFile(list);
}
}
private void Form1_Load(object sender, EventArgs e)
{
panel3.Visible = true;
panel4.Visible = false;
panel5.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
panel3.Visible = false;
panel4.Visible = true;
panel5.Visible = false;
}
private void button10_Click(object sender, EventArgs e)
{
Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
if(textBox3.Text.Equals("")!=true&&(radioButton1.Checked!=false|| radioButton2.Checked != false || radioButton3.Checked != false) )
{
if (radioButton1.Checked)
{
try
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "DOC(*.doc)|*.doc"; //设置文件类型
save.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
save.FileName = "请输入你要保存的文件名";
if (save.ShowDialog() == DialogResult.OK)//点了保存按钮进入
{
label6.Text = "转换中请耐心等待.....";
pdf.LoadFromFile(PDFPath);
pdf.SaveToFile(save.FileName.ToString(), FileFormat.DOC);//生成word的物理路径
label6.Text = "转换成功";
}
}
catch
{
label6.Text = "转换失败";
}
}
else if(radioButton2.Checked)
{
try
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "XlS(*.xlsx)|*.xlsx"; //设置文件类型
save.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
if (save.ShowDialog() == DialogResult.OK)//点了保存按钮进入
{
label6.Text = "转换中请耐心等待.....";
pdf.LoadFromFile(PDFPath);
pdf.SaveToFile(save.FileName.ToString(), FileFormat.XLSX);//生成word的物理路径
label6.Text = "转换成功";
}
}
catch
{
label6.Text = "转换失败";
}
}
else if(radioButton3.Checked)
{
try
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "HTML(*.html)|*.html"; //设置文件类型
save.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
if (save.ShowDialog() == DialogResult.OK)//点了保存按钮进入
{
label6.Text = "转换中请耐心等待.....";
pdf.LoadFromFile(PDFPath);
pdf.SaveToFile(save.FileName.ToString(), FileFormat.HTML);//生成word的物理路径
label6.Text = "转换成功";
}
}
catch
{
label6.Text = "转换失败";
}
}
}
else
{
MessageBox.Show("选择路径和转换方式之后才能生成文件");
}
}
private void button11_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "PDF(*.pdf)|*.pdf";
if (openFile.ShowDialog() != DialogResult.OK)//打开文件是否点击了取消
return;
PDFPath = openFile.FileName;
textBox3.Text = PDFPath;
}
public static void PDFConvertTo(string inFilePath, string outFilePath, ImageFormat format)
{
outFilePath = $"{outFilePath}\\{DateTime.Now.ToString("yyyyMMdd-HHmmss")}";
using (var document = PdfiumViewer.PdfDocument.Load(inFilePath))
{
var pageCount = document.PageCount;
for (int i = 0; i < pageCount; i++)
{
string outFile = $"{outFilePath}({i + 1}).{format}";
var dpi = 300;
using (var image = document.Render(i, dpi, dpi, PdfRenderFlags.CorrectFromDpi))
{
var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == format.Guid);
var encParams = new EncoderParameters(1);
encParams.Param[0] = new EncoderParameter(
System.Drawing.Imaging.Encoder.Quality, 10L);
image.Save(outFile, encoder, encParams);
}
}
}
}
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "PDF(*.pdf)|*.pdf";
if (openFile.ShowDialog() != DialogResult.OK)//打开文件是否点击了取消
return;
PDFPhotoPath = openFile.FileName;
textBox5.Text = PDFPhotoPath;
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox5.Text.Equals("") != true &&( radioButton5.Checked != false || radioButton6.Checked != false || radioButton7.Checked != false || radioButton8.Checked != false || radioButton9.Checked != false || radioButton10.Checked != false || radioButton11.Checked != false || radioButton12.Checked != false))
{
try
{
SaveFileDialog save = new SaveFileDialog();
save.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
save.FileName = "选择你需要保存的位置";
if (save.ShowDialog() == DialogResult.OK)//点了保存按钮进入
{
label7.Text = "转换中请耐心等待.....";
if(radioButton5.Checked==true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Gif);
}
else if(radioButton6.Checked==true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Bmp);
}
else if (radioButton7.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Jpeg);
}
else if (radioButton8.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Png);
}
else if (radioButton9.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Exif);
}
else if (radioButton10.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Wmf);
}
else if (radioButton11.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Icon);
}
else if (radioButton12.Checked == true)
{
PDFConvertTo(PDFPhotoPath, save.FileName.Substring(0, save.FileName.LastIndexOf("\\")), ImageFormat.Tiff);
}
label7.Text = "转换成功";
}
}
catch
{
label6.Text = "转换失败";
}
}
else
{
MessageBox.Show("选择路径和转换格式之后才能生成文件");
}
}
private void button3_Click_1(object sender, EventArgs e)
{
panel3.Visible = false;
panel4.Visible = false;
panel5.Visible = true;
}
}
}
下载链接:链接:https://pan.baidu.com/s/1UEJoKMhGQjzEZZxpSokgAg
提取码:IC00
使用的技术有,XML文件的生成,对PDF的依赖接口的引用,对文件的读取,由于博主技术有限,只能做到这个样子,后期不断的学习,不断的探索,希望可以对这个小工具软件进一步的优化,欢迎大家留言评论一下,我们一起探讨,顺便指点我一下,我会继续学习,毕竟学无止境,家人们不喜勿喷,点赞收藏,你的点赞是我更文的动力,也是我学习的方向。栓Q啦!