如何使用itextsharp 5.1.1将html文件转换为pdf文件 [英] how to convert html file to pdf file using itextsharp 5.1.1

查看:107
本文介绍了如何使用itextsharp 5.1.1将html文件转换为pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将html文件转换为pdf文件。请给我示例代码c#

I want to convert html file into pdf file . please give me sample code in c#

推荐答案

fdjdjhg

njgjkjkj

jhjkgfhhhhganessbm

,Daafj。,jfhsh

maybbnjnmhuh jhfhduhfnjuu huhuakdaaoyu jhcsdfuydh kuaysdfuauaj jhjahuyii hkha uu

jmSHDDD / HHH D HFSSHH HJ hjghdf
fdjdjhg
njgjkjkj
jhjkgfhhhhganessbm
,Daafj.,jfhsh
maybbnjnmhuh jhfhduhfnjuu huhuakdaaoyu jhcsdfuydh kuaysdfuauaj jhjahuyii hkha uu
jmSHDDD / HHHD HFSSHH HJ hjghdf
<pre lang="c++">

g fg jg kj,vjh jhh jghfkgkj hjkjjklfguuewn yyro uriweurw

g fg jg kj , vjh j h h jghfkgkj hjkjjklfguuewn yyro uriweurw


这个问题含糊不清,你没有指定你正在使用的ItextSharp的版本,即使你所处的情况也没有。如果你搜索了你的问题的关键字,你会得到的答案少于一秒。但是,



This question is ambiguous, you are not specifying the version of ItextSharp you are using not even the situation you are in. If you googled the keywords of you question you will get the answer in less then a second. However,

private MemoryStream createPDF(string html)
    {
        MemoryStream msOutput = new MemoryStream();
        TextReader reader = new StringReader(html);

        // step 1: creation of a document-object
        Document document = new Document(PageSize.A4, 30, 30, 30, 30);            

        // step 2:
        // we create a writer that listens to the document
        // and directs a XML-stream to a file
        PdfWriter writer = PdfWriter.GetInstance(document, msOutput);

        // step 3: we create a worker parse the document
        HTMLWorker worker = new HTMLWorker(document);

        // step 4: we open document and start the worker on the document
        document.Open();
        worker.StartDocument();

        // step 5: parse the html into the document
        worker.Parse(reader);

        // step 6: close the document and the worker
        worker.EndDocument();
        worker.Close();
        document.Close();

        return msOutput;
    }





来源: http://stackoverflow.com/questions/2822843/itextsharp-html-to-pdf [ ^ ]



干杯



Source: http://stackoverflow.com/questions/2822843/itextsharp-html-to-pdf[^]

Cheers


这篇关于如何使用itextsharp 5.1.1将html文件转换为pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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