Files
VAR.PdfTools/VAR.PdfTools.Workbench/FrmPdfInfo.cs

67 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace VAR.PdfTools.Workbench
{
public partial class FrmPdfInfo : Form
{
public FrmPdfInfo()
{
InitializeComponent();
}
private void FrmPdfInfo_Load(object sender, EventArgs e)
{
txtPdfPath.Text = Properties.Settings.Default.LastPdfPath;
}
private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.LastPdfPath = txtPdfPath.Text;
Properties.Settings.Default.Save();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
var dlgFile = new OpenFileDialog();
DialogResult result = dlgFile.ShowDialog();
if (result == DialogResult.OK)
{
txtPdfPath.Text = dlgFile.FileName;
}
}
private void btnProcess_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(txtPdfPath.Text) == false)
{
MessageBox.Show("File does not exist");
return;
}
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
int nObjects = doc.Objects.Count;
List<PdfStream> streams = doc.Objects
.Where(obj => obj.Data.Type == PdfElementTypes.Stream)
.Select(obj => (PdfStream)obj.Data)
.ToList();
int nStreams = streams.Count;
int nPages = doc.Pages.Count;
List<string> lines = new List<string>();
lines.Add(string.Format("Filename : {0}", System.IO.Path.GetFileNameWithoutExtension(txtPdfPath.Text)));
lines.Add(string.Format("Number of Objects : {0}", nObjects));
lines.Add(string.Format("Number of Streams : {0}", nStreams));
lines.Add(string.Format("Number of Pages : {0}", nPages));
txtOutput.Lines = lines.ToArray();
}
}
}