Convert HTML to PDF in .NET

I want to generate a PDF by passing HTML contents to a function. I have made use of iTextSharp for this but it does not perform well when it encounters tables and the layout just gets messy. Is there a better way? Try wkhtmtopdf. It is the best tool I have found so far. For .NET, you may use this small library to easily invoke wkhtmtopdf command line utility. EDIT: New Suggestion HTML R

在.NET中将HTML转换为PDF

我想通过将HTML内容传递给函数来生成PDF。 我已经使用了iTextSharp,但它在遇到表格时表现不佳,布局变得混乱。 有没有更好的办法? 尝试wkhtmtopdf。 这是迄今为止我发现的最好的工具。 对于.NET,您可以使用这个小型库轻松调用wkhtmtopdf命令行实用程序。 编辑:使用PdfSharp的PDF 新建议 HTML渲染器 (尝试wkhtmltopdf并建议避免它) HtmlRenderer.PdfSharp是完全完全的C#托管代码 , 易于使用,线程安全且最

iTextSharp is producing a corrupt PDF

The code snippet below returns a corrupt PDF document however if I return mergedDocument instead it always returns a valid PDF. mergedDocument is based on a PDF file i created using Word, whereas completed document is entirely programmatically generated. The code "works" in that it throws no exceptions. Why is iTextSharp creating a corrupt PDF? byte[] completedDocument = null;

iTextSharp正在生成一个损坏的PDF

下面的代码片段返回一个损坏的PDF文档,但是如果我返回mergedDocument,它总是返回一个有效的PDF。 mergedDocument基于我使用Word创建的PDF文件,而完整的文档完全是以编程方式生成的。 代码“起作用”,因为它不会引发异常。 为什么iTextSharp创建一个损坏的PDF? byte[] completedDocument = null; using (MemoryStream streamCompleted = new MemoryStream()) { using (Document document = new Document())

iTextSharp + FileStream = Corrupt PDF file

I am trying to create a pdf file with iTextSharp. My attempt writes the content of the pdf to a MemoryStream so I can write the result both into file and a database BLOB. The file gets created, has a size of about 21kB and it looks like a pdf when opend with Notepad++. But my PDF viewer says it's currupted. Here is a little code snippet (only tries to write to a file, not to a database):

iTextSharp + FileStream =损坏的PDF文件

我正在尝试使用iTextSharp创建PDF文件。 我尝试将pdf的内容写入MemoryStream,以便将结果写入文件和数据库BLOB。 该文件被创建,大小约为21kB,在使用Notepad ++进行操作时,它看起来像一个pdf。 但我的PDF阅读器说它已经被破坏了。 这是一段小小的代码片段(只尝试写入文件,而不是数据库): Document myDocument = new Document(); MemoryStream myMemoryStream = new MemoryStream(); PdfWriter myPDFWriter = PdfWriter

C# Filestream Read

I am working with filestream read: https://msdn.microsoft.com/en-us/library/system.io.filestream.read%28v=vs.110%29.aspx What I'm trying to do is read a large file in a loop a certain number of bytes at a time; not the whole file at once. The code example shows this for reading: int n = fsSource.Read(bytes, numBytesRead, numBytesToRead); The definition of "bytes" is: "Whe

C#文件流读取

我正在使用filestream读取:https://msdn.microsoft.com/en-us/library/system.io.filestream.read%28v=vs.110%29.aspx 我试图做的是一次读取一个循环中的大文件一定数量的字节; 不是一次完整的文件。 代码示例显示了这个阅读: int n = fsSource.Read(bytes, numBytesRead, numBytesToRead); “字节”的定义为:“当此方法返回时,包含指定的字节数组,其偏移量和(偏移量+ count - 1)之间的值由当前源读取的字节替换。”

pdf is not opening by Adobe reader, created by using iTextSharp

I am new in iTextSharp coding. I am creating pdf file in VS2010 from html string . The html string containing html table that I want convert it into a pdf file. I have develop a code by own, which successfully create PDF file but when I go to open file, its shows message that Adobe Reader could not open 'XXX.pdf' because it is either not a supported file or because file has been dama

pdf不会由Adobe Reader使用iTextSharp创建

我是iTextSharp编码的新手。 我正在从html字符串在VS2010中创建PDF文件。 包含我想将其转换为pdf文件的html表格的html字符串。 我已经开发了自己的代码,它成功地创建PDF文件,但当我去打开文件时,它显示消息 Adobe Reader无法打开'XXX.pdf',因为它不是受支持的文件,或者是因为文件已损坏 但我没有得到我要去的地方错我开发的代码如下: Response.ContentType = "application/pdf"; Response.

Removing PDF invisible objects with iTextSharp

Is possible to use iTextSharp to remove from a PDF document objects that are not visible (or at least not being displayed)? More details: 1) My source is a PDF page containing images and text (maybe some vectorial drawings) and embedded fonts. 2) There's an interface to design multiple 'crop boxes'. 3) I must generate a new PDF that contains only what is inside the crop boxes.

