private void WinFormToPDF_Click(object sender, EventArgs e)
{
try
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Iterate through tabs
foreach (TabPage tab in Main_TabPage.TabPages)
{
// Create a new PDF page for each tab
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
// Add content to the PDF page
XFont font = new XFont("Arial", 12);
XBrush brush = XBrushes.Black;
gfx.DrawString("Data from WinForms:", font, brush, 100, 100);
}
// Save the PDF to a file
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string pdfFileName = Path.Combine(desktopPath, "ETTV CALCULATION PDF.pdf");
document.Save(pdfFileName);
System.Diagnostics.Process.Start(pdfFileName);
TaskDialog.Show("PDF Created", $"The information has been saved to {pdfFileName}");
System.Diagnostics.Process.Start(pdfFileName);
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}