Laz
Laz
CC#
Created by Laz on 10/23/2023 in #help
❔ How to fix distortion? also how to fix page cut off? also using Using PDFSharp
//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);
}
}
//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);
}
}
5 replies
CC#
Created by Laz on 10/23/2023 in #help
❔ How to fix distortion? also how to fix page cut off? also using Using PDFSharp
private void button30_Click(object sender, EventArgs e)
{
SaveAllTabsAsPDF();
}
private void SaveAllTabsAsPDF() // by taurius litvinavicius
{

//https://stackoverflow.com/questions/30867703/load-all-user-controls-of-a-form-on-start
// to force cycle and load every single tabpage in order to make them momentarily active to be saved
for (int i = 1; i < Main_TabPage.TabPages.Count; i++)
{
Main_TabPage.SelectedIndex = i;
}
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

//need to create a new pdf document so = , creates new var by incoking the class
PdfSharp.Pdf.PdfDocument pdfDocument = new PdfSharp.Pdf.PdfDocument();

//need to add a page so the information can be stored inside so =
// newPdfPage = pdfDocument.AddPage();

//need to creation class variable for providing drawing related Methods/Functions for the unique page created so =
// XGraphics gfx = XGraphics.FromPdfPage(newPdfPage);
//basically allows to "draw" on the pdf from the winform


foreach (TabPage tab in Main_TabPage.TabPages)
{
{
PdfPage newPdfPage = pdfDocument.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(newPdfPage);
private void button30_Click(object sender, EventArgs e)
{
SaveAllTabsAsPDF();
}
private void SaveAllTabsAsPDF() // by taurius litvinavicius
{

//https://stackoverflow.com/questions/30867703/load-all-user-controls-of-a-form-on-start
// to force cycle and load every single tabpage in order to make them momentarily active to be saved
for (int i = 1; i < Main_TabPage.TabPages.Count; i++)
{
Main_TabPage.SelectedIndex = i;
}
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

//need to create a new pdf document so = , creates new var by incoking the class
PdfSharp.Pdf.PdfDocument pdfDocument = new PdfSharp.Pdf.PdfDocument();

//need to add a page so the information can be stored inside so =
// newPdfPage = pdfDocument.AddPage();

//need to creation class variable for providing drawing related Methods/Functions for the unique page created so =
// XGraphics gfx = XGraphics.FromPdfPage(newPdfPage);
//basically allows to "draw" on the pdf from the winform


foreach (TabPage tab in Main_TabPage.TabPages)
{
{
PdfPage newPdfPage = pdfDocument.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(newPdfPage);
5 replies
CC#
Created by Laz on 10/18/2023 in #help
✅ Need help with school project, premises is to convert and print WinForms into a PDF format
/close
9 replies
CC#
Created by Laz on 10/18/2023 in #help
✅ Need help with school project, premises is to convert and print WinForms into a PDF format
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);
}
}
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);
}
}
this is what i have come up with but no progress, the API runs winform pops up, but then unable to be saved and converted to PDF form, as in there is no PDF generated and i don't know whyh
9 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
How do i close this
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
I found my error...
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Nvm...
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
I was looking in the comments section and a poster said to include it, and i did what they said...
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
No description
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
They said to use WPF...
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Yes WPF
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
I followed the video wrongly
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Then another error appeared
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Usercontrol was replaced with SimpleForm
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
No description
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
No description
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
I have no idea what im doing too, i was originally from C++ then my school pushed C# on to my entire cohort...
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Its what im given to use
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
Its supposed to be used in conjunction with ReVit to make API Plugins
45 replies
CC#
Created by Laz on 9/16/2023 in #help
✅ C# CS0246
No description
45 replies