#if Html2pdf
using iText.Html2pdf;
#endif
using Microsoft.Extensions.Logging;
#if Selenium
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
#endif
namespace File_Folder_Helper.ADO2025.PI5;
internal static partial class Helper20250505 {
//
//
//
//
//
//
internal static void HyperTextMarkupLanguageToPortableDocumentFormat(ILogger logger, List args) {
if (args.Count == 999)
TestA();
if (args.Count == 999)
TestB();
if (args.Count != 999)
TestC(logger);
}
private static void TestA() {
#if Html2pdf
string inputFile = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", ".html");
string outputFile = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "a.pdf");
using (FileStream htmlSource = File.Open(inputFile, FileMode.Open))
using (FileStream pdfDest = File.Open(outputFile, FileMode.Create)) {
ConverterProperties converterProperties = new();
HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
}
#endif
}
private static void TestB() {
#if Html2pdf
HttpClient httpClient = new();
Task stream = httpClient.GetStreamAsync("https://ourrescue.org/");
stream.Wait();
string outputFile = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "b.pdf");
using (FileStream pdfDest = File.Open(outputFile, FileMode.Create)) {
ConverterProperties converterProperties = new();
HtmlConverter.ConvertToPdf(stream.Result, pdfDest, converterProperties);
}
#endif
}
private static void TestC(ILogger logger) {
#if Selenium
EdgeOptions edgeOptions = new();
edgeOptions.AddArgument("--no-sandbox");
edgeOptions.AddArgument("--disable-gpu");
edgeOptions.AddArgument("--headless=new");
edgeOptions.AddArgument("--start-maximized");
edgeOptions.AddArgument("--profile-directory=Default");
edgeOptions.AddArgument("--browser-version 133.0.3065.82");
EdgeDriver edgeDriver = new(edgeOptions);
string outputFile = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", ".png");
try {
// edgeDriver.Navigate().GoToUrl("https://ourrescue.org/");
// edgeDriver.Navigate().GoToUrl("https://intranet.infineon.com/");
edgeDriver.Navigate().GoToUrl("https://messa020ec.infineon.com:50205/ProductionReport/DailyReport");
int fullWidth = int.Parse(edgeDriver.ExecuteScript("return document.body.parentNode.scrollWidth").ToString());
int fullHeight = int.Parse(edgeDriver.ExecuteScript("return document.body.parentNode.scrollHeight").ToString());
edgeDriver.Manage().Window.Size = new(fullWidth, fullHeight);
Screenshot screenshot = edgeDriver.GetScreenshot();
screenshot.SaveAsFile(outputFile);
} catch (Exception ex) {
logger.LogError(ex, ex.Message);
}
edgeDriver.Close();
#endif
}
}