需要现在服务器安装 abcpdf
先 using WebSupergoo.ABCpdf7;
string fileToSave = System.Web.HttpContext.Current.Server.MapPath("pdf保存路径");
Doc theDoc = new Doc();
XSettings.License = "XXX";//许可号 应该可以不填
theDoc.Font = theDoc.AddFont("宋体");
/*
theDoc.MediaBox.String = "0 0 590 840";
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
//要是横着打印就注解下面代码
// theDoc.Transform.Rotate(90, 1, b);
// theDoc.Transform.Translate(w, 0);
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
*/
// add some text
theDoc.Rect.Inset(15, 0);
string pageBreak = "<div style=\"page-break-before:always\"> </div> ";
string content = Literal1.Text.ToString();
content += pageBreak ;
int theID = theDoc.AddImageHtml(content);
while (true)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
theDoc.SetInfo(theID, "/Rotate", "90");
theDoc.Save(fileToSave);
theDoc.Dispose();
//---------------------------------------------------
Response.ContentType = "Application/pdf";
// string FilePath = pdfFile;
Response.WriteFile(fileToSave);
Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();