169 lines
5.9 KiB
C#
169 lines
5.9 KiB
C#
using Library14Petrushin;
|
||
using Library14Petrushin.Classes;
|
||
|
||
namespace ExexForm2
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
private PdfImg pdfImg;
|
||
private List<ImageData> selectedImages;
|
||
private string selectedDirectory;
|
||
private PdfColGroupTable pdfTable;
|
||
private PdfCirclDiagr pdfCirclDiagr;
|
||
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
pdfImg = new PdfImg();
|
||
selectedImages = new List<ImageData>();
|
||
pdfTable = new PdfColGroupTable();
|
||
pdfCirclDiagr = new PdfCirclDiagr();
|
||
}
|
||
|
||
private void btnSelectImages_Click(object sender, EventArgs e)
|
||
{
|
||
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
||
{
|
||
openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";
|
||
openFileDialog.Multiselect = true;
|
||
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
foreach (string fileName in openFileDialog.FileNames)
|
||
{
|
||
selectedImages.Add(new ImageData { ImagePath = fileName });
|
||
lstImages.Items.Add(fileName);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectDirectory_Click(object sender, EventArgs e)
|
||
{
|
||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||
{
|
||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
selectedDirectory = folderBrowserDialog.SelectedPath;
|
||
lblDirectory.Text = "Selected Directory: " + selectedDirectory;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnCreatePdf_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(txtDocumentTitle.Text) || selectedImages.Count == 0 || string.IsNullOrEmpty(selectedDirectory))
|
||
{
|
||
MessageBox.Show("Please select images, directory, and enter a document title.");
|
||
return;
|
||
}
|
||
|
||
string fileName = Path.Combine(selectedDirectory, "output1.pdf");
|
||
pdfImg.CreatePdfDocument(fileName, txtDocumentTitle.Text, selectedImages);
|
||
MessageBox.Show("PDF document created successfully!");
|
||
}
|
||
|
||
|
||
// 2 -------------------------------------------
|
||
|
||
|
||
private void btnCreatePdfTable_Click(object sender, EventArgs e)
|
||
{
|
||
string selectDirTable = "";
|
||
string fileName = "";
|
||
|
||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||
{
|
||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
selectDirTable = folderBrowserDialog.SelectedPath;
|
||
}
|
||
}
|
||
|
||
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
||
{
|
||
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
|
||
saveFileDialog.DefaultExt = "pdf";
|
||
saveFileDialog.InitialDirectory = selectDirTable;
|
||
saveFileDialog.FileName = "output2.pdf";
|
||
|
||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
fileName = saveFileDialog.FileName;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(fileName))
|
||
{
|
||
var generator = new PdfColGroupTable();
|
||
|
||
var data1 = new List<Person>
|
||
{
|
||
new Person { FirstName = "John", LastName = "Doe", Age = 30 },
|
||
new Person { FirstName = "Jane", LastName = "Smith", Age = 25 }
|
||
};
|
||
|
||
var commonHeaders = new List<string> { "Name", "", "" };
|
||
var headersNames = new List<(string, string)> {
|
||
("First Name","FirstName"),
|
||
("Last Name", "LastName"),
|
||
("Age", "Age")
|
||
};
|
||
var rowHeights = new List<double> { 20, 20 };
|
||
var mergeCells = new List<(int startRow, int endRow, int startColumn, int endColumn)>
|
||
{
|
||
(0, 1, 0, 0), // 0 <20> 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
(2, 2, 0, 1)
|
||
};
|
||
|
||
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headersNames, commonHeaders, data1);
|
||
}
|
||
}
|
||
|
||
|
||
// 3 -------------------------------------------
|
||
|
||
|
||
private void btnCreatePdfCircl_Click(object sender, EventArgs e)
|
||
{
|
||
string selectDir = "";
|
||
string fileName = "";
|
||
|
||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||
{
|
||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
selectDir = folderBrowserDialog.SelectedPath;
|
||
}
|
||
}
|
||
|
||
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
||
{
|
||
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
|
||
saveFileDialog.DefaultExt = "pdf";
|
||
saveFileDialog.InitialDirectory = selectDir;
|
||
saveFileDialog.FileName = "output3.pdf";
|
||
|
||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
fileName = saveFileDialog.FileName;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(fileName))
|
||
{
|
||
var pdfCirclDiagr = new PdfCirclDiagr();
|
||
|
||
List<ChartData> chartData = new List<ChartData>
|
||
{
|
||
new ChartData { SeriesName = "Series 1", Value = 10 },
|
||
new ChartData { SeriesName = "Series 2", Value = 20 },
|
||
new ChartData { SeriesName = "Series 3", Value = 30 },
|
||
new ChartData { SeriesName = "Series 4", Value = 40 }
|
||
};
|
||
|
||
pdfCirclDiagr.GeneratePdf(fileName, "Document Title", "Chart Title", LegendPosition.Right, chartData);
|
||
}
|
||
}
|
||
}
|
||
} |