//Ensure that the pdfPage printed is always PORTRAIT so =
newPdfPage.Orientation = PageOrientation.Portrait;
newPdfPage.Size = PageSize.A4;
/*int baseX = 500;
int baseY = 1000;
double height = XUnit.FromMillimeter(baseY + 10).Point;
newPdfPage.CropBox = new PdfRectangle(new XPoint(0, newPdfPage.Height - height),
new XSize(newPdfPage.Width, height));
*/
// Capture the content of the tab as an image
using (Bitmap tabImage = new Bitmap(tab.Width, tab.Height))
{
tab.DrawToBitmap(tabImage, new System.Drawing.Rectangle(0, 0, tab.Width, tab.Height));
// Draw the captured image directly onto the PDF page
XImage image = XImage.FromGdiPlusImage(tabImage);
// https://stackoverflow.com/questions/61874041/how-to-set-format-of-pdf-by-pdfsharp-set-pagesize-to-a4-and-fit-on-page-shrink
// this 595,842 always prints the captured image as an A4 picture
gfx.DrawImage(image, 0, 0, 595, 802);
// the above command makes uploads the image as sized pdf, however it is slightly distorted
}
}
}
// Get the user's desktop path
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// Specify the save path for the PDF
string savePath = System.IO.Path.Combine(desktopPath, "ETTV CALC PDF.pdf");
// Save the PDF to the desktop
pdfDocument.Save(savePath);
MessageBox.Show("Tabs saved as a single PDF on the desktop.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}