C# - 将 XML 文件另存为 PDF 作为原始图像(不转换) [英] C# - Save XML file as PDF as Raw Image (not converting)

查看:40
本文介绍了C# - 将 XML 文件另存为 PDF 作为原始图像(不转换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 xml 文件按原样保存为 PDF.换句话说,我正在尝试创建显示 XML 内容的 PDF 文件,如屏幕截图(如原始屏幕截图).我的客户不知何故需要这样.我真的在stackoverflow上找不到同样的问题.无论如何,我可以使用 iText 或其他一些库来做到这一点吗?

I am trying to save xml file as PDF as it is. In other words, I am trying to create PDF file that shows content of XML like a screenshot (like raw screenshot). My client somehow needs it like this. I couldn't really find the same question on stackoverflow. Is there anyway I can do this using iText or some other library?

谢谢!

推荐答案

首先从 XML 文件中提取文本:

First extract your text from XML file:

XmlDocument doc = new XmlDocument();
doc.Load("c:\\temp.xml");
string myText;
foreach(XmlNode node in doc.DocumentElement.ChildNodes){
   myText= node.InnerText; //or loop through its children as well
}

然后创建一个 PDF 文件并将此文本传递给它

Then create a PDF file and pass this text into it

在这种情况下,我使用 PDFFlow 库来创建 pdf 文档

in this case here I use PDFFlow library to create pdf documents

var DocumentBuilder.New()  
  .AddSection().AddParagraphToSection(myText).ToDocument()  
   .Build("Result.PDF"); 

这篇关于C# - 将 XML 文件另存为 PDF 作为原始图像(不转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