使用iTextSharp删除PDF不可见对象

是否可以使用iTextSharp从PDF文档中删除不可见(或至少未显示)的对象? 更多细节: 1)我的源代码是一个包含图像和文本(可能是一些矢量图形)和嵌入字体的PDF页面。 2)有一个界面来设计多个“裁剪框”。 3)我必须生成一个新的PDF,其中只包含裁剪框内的内容。 其他任何东西都必须从结果文档中删除(实际上,我可能会接受内部一半和外部一半的内容,但这不是理想的,它不应该出现)。 目前我的解决方案是: 我已经

itextsharp and pdf

i want to read a pdf file line per line but i want to maintain his original format ¿can i do this with itextsharp? i use the next code : private void button1_Click(object sender, EventArgs e) { string text = string.Empty; string path = string.Empty; path = "C:\Documents and Settings\Rafael\Desktop\Imprimiendo\Print1.pdf"; PdfReader rea

itextsharp和pdf

我想读一行pdf文件行,但我想保持他原来的格式 ¿我可以用itextsharp做到这一点吗? 我使用下面的代码: private void button1_Click(object sender, EventArgs e) { string text = string.Empty; string path = string.Empty; path = "C:\Documents and Settings\Rafael\Desktop\Imprimiendo\Print1.pdf"; PdfReader reader = new PdfReader(path);

Merging multiple PDFs using iTextSharp in c#.net

Well i'm trying to merge multiple PDFs in to one. I gives no errors while compiling. I tried to merge the docs first but that went wrong because I'm working with tables. This is the asp.net code-behind if (Button.Equals("PreviewWord")) { String eventTemplate = Server.MapPath("/ERAS/Badges/Template/EventTemp" + EventName + ".doc"); String SinglePreview = Server.MapP

在c#.net中使用iTextSharp合并多个PDF

那么我试图合并多个PDF到一个。 编译时我没有提供任何错误。 我试图首先合并文档,但由于我正在使用表格而出错。 这是asp.net代码隐藏 if (Button.Equals("PreviewWord")) { String eventTemplate = Server.MapPath("/ERAS/Badges/Template/EventTemp" + EventName + ".doc"); String SinglePreview = Server.MapPath("/ERAS/Badges/Template/PreviewSingle" + EventName + ".doc"); String PDF

ITextSharp insert text to an existing pdf

The title sums it all. I want to add a text to an existing PDF file using iTextSharp, however i can't find how to do it anywhere in the web... PS: I cannot use PDF forms. Thanks in advance I found a way to do it (dont know if it is the best but it works) string oldFile = "oldFile.pdf"; string newFile = "newFile.pdf"; // open the reader PdfReader reader = new PdfReader(oldFile); Rect

ITextSharp将文本插入到现有的pdf中

标题总结了这一切。 我想使用iTextSharp将文本添加到现有的PDF文件,但是我找不到如何在网络中的任何位置执行此操作。 PS:我不能使用PDF表单。 提前致谢 我找到了一个方法来做到这一点(不知道它是否是最好的,但它的工作原理) string oldFile = "oldFile.pdf"; string newFile = "newFile.pdf"; // open the reader PdfReader reader = new PdfReader(oldFile); Rectangle size = reader.GetPageSizeWithRotation(1)

Reading PDF content with itextsharp dll in VB.NET or C#

How can I read PDF content with the itextsharp with the Pdfreader class. My PDF may include Plain text or Images of the text. using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System.IO; public string ReadPdfFile(string fileName) { StringBuilder text = new StringBuilder(); if (File.Exists(fileName)) { PdfReader pdfReader = new PdfReader(fileName);

在VB.NET或C#中使用itextsharp dll读取PDF内容

我如何使用带有Pdfreader类的itextsharp读取PDF内容。 我的PDF可能包含纯文本或图片的文字。 using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System.IO; public string ReadPdfFile(string fileName) { StringBuilder text = new StringBuilder(); if (File.Exists(fileName)) { PdfReader pdfReader = new PdfReader(fileName); for (int page = 1; page <= pdfReade