English 中文(简体)
传真到PDF 解决办法(Handling Content, Headers andfooters)
原标题:HTML to PDF Solution (Handling Content, Headers and Footers)

我试图通过产生以超文本为基础的国防军来制造“报告”。

首先,我只是试图用 raw字书写硬形的超文本,然后用 Java印该文件。 然而,这给我带来了对头脑和脚.的控制。

我尝试使用<代码>thead和tfoot内容,这些内容在大多数浏览器中相当有效,但我无法得到我所期待的格式。

目前,我正试图在MVC3使用iTextSharp进行服务器边解决方案,然而,我对于如何继续工作,没有与iTextSharp做很多工作,就失去了一点。

www.un.org/Depts/DGACM/index_spanish.htm 产出和说明:

编写报告时将使用4个项目:

  • Report Content (which is currently encoded HTML, as I am unsure if decoding will change any formatting)
  • Report Title (will simply be the name of the PDF generated)
  • Report Header (will be displayed at the upper-left of each page)
  • Report Footer (will be displayed at the lower-left of each page)

www.un.org/Depts/DGACM/index_spanish.htm 主计长行动:

//This will be accessed by a jQuery Post
[HttpPost]
public FileStreamResult GeneratePDF(string id)
{
      //Grab Report Item
      ReportClass report = reportingAgent.GetReportById(id);

      Document doc = new Document();

      //Do I need to decode the HTML or is it possible to use the encoded HTML?

      //Adding Headers / Footers

      //Best method of returning the PDF?
}
最佳回答

iTextSharp cannot convert HTML to PDF. It s not what it was designed to do. It was designed to create PDF files from scratch, not converting between various formats into PDF. If you want to convert HTML into PDF you could for example use the the flying-saucer library which is based on iText. I have blogged about how this could be done in .NET using IKVM.NET Bytecode Compiler (ikvmc.exe).

因此,你的控制者的行动可能会看一看:

[HttpPost]
public FileStreamResult GeneratePDF(string id)
{
    ReportClass report = reportingAgent.GetReportById(id);
    return PdfResult(report.Html);
}

www.un.org/spanish/ecosoc 这可能是一种习俗行动的结果,使人民抵抗力量在反应流中投放原始的超文本和产出:

public class PdfResult : ActionResult
{
    private readonly string _html;
    public PdfResult(string html)
    {
        _html = html;
    }

    public override void ExecuteResult(ControllerContext context)
    {
        var response = context.HttpContext.Response;
        response.ContentType = "application/pdf";
        var builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        using (var bais = new ByteArrayInputStream(Encoding.UTF8.GetBytes(_html)))
        using (var bao = new ByteArrayOutputStream())
        {
            var doc = builder.parse(bais);
            var renderer = new ITextRenderer();
            renderer.setDocument(doc, null);
            renderer.layout();
            renderer.createPDF(bao);
            var buffer = bao.toByteArray();
            response.OutputStream.Write(buffer, 0, buffer.Length);
        }
    }
}
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签