參考
https://stackoverflow.com/questions/32714386/convert-xps-to-pdf-using-pdfsharp-or-itextsharp
WinForm 專案
Form1.cs
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
string sourceXpsFile = "";
string destPdfFile = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
sourceXpsFile = openFileDialog1.FileName;
destPdfFile = sourceXpsFile + ".pdf";
//Read the contents of the file into a stream
//var fileStream = openFileDialog1.OpenFile();
//using (StreamReader reader = new StreamReader(fileStream))
//{
// fileContent = reader.ReadToEnd();
//}
}
PdfSharp.Xps.XpsConverter.Convert(sourceXpsFile, destPdfFile, 0);
}
}
}
|
(完)
沒有留言:
張貼留言