if (FormFields["COM_FORMNO"].Length > 0)
{
DataTable dt = new DataTable();
using (WF_SampleV5Service service = new WF_SampleV5Service(WFConn))
dt = service.GetReport(FormFields["COM_FORMNO"]);
try
{
oPage = (Page)oContainer;
//有用,关于 认证 暂不可删除
String AsposeLicPath = String.Empty;
if (System.Configuration.ConfigurationManager.AppSettings["DocLicPath"] == null)
throw new Exception("Please setup [AsposeLicPath] in Web.Config!");
else
AsposeLicPath = System.Configuration.ConfigurationManager.AppSettings["DocLicPath"];

Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(AsposeLicPath);

Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc);
for (int i = 0; i < dt.Rows.Count; i++)
{
db.PageSetup.HeaderDistance = 0;
db.PageSetup.FooterDistance = 0;
db.PageSetup.PageWidth = Convert.ToInt32(ConfigurationManager.AppSettings["PageWidth"].ToString());
db.PageSetup.PageHeight = Convert.ToInt32(ConfigurationManager.AppSettings["PageHeight"].ToString());
db.PageSetup.LeftMargin = 10;
db.PageSetup.TopMargin = 5;
db.PageSetup.RightMargin = 5;
db.PageSetup.BottomMargin = 5;
db.PageSetup.VerticalAlignment = Aspose.Words.PageVerticalAlignment.Center;

db.StartTable();
db.InsertCell();
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["TableWidth"].ToString());
db.Write("LITEON");
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center;
db.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
db.Font.Size = 14;
db.Font.Bold = true;
db.EndRow();

db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight2"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth1"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
db.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
db.Write("品名規格");
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight2"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth4"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Top;
db.Write(dt.Rows[i]["Standard"].ToString());
db.EndRow();

db.InsertCell();
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth1"].ToString());
db.Font.Size = 12;
db.Font.Bold = false;
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
db.Write("料號");
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth2"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write(dt.Rows[i]["MaterialNO"].ToString());
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth3"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write("口CE:");
db.EndRow();

db.InsertCell();
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth1"].ToString());
db.Font.Size = 12;
db.Font.Bold = false;
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
db.Write("日期");
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth2"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write(dt.Rows[i]["IssueDate"].ToString());
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth3"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write("口EE:");
db.EndRow();

db.InsertCell();
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth1"].ToString());
db.Font.Size = 12;
db.Font.Bold = false;
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
db.Write("廠商");
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth2"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write(dt.Rows[i]["Supplier"].ToString());
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth3"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write("口ME:");
db.EndRow();

db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth1"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
db.Write("編號");
db.InsertCell();
db.Font.Size = 12;
db.Font.Bold = false;
db.RowFormat.Height = Convert.ToInt32(ConfigurationManager.AppSettings["RowHeight1"].ToString());
db.CellFormat.Width = Convert.ToInt32(ConfigurationManager.AppSettings["ColWidth4"].ToString());
db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
db.Write(dt.Rows[i]["AcceptNO"].ToString());
db.EndRow();
db.EndTable();
}

Aspose.Words.Saving.PdfSaveOptions pdfSO = new Aspose.Words.Saving.PdfSaveOptions();
pdfSO.ZoomBehavior = Aspose.Words.Saving.PdfZoomBehavior.ZoomFactor;
//doc.Save(oPage.Response, HttpUtility.UrlEncode("(SampleFormUIShadow)UIShadow.pdf"), Aspose.Words.ContentDisposition.Attachment, pdfSO);
oPage.EnableViewState = false;
MemoryStream pdfdata = new MemoryStream();
doc.Save(pdfdata, pdfSO);
oPage.Response.Clear();
oPage.Response.ClearContent();
oPage.Response.ClearHeaders();
oPage.Response.ContentType = "application/pdf";
oPage.Response.Charset = string.Empty;
oPage.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
oPage.Response.AddHeader("Content-Disposition", "inline; filename=SampleIssue.pdf");

oPage.Response.OutputStream.Write(pdfdata.GetBuffer(), 0, pdfdata.GetBuffer().Length);
oPage.Response.OutputStream.Flush();
oPage.Response.OutputStream.Close();

oPage.Response.Flush();
oPage.Response.Close();
}
catch (Exception ex)
{
//写 将因为模板 版本过高造成的错误写入log,便于 IT 同仁查错
if (ex.Message.Contains("document appears to be corrupted and cannot be loaded."))
{
}
else
{
}

throw ex;
}
}

posted on 2022-02-27 11:41  Hawk_Yuan  阅读(238)  评论(0编辑  收藏  举报