110,532
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Windows.Forms;
using PDFMAKERAPILib;
namespace pdfFormApp
{
public partial class Form1 : Form
{
private string PDF_DIRECTORY_PATH = @"C:\pdfFolder\";
public Form1()
{
InitializeComponent();
}
private void btn_select_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = false;
openFileDialog1.ShowDialog();
docPath.Text = openFileDialog1.FileName;
}
private void btn_Switch_Click(object sender, EventArgs e)
{
if (docPath.Text != null && docPath.Text != "")
{
string pdfFileName = PDF_DIRECTORY_PATH + GetRandomName();
PDFMakerApp app = new PDFMakerApp();
int flag = app.CreatePDF(docPath.Text, pdfFileName, PDFMakerSettings.kConvertAllPages, false, true, true, System.Type.Missing);
if (flag == 0)
{
pdfPath.Text = pdfFileName;
}
else
{
pdfPath.Text = "switch fail" + flag;
}
}
}
public string GetRandomName()
{
string companyName = "TaiJiKeJi";
DateTime nowTime = DateTime.Now;
companyName += "_" + nowTime.ToString().Replace("/", "_").Replace(":", "_").Replace(" ", "_");
string text = "pqowieurytalskdjfhgmznxbcv";
string lastName = "";
Random rad = new Random();
for (int i = 0; i < 10; ++i)
{
double randomDou = rad.NextDouble();
int randomInt = rad.Next(text.Length);
int pos = (int)(randomDou * 100 + randomInt) % text.Length;
lastName += text[pos];
}
return companyName + lastName + ".pdf";
}
private void btn_show_Click(object sender, EventArgs e)
{
if (pdfPath.Text != null && pdfPath.Text != "")
{
System.Diagnostics.Process.Start(pdfPath.Text);
}
}
}
}