English 中文(简体)
利用ITextSharp向PDF文档发送超文本文件
原标题:Convert HTML file to PDF file using ITextSharp

我愿完成以下工作:

鉴于html档案的路面名称,以及希望的pdf文档路名,使用ITextSharp将超文本文档转换为PDF。 我看到大量法典样本,这些样本与我需要的东西相接近,但并非完全需要。 我认为,我的解决办法需要利用iTextSharp.text.html.simpleparser. RainbowWorker.Parse ToList()的功能,但我有麻烦地利用实际的超文本档案和编制实际的PDF文件。

public void GeneratePDF(string htmlFileName, string outputPDFFileName)
{...}

我真的希望能正常工作。

预 收

www.un.org/Depts/DGACM/index_french.htm

iTextSharp.text.Document doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream(Path.GetFullPath("fromHTML.pdf"), FileMode.Create));

        doc.Open();

        try
        {
            List<IElement> list = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(File.ReadAllText(this.textBox1.Text)), null);
            foreach (IElement elm in list)
            {
                doc.Add(elm);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        doc.Close();

请注意,文本Box1.Text中载有试图转换为pdf的html案Im的全部路径名称,我希望将这一名称从“超文本”中获取产出。

感谢!

问题回答

I had the same requirement and was diverted to this page by Google but could not find a concrete answer. But after some head hitting and trials, i have been able to successfully convert the HTML code to PDF using iTextSharp library 5.1.1. The code that i have shared here also takes care of the img tags in HTML with relative paths. iTextSharp library throws an error if your img tags do not have absolute src. You an find the code here: http://am22tech.com/s/22/Blogs/post/2011/09/28/HTML-To-PDF-using-iTextSharp.aspx

让我知道,你们是否需要更多的信息。 该法典正在编号中。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签