HTMLתPDF£¨C# itextsharp£©
Ò»¡¢ ÐèÇ󣺽«HTMLתPDF´òÓ¡¡£WebÏîÄ¿ÖÐ×ÜÊÇÓÐÕâÑùµÄÐèÇ󣬺ÜÊÇÈÃÈË¿àÄÕ¡£
¶þ¡¢ ·ÖÎö£ºÈçºÎÍê³ÉÕâ¸ö¹¤×÷£¿
1¡¢ ÐèÒª½âÎöHTML£¬È»ºóÀûÓÃitextsharp»æÖÆpdfÎĵµ¡£½âÎöHTMLÊÇÒ»¸öºÜÄÑÍê³ÉµÄÈÎÎñ£¬¸÷¸öä¯ÀÀÆ÷¶ÔHTMLµÄ½âÎöÎ廨°ËÞÍÖªµÀÕâ²»ºÃ½â¾ö¡£ÕâÌõ·²»ºÃ×ߣ¬µ«Ò²ÊÇ¿ÉÒÔÍê³ÉµÄ£¬Í¨¹ýwebbrowserÀà¿ÉÒÔ½âÎöHTML»ñÈ¡¸÷¶ÔÏóµÄλÖã¬È»ºó»æÖƵ½pdfÖС£·½·¨ÊÇ¿ÉÐУ¬ÆäÖеĸ´ÔӶȲ»Ð¡¡£
2¡¢ ½«HTML±£´æΪͼƬ£¬È»ºó²åÈëµ½pdfÎĵµÖУ¬ÕâÀォ½éÉÜÕâÖÖ·½·¨¡£ËæÖ®¶øÀ´µÄÎÊÌ⣺ÈçºÎ½«HTML±£´æΪͼƬÄØ£¿
Èý¡¢ ½â¾ö°ì·¨£º
1¡¢ ½«HTML±£´æΪͼƬ£ºÐèÒªÓõ½webbrowerÀ࣬½«Ö¸¶¨µÄHTMLÔØÈëwebbrower£¬È»ºóµ÷ÓÃÆäDrawToBitmap·½·¨»ñȡͼƬ¡£´úÂëÈçÏ£º
private System.Drawing.Bitmap bitmap;
private string url;
private int w = 760, h = 900;//A4Ö½ÕŶÔÓ¦µÄ·Ö±æÂÊ´ó¸Å¾ÍÊÇ760*900
public void setBitmap()
{
using (WebBrowser wb = new WebBrowser())
{
wb.Width = w;
wb.Height = h;
wb.ScrollBarsEnabled = false;
wb.Navigate(url);
//È·±£Ò³Ãæ±»½âÎöÍêÈ«
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
bitmap = new System.Drawing.Bitmap(w, h);
wb.DrawToBitmap(bitmap, new
Ïà¹ØÎĵµ£º
I always consider the coolitm control only can use its control tag in its body.
But I found that it can use html tag ,this very good.
so I show the sample to other:
<ext:Window
ID="Window1"
runat="server"
Width="500"
Height="485"
......
1.wkhtmltopdf http://code.google.com/p/wkhtmltopdf/downloads/list
ÈçlinuÏÂÔØwkhtmltopdf-0.9.6-static-i386.tar.bz2
2. tar -jxvf wkhtmltopdf-0.9.6-static-i386.tar.bz2
3¡£ÖØÃüÃû mv wkhtmltopdf-i386 wkhtmltopdf
4.²âÊÔÉú³Épdf ./wkhtm ......
C# Delphi´¦Àí·ÖÎöQQÐÒé
¡¡´ó¼Ò˵µ½QQÐÒ鶼¾õµÃºÜÉñÃØ£¬ÊÇÒòΪQQ²»ÏñMSN»òÕßICQÐÒ鶼ÒѾ¹Ù·½¹«²¼ÁË£¬¶øQQµÄûÓй«²¼¡£Ñо¿ËüµÄÈËÒ²²»ÊÇÌرðµÄ¶à£¬ËäÈ»ÒѾÓÐÁË»ùÓÚ QQÐÒéËùд³ÉµÄµÚÈý·½Èí¼þ foicq, qq plugins for gaim, LumaQQ£¬µ«ÊÇÓÉÓÚËûÃÇÊÇ»ùÓÚ¶þ½øÖÆStreamµÄÐÒé¹ýÓÚ¸´ÔÓ£¬´ó¼ÒÔĶÁ´úÂëÒ²ÓÐÒ ......
<form action="#" method="get">ÕâÀïÊÇ±íµ¥µÄÄÚÈÝ</form>
<form action="#" method="post">ÕâÀïÊÇ±íµ¥µÄÄÚÈÝ</form>
ÊôÐÔ"action",ÀïÃæÉèÖõÄÊÇ±íµ¥Ìá½»µÄ·¾¶.Ò»¸ö¶ÔÏó,°×»°ÎĵĽâÊÍ:±íµ¥½»¸øÁËË.
ÊôÐÔ"method",ÀïÃæÉèÖõÄÊÂ±íµ¥Ìá½»µÄ·½Ê½,Ò»ÖÖ·½·¨,°×»°ÎĽâÊÍ:ÒªÔõÑùÌá½»Õâ¸ö±íµ¥,ÊÇÎÒÖ±½Óà ......
<html>
<head>
<mce:style type = "text/css"><!--
table
{
border-collapse:collapse;
}
td
{
border:solid 1px black;
}
--></mce:style><style type = "text/css" mce_bogus="1">table
{
border-collapse:collapse;
}
td
......