-1

我试图将我的网站转换为 pdf,我的网站用于报告,在一个页面上您输入信息,在另一页面上您通过会话获取它,如果重要的话,网站中有图片和 css。

我试图使用 itextsharp 但它对我来说太复杂了。

我尝试在这里使用一些示例,但它们都不是我所需要的,所以它不起作用。 http://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/

谁能向我解释我需要做什么?

我也试过这段代码,但它不起作用,有人告诉我我需要使用 xmlworker 但我真的不明白如何(以及它是否会工作)

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

谢谢你

顺便说一句,如果有一个简单的解决方案需要花钱,我有能力支付它。

4

1 回答 1

0

Try to use Scryber, it's pay in commercial ussage, but you can use the free version (it adds a watermark on generated .pdf files) for prototyping.

A .pdf file structure and styles are configurable in .xml so it's quite easy and flexible.

Exaple of defining a structure

<data:ForEach select="rss/channel" datasource-id="BBCRss" >
         <Template>
           <pdf:Div style:class="heading" >
             <data:If test="string-length(image/url) &gt; 0" >
               <Template>
                 <pdf:Link action="Uri" file="{xpath:image/link}" new-window="true" alt="{xpath:image/title}" >
                   <Content>
                     <pdf:Image src="{xpath:image/url}" style:width="{xpath:image/width}" style:padding="10" />
                   </Content>
                 </pdf:Link>
               </Template>
             </data:If>
               <pdf:H1 style:class="red-text" text="{xpath:title}"></pdf:H1>
               <pdf:Label text="{xpath:description}" /><BR/>
               Date: <pdf:Label text="{xpath:lastBuildDate}" />
           </pdf:Div>

           <pdf:Div style:class="content" >            
             <data:ForEach select="item" >
               <Template>
                 <pdf:Div style:class="rss-item red-underline" >
                   <pdf:Div style:class="rss-item-data" >
                     <pdf:H2 style:class="red-text" text="{xpath:title}" ></pdf:H2>
                     <pdf:Label text="{xpath:description}" />
                   </pdf:Div>
                 </pdf:Div>

          </Template>
 </data:ForEach>

and style

<style:Style applied-type="pdf:Div" applied-class="content" >
   <style:Columns count="2" alley-width="20pt"/>
   <style:Font size="12pt" bold="false" italic="false"  />
 </style:Style>

Here you'll find sample project and some explanation. Moreover, Scryber is better documented than iTextSharp.

于 2013-11-05T20:27:00.953 回答