在 C#/WPF 应用程序中使用 pdflatex.exe 将 TeX 转换为 PDF
有人曾经在 C#/WPF 应用程序中使用 pdflatex.exe 从 TeX 文档创建过 PDF 文档吗?我有我的 TeX 文档,我想将其转换为 PDF 并在应用程序中显示它,但是,我不确定如何执行此操作,而且我在网上几乎找不到任何关于执行此类操作的信息。有谁知道做这样的事情的最佳方法是什么(通过 C# 应用程序中的 pdflatex.exe 将 TeX 文档转换为 PDF)?
多谢!
Has anyone ever created a PDF document from a TeX document using pdflatex.exe in their C#/WPF application? I have my TeX document and I want to convert it to PDF and display it within the application, however, I'm unsure how to go about doing this and there's virtually nothing that I can find online about doing something like this. Does anyone know what the best way to do something like this is (convert a TeX document to PDF via pdflatex.exe within a C# application)?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我使用的代码。它假设源代码与可执行文件位于同一文件夹中,并且如果需要,则包括运行 BibTeX(如果需要,只需排除第二个进程)。
是的,这可以稍微清理一下,当然,如果不调用 BibTeX,则可以在循环中调用(建议使用 3 次,以确保所有引用都正确)。此外,没有异常处理,因此您可能需要在进程调用等周围添加 try / catch 块。
Here's the code I used. It assumes the source is in the same folder as the executable, and includes running BibTeX if you need it (just exclude the second process if needed).
Yes, this could be cleaned up a little, and certainly without the call to BibTeX could just be called in a loop (3 times is the recommended number to make sure all the references are correct). Also, there's no exception handling, so you might want to add try / catch blocks around the process calls, etc.
我从来没有这样做过,但这完全有可能。您需要使用 System.Diagnostics.Process运行 pdflatex.exe 的类
剩下的就是选择它的运行方式。您可能在这里有一些选择:
如果 pdflatex 支持将输出写入“标准输出”,您可以拦截它并按照您想要的方式处理内容。
另一种选择是使用某个临时文件夹写入文件并订阅有关文件夹更改的通知(异步,您可以运行 pdflatex 的多个实例)或只是等待该过程完成(同步,您只能运行一个 pdflatex 实例)一次)。
I have never done that, but this is perfectly possible. You'll need to use System.Diagnostics.Process class to run pdflatex.exe
The rest is about choosing the way this should run. You probably have some options here:
If pdflatex supports writing output to "standard output" you can intercept that and do with the content whatever you want.
Another option is using some temporary folder to write the file to and subscribing to notifications about folder changes (asynchronous, you can run multiple instances of pdflatex) or simply waiting for the process to finish (synchronous, you can run only one instance of pdflatex at a time).