又仔细看了下,iTextSharp的标准例子程序里的第7章有你要的东西Chap0707 chap0708(Chapter 7 example 8: HTML and CSS),我想几个例子结合研究下应该可以满足你的要求。
我也没做过,具体的不是很清楚,但是http://threebit.net/mail-archive/itext-questions/msg01033.html这个是一个html 2 pdf的例子,我还试验了下,效果还不错,不过不能处理css,但是css处理iTextSharp的标准例子程序里的第7章有你要的东西Chap0707 chap0708(Chapter 7 example 8: HTML and CSS)里边有,所以让你结合看一下,我也没弄过,我就不帮你仔细研究了。 只能给你提示,反正目前看下来,itextsharp功能还是比较强大的,另外推荐一个强人的blog给你http://www.cnblogs.com/hardrock/default.html?page=1,这个人应该是IText中国这边的最主要代表人物
Doc Converter COM Component
http://www.verypdf.com/pdfcamp/doc2pdf_readme.html
or use the html2pdf services at
http://html2pdf.seven49.net/
see
http://authors.aspalliance.com/articles/renderpdf.aspx
http://authors.aspalliance.com/articles/refer2pdfVBNET.html
namespace Com.Vervidian.TIO.Calculator.model
{
public class PdfHelper : IDisposable
{
#region IDisposable Members public void Dispose()
{
} #endregion public static byte[] GetBytes(string htmlContext)
{
return PdfBytes(new StringBuilder(htmlContext), false);
}
public static void PDFsave(StringBuilder htmlcontext, string savepath)
{
using (Doc pdf = new Doc())
{
int pdfId = 0;
pdf.HPos = .3;
pdf.VPos = .5;
double scale = .8;
int x = 30;
int y = 30;
pdf.Rect.Magnify(1 / scale, 1 / scale);
pdf.Transform.Magnify(scale, scale, 0, 0);
pdf.Rect.Width = 900;
pdf.Rect.Inset(x, y);
try
{
pdfId = pdf.AddImageHtml(htmlcontext.ToString());
while (pdf.Chainable(pdfId))
{
pdf.Page = pdf.AddPage();
pdfId = pdf.AddImageToChain(pdfId);
}
for (int i = 0; i < pdf.PageCount - 1; i++)
{
pdf.PageNumber = i;
pdf.Flatten();
} pdf.Save(savepath);
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdf.Delete(pdfId);
pdf.Clear();
}
}
} public static void PDFsave(StringBuilder htmlcontext, string savepath, bool bLandscape)
{
using (Doc pdf = new Doc())
{
int pdfId = 0;
pdf.HPos = .3;
pdf.VPos = .5;
double scale = .8;
int x = 30;
int y = 30;
pdf.Rect.Magnify(1 / scale, 1 / scale);
pdf.Transform.Magnify(scale, scale, 0, 0);
pdf.Rect.Width = 900;
pdf.Rect.Inset(x, y); if (bLandscape)
{
Lanscape(pdf);
} pdf.Rect.Inset(x, y);
try
{
pdfId = pdf.AddImageHtml(htmlcontext.ToString());
while (pdf.Chainable(pdfId))
{
pdf.Page = pdf.AddPage();
pdfId = pdf.AddImageToChain(pdfId);
}
for (int i = 0; i < pdf.PageCount - 1; i++)
{
pdf.PageNumber = i;
pdf.Flatten();
} pdf.Save(savepath);
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdf.Delete(pdfId);
pdf.Clear();
}
}
} public static byte[] PdfBytes(StringBuilder htmlcontext)
{
using (Doc pdf = new Doc())
{
int pdfId = 0;
pdf.HPos = .3;
pdf.VPos = .5;
double scale = .8;
int x = 30;
int y = 30;
pdf.Rect.Magnify(1 / scale, 1 / scale);
pdf.Transform.Magnify(scale, scale, 0, 0);
pdf.Rect.Width = 900;
pdf.Rect.Inset(x, y);
byte[] temp;
try
{
pdfId = pdf.AddImageHtml(htmlcontext.ToString());
while (pdf.Chainable(pdfId))
{
pdf.Page = pdf.AddPage();
pdfId = pdf.AddImageToChain(pdfId);
}
for (int i = 0; i < pdf.PageCount - 1; i++)
{
pdf.PageNumber = i;
pdf.Flatten();
}
temp = pdf.GetData();
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdf.Delete(pdfId);
pdf.Clear();
}
return temp;
}
} public static byte[] PdfBytes(StringBuilder htmlcontext, bool bLandscape)
{
using (Doc pdf = new Doc())
{
int pdfId = 0;
pdf.HPos = .3;
pdf.VPos = .5;
double scale = .8;
int x = 30;
int y = 30;
pdf.Rect.Magnify(1 / scale, 1 / scale);
pdf.Transform.Magnify(scale, scale, 0, 0);
pdf.Rect.Width = 900;
pdf.Rect.Inset(x, y);
if (bLandscape)
{
Lanscape(pdf);
}
byte[] temp;
try
{
pdfId = pdf.AddImageHtml(htmlcontext.ToString());
while (pdf.Chainable(pdfId))
{
pdf.Page = pdf.AddPage();
pdfId = pdf.AddImageToChain(pdfId);
}
for (int i = 0; i < pdf.PageCount - 1; i++)
{
pdf.PageNumber = i;
pdf.Flatten();
}
temp = pdf.GetData();
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdf.Delete(pdfId);
pdf.Clear();
}
return temp;
}
} public static void PDFsave(byte[] data, string savepath)
{
using (Doc pdf = new Doc())
{
int pdfId = 0;
try
{
pdf.Read(data);
pdf.Save(savepath);
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdf.Delete(pdfId);
pdf.Clear();
}
}
} public static void Lanscape(Doc pdf)
{ double w = pdf.MediaBox.Width;
double h = pdf.MediaBox.Height;
double My = (w - h) > 0 ? (w - h) : -1 * (w - h); pdf.Transform.Rotate(90, 100 * 3 / 4, 100);
pdf.Transform.Translate(w, My / 10);
}
}
}
http://geekswithblogs.net/casualjim/articles/59943.aspx
可能对你有帮助
只能给你提示,反正目前看下来,itextsharp功能还是比较强大的,另外推荐一个强人的blog给你http://www.cnblogs.com/hardrock/default.html?page=1,这个人应该是IText中国这边的最主要代表人物