Rendern mathjax beim Konvertieren von JS HTML in PDF mit iText7 in C# .NET 8.0C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Rendern mathjax beim Konvertieren von JS HTML in PDF mit iText7 in C# .NET 8.0

Post by Anonymous »

Ich versuche, JS zu bewerten und von HTML nach PDF mit ITEXT7 in C# zu konvertieren, wobei Selenium WebDrive und Headless Chrome diesem Beispiel folgen. Ich mache dies hauptsächlich, um zu versuchen, mathematische Gleichungen mit Mathjax zu rendern und sie in ein PDF -Format umzuwandeln. class = "Lang-CS PrettyPrint-Override">

Code: Select all

static void Main(string[] args)
{
String html = File.ReadAllText(SRC);
ChromeOptions options = new ChromeOptions();
// Spin up the browser in "headless" mode, this way Selenium will not open up
// a graphical user interface.
options.AddArgument("--headless");
// I have a copy of the chromedriver.exe file in my 'Debug' folder, as such I can
// pass "." as an argument and Selenium will automatically load up the correct Driver.
// If your chromedriver.exe file is located elsewhere you will have to provide a
// path to its parent folder.
// It is also possible to use a different 3rd party library to automatically
// download the necessary driver.
// This way you don't have to bother with setting the path to the executable.
// An example could be
// https://www.nuget.org/packages/Selenium.WebDriver.ChromeDriver/.
ChromeDriver driver = new ChromeDriver(options);
// Open up the HTML file in our headless browser. This step will evaluate the
// JavaScript for us.
driver.Navigate().GoToUrl("data:text/html;charset=utf-8," + html);
// Now all we have to do is extract the evaluated HTML syntax and convert it to
// a PDF using iText's HtmlConverter.
String evaluatedHtml =
(String)driver.ExecuteScript("return document.documentElement.innerHTML;");
HtmlConverter.ConvertToPdf(evaluatedHtml, new FileStream(DEST, FileMode.Create));
}
< /code>
[b] Hier ist meine HTML-Datei mit JS: < /strong> < /p>





MathJax TeX Test Page




When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$



Wie mein PDF derzeit aussieht: [/b]
pdfimage
Haben Sie eine Idee, wie ich dieses Problem übergeben kann?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post