本文整理汇总了C#中iTextSharp.text.Document.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Dispose方法的具体用法?C# Document.Dispose怎么用?C# Document.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.Dispose方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisposePdf
/// <summary>
/// 关闭PDF文档流
/// </summary>
/// <param name="doc"></param>
public void DisposePdf(Document doc)
{
if (doc.IsOpen())
{
doc.Close();
}
doc.Dispose();
}
示例2: GeneralLetter
public void GeneralLetter(String CreditControlID)
{
try
{
BillCreditControlList Vwobj = new BillCreditControlList();
Vwobj = BAL.BillCreditControlModel.ViewCreditControlReminderLetter(CreditControlID);
if (Vwobj != null)
{
var document = new Document(PageSize.A4, 50, 50, 25, 25);
String PDFName = Vwobj.BillNo + "-" + Vwobj.ID.ToString() + ".pdf";
var filePath = Path.Combine(Server.MapPath("~/PdfContent/CreditControl/Letter"), PDFName);
// var output = new MemoryStream();
var output = new FileStream(filePath, FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
try
{
// Open the Document for writing
document.Open();
// Read in the contents of the Receipt.htm file...
StyleSheet styles = new StyleSheet();
//styles.LoadTagStyle(HtmlTags.H1, HtmlTags.FONTSIZE, "16");
//styles.LoadTagStyle(HtmlTags.P, HtmlTags.FONTSIZE, "10");
//styles.LoadTagStyle(HtmlTags.P, HtmlTags.m, "#ff0000");
//styles.LoadTagStyle(HtmlTags.CLASS, HtmlTags.COLOR, "#ff0000");
styles.LoadTagStyle(HtmlTags.TD, HtmlTags.ALIGN, "left");
styles.LoadTagStyle(HtmlTags.TD, HtmlTags.CELLPADDING, "10");
styles.LoadTagStyle(HtmlTags.P, HtmlTags.P, "margin-bottom:20px");
styles.LoadTagStyle(HtmlTags.P, HtmlTags.SPAN, "text-decoration:underline;");
styles.LoadStyle("Subject", "ALIGN", "center");
styles.LoadStyle("Subject", "FONTSIZE", "26px");
styles.LoadStyle("Subject", "color", "#ff0000");
styles.LoadStyle("c_outstanding", "font-size", "20px");
styles.LoadStyle("c_outstanding", "text-align", "center");
String contents = System.IO.File.ReadAllText(Server.MapPath("~/HTMLTemplate/GeneralLetter.htm"));
// Replace the placeholders with the user-specified text
contents = contents.Replace("[CustomerName]", Vwobj.ConsumerName.Trim());
contents = contents.Replace("[AddressLine1]", Vwobj.ConsumerAddress.Trim());
contents = contents.Replace("[AddressLine2]", Vwobj.ConsumerCounty.Trim());
contents = contents.Replace("[AddressLine3]", Vwobj.ConsumerCity.Trim());
contents = contents.Replace("[PostCode]", Vwobj.ConsumerZipCode.Trim());
contents = contents.Replace("[Amount]", Vwobj.LastBillAmount.ToString().Trim());
//' contents = contents.Replace("[propertyAddress]", Vwobj.PropertyNo.Trim());
contents = contents.Replace("[sitename]", Vwobj.SiteName.Trim());
contents = contents.Replace("[balanceofaccount]", Vwobj.Balance.ToString());
contents = contents.Replace("[invoicedateFrom]", Vwobj.InvoiceDateForm);
contents = contents.Replace("[invoicedateTo]", Vwobj.InvoiceDateTo);
contents = contents.Replace("[InvioceDate]", Vwobj.InvoiceDate);
contents = contents.Replace("[ClientName]", Vwobj.ClientName);
contents = contents.Replace("[ClientTelephoneNumber]", Vwobj.ClientTelephone);
contents = contents.Replace("[ClientEmailAddress]", Vwobj.ClientEmail);
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), styles);
// Enumerate the elements, adding each one to the Document...
foreach (var htmlElement in parsedHtmlElements)
{
document.Add(htmlElement as IElement);
}
writer.CloseStream = false;
document.Close();
output.Dispose();
}
catch (Exception ex)
{
output.Dispose();
document.Dispose();
}
}//if
}//try
catch (Exception ex)
{
throw;
}
}
示例3: GenerateReminder1
//.........这里部分代码省略.........
}
if (Vwobj.BankTransfer == "1")
{
PaymentList.Append("<td valign='top'>");
String BankTransferImg = "<img src='" + Server.MapPath("~/Images/bank_transfer_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(BankTransferImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Our account details for Bank Transfers: ");
if (Vwobj.SortCode != null)
{
PaymentList.Append("Sort Code " + Vwobj.SortCode);
}
if (Vwobj.ClientBankAccountNo != null)
{
PaymentList.Append(" Account Number ");
PaymentList.Append(Vwobj.ClientBankAccountNo != null?Vwobj.ClientBankAccountNo :"");
}
PaymentList.Append("</td>");
}
if (Vwobj.TelephonePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String telephonepaypngImg = "<img src='" + Server.MapPath("~/Images/telephone_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(telephonepaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card by calling ");
PaymentList.Append(Vwobj.TemplateTelephone != null? Vwobj.TemplateTelephone:"");
PaymentList.Append("</td>");
}
if (Vwobj.OnlinePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlinePaypngImg = "<img src='" + Server.MapPath("~/Images/online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlinePaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card. Visit your online account for App and SMS details");
PaymentList.Append("</td>");
}
if (Vwobj.OnlineNTelephonePay == "1")
{
PaymentList.Append("<td valign='top' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlineNTelephonePayImg = "<img src='" + Server.MapPath("~/Images/telephone_online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlineNTelephonePayImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card calling ");
PaymentList.Append(Vwobj.TemplateTelephone != null?Vwobj.TemplateTelephone :"" );
PaymentList.Append(" visit www.mysycous.com</td>");
}
contents = contents.Replace("[PaymentOption]", PaymentList.ToString());
// Step 4: Parse the HTML string into a collection of elements...
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), styles);
// Enumerate the elements, adding each one to the Document...
foreach (var htmlElement in parsedHtmlElements)
{
document.Add(htmlElement as IElement);
}
writer.CloseStream = false;
document.Close();
output.Dispose();
//Get the pointer to the beginning of the stream.
// output.Position = 0;
// MailCls email = new MailCls();
// email.EmailTo = "[email protected]";
//// email.EmailTo = "[email protected]";
// email.EmailSubject = "Reminder Letter 1";
// email.Body = " Plz check It";
// email.DispalyName = "sarajit";
// email.Attachment = 0;
// email.stream = output;
// email.Email_Sent();
// output.Dispose();
// document.Dispose();
}
catch (Exception ex)
{
output.Dispose();
document.Dispose();
}
}//if
}//try
catch (Exception ex)
{
throw;
}
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null)
{
string tType = Request.Form["type"].ToString();
string tSvg = Request.Form["svg"].ToString();
string tFileName = Request.Form["filename"].ToString();
if (tFileName == "")
{
tFileName = "chart";
}
string tTmp = new Random().Next().ToString();
string tExt = "";
string tTypeString = "";
switch (tType)
{
case "image/png":
tTypeString = "-m image/png";
tExt = "png";
break;
case "image/jpeg":
tTypeString = "-m image/jpeg";
tExt = "jpg";
break;
case "application/pdf":
tTypeString = "-m application/pdf";
tExt = "pdf";
break;
case "image/svg+xml":
tTypeString = "-m image/svg+xml";
tExt = "svg";
break;
}
string tSvgOuputFile = tTmp + "." + "svg";
string tOutputFile = tTmp + "." + tExt;
if (tTypeString != "")
{
string tWidth = Request.Form["width"].ToString();
//WRITING SVG TO DISK
StreamWriter tSw = new StreamWriter(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
tSw.Write(tSvg);
tSw.Close();
tSw.Dispose();
Svg.SvgDocument tSvgObj = SvgDocument.Open(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
switch (tExt)
{
case "jpg":
tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, ImageFormat.Jpeg);
//DELETING SVG FILE
if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile))
{
File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
}
break;
case "png":
tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, ImageFormat.Png);
//DELETING SVG FILE
if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile))
{
File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
}
break;
case "pdf":
PdfWriter tWriter = null;
Document tDocumentPdf = null;
try
{
// First step saving png that would be used in pdf
tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png", ImageFormat.Png);
// Creating pdf document
tDocumentPdf = new Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height));
// setting up margin to full screen image
tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);
// creating image
iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png");
tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height);
// Insert content
tWriter = PdfWriter.GetInstance(tDocumentPdf, new FileStream(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, FileMode.Create));
tDocumentPdf.Open();
tDocumentPdf.NewPage();
tDocumentPdf.Add(tGraph);
tDocumentPdf.CloseDocument();
// deleting png
if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png"))
{
File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png");
//.........这里部分代码省略.........
示例5: ExecuteResult
/// <summary>
/// ExecuteResult
/// </summary>
/// <param name="context"></param>
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = "application/pdf";
if (Download)
context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
Html = RenderRazorViewToString(context);
Format(context.HttpContext);
using (var document = new Document(Settings.PageSize, Settings.Margin.Left, Settings.Margin.Right, Settings.Margin.Top, Settings.Margin.Bottom))
{
var memoryStream = new MemoryStream();
TextReader textReader = new StringReader(Html);
var pdfWriter = PdfWriter.GetInstance(document, memoryStream);
var htmlPipelineContext = new HtmlPipelineContext(null);
var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
document.Open();
FontFactory.RegisterDirectories();
htmlPipelineContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
foreach (var styleSheet in StyleSheets)
{
cssResolver.AddCssFile(context.HttpContext.Server.MapPath(styleSheet), true);
}
var pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlPipelineContext, new PdfWriterPipeline(document, pdfWriter)));
var worker = new XMLWorker(pipeline, true);
var xmlParse = new XMLParser(true, worker);
xmlParse.Parse(textReader);
xmlParse.Flush();
document.Close();
document.Dispose();
context.HttpContext.Response.BinaryWrite(memoryStream.ToArray());
}
context.HttpContext.Response.End();
context.HttpContext.Response.Flush();
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null)
{
string tType = Request.Form["type"].ToString();
string tSvg = Request.Form["svg"].ToString();
string tFileName = Request.Form["filename"].ToString();
if (tFileName == "") tFileName = "chart";
MemoryStream data = new MemoryStream(Encoding.ASCII.GetBytes(tSvg));
MemoryStream stream = new MemoryStream();
switch (tType)
{
case "image/png":
tFileName += ".png";
SvgDocument.Open(data).Draw().Save(stream, ImageFormat.Png);
break;
case "image/jpeg":
tFileName += ".jpg";
SvgDocument.Open(data).Draw().Save(stream, ImageFormat.Jpeg);
break;
case "image/svg+xml":
tFileName += ".svg";
stream = data;
break;
case "application/pdf":
tFileName += ".pdf";
PdfWriter tWriter = null;
Document tDocumentPdf = null;
try
{
SvgDocument tSvgObj = SvgDocument.Open(data);
tSvgObj.Draw().Save(stream, ImageFormat.Png);
// Creating pdf document
tDocumentPdf = new Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height));
// setting up margin to full screen image
tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);
// creating image
iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(stream.ToArray());
tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height);
stream = new MemoryStream();
// create writer
tWriter = PdfWriter.GetInstance(tDocumentPdf, stream);
tDocumentPdf.Open();
tDocumentPdf.NewPage();
tDocumentPdf.Add(tGraph);
tDocumentPdf.CloseDocument();
tDocumentPdf.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
tDocumentPdf.Close();
tDocumentPdf.Dispose();
tWriter.Close();
tWriter.Dispose();
}
break;
}
if (stream != null)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = tType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + tFileName);
Response.BinaryWrite(stream.ToArray());
Response.End();
}
}
}
}
示例7: runInDebugMode
private void runInDebugMode()
{
PdfDoc = new Document(DocumentSettings.GetPageSizeAndColor(_pdfRptData.DocumentPreferences),
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Left,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Right,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Top,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Bottom);
createPdf();
PdfDoc.Dispose();
}
示例8: PDF
//.........这里部分代码省略.........
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasTuesday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaEntradaWendnsday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaSalidaWendnsday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasWendnsday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaEntradaThursday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaSalidaThursday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasThursday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaEntradaFriday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaSalidaFriday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasFriday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaEntradaSaturday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaSalidaSaturday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasSaturday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaEntradaSunday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase(Convert.ToDateTime(item.FechaSalidaSunday).ToShortTimeString().ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
cell.Phrase = new Phrase((item.HorasSunday).ToString());
cell.HorizontalAlignment = 1;
table.AddCell(cell);
// DateTime d1 = DateTime.Parse(Convert.ToDateTime(item.HorasMonday).ToString());
//DateTime d2 = DateTime.Parse(Convert.ToDateTime(item.HorasMonday).ToString());
// double span = (d1 - d2).TotalHours;
cell.Phrase = new Phrase(Convert.ToString(Convert.ToDecimal(item.HorasMonday) + Convert.ToDecimal(item.HorasTuesday) + Convert.ToDecimal(item.HorasWendnsday) + Convert.ToDecimal(item.HorasThursday) + Convert.ToDecimal(item.HorasFriday) + Convert.ToDecimal(item.HorasSaturday) + Convert.ToDecimal(item.HorasSunday)));
cell.HorizontalAlignment = 1;
table.AddCell(cell);
//table.Rows.Add(cell);
//
}
// document.Add(table);
document.Add(table);
document.Close();
document.Dispose();
writer.Close();
output.Close();
}
catch (Exception)
{
}
// DateTime date =Convert.ToDateTime(Convert.ToDateTime("09-21-2015")).ToShortDateString();
}
}
// var output = new MemoryStream();
}
}
示例9: runInDebugMode
private byte[] runInDebugMode()
{
byte[] data;
try
{
PdfDoc = new Document(DocumentSettings.GetPageSizeAndColor(_pdfRptData.DocumentPreferences),
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Left,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Right,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Top,
_pdfRptData.DocumentPreferences.PagePreferences.Margins.Bottom);
data = createPdf();
}
finally
{
PdfDoc.Dispose();
}
return data;
}
示例10: NewBillPDF
//.........这里部分代码省略.........
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append(" Pay by Cash at any PayZone outlet using your payment card</td>");
}
if (Bill.PostOffice == "1")
{
PaymentList.Append("<td valign='top' style='font-size:10px; text-align:center; padding:10px;'>");
String PostOfficeImg = "<img src='" + Server.MapPath("~/Images/payment_card_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(PostOfficeImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append(" Pay by Cash at any Post Office branch using your payment card</td>");
}
if (Bill.BankTransfer == "1")
{
PaymentList.Append("<td valign='top'>");
String BankTransferImg = "<img src='" + Server.MapPath("~/Images/bank_transfer_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(BankTransferImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Our account details for Bank Transfers: ");
if (Bill.SortCode != null)
{
PaymentList.Append("Sort Code " + Bill.SortCode);
}
if (Bill.ClientBankAccountNo != null)
{
PaymentList.Append(" Account Number ");
PaymentList.Append(Bill.ClientBankAccountNo);
}
PaymentList.Append("</td>");
}
if (Bill.TelephonePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String telephonepaypngImg = "<img src='" + Server.MapPath("~/Images/telephone_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(telephonepaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card by calling ");
PaymentList.Append(Bill.TemplateTelephone);
PaymentList.Append("</td>");
}
if (Bill.OnlinePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlinePaypngImg = "<img src='" + Server.MapPath("~/Images/online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlinePaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card. Visit your online account for App and SMS details");
PaymentList.Append("</td>");
}
if (Bill.OnlineNTelephonePay == "1")
{
PaymentList.Append("<td valign='top' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlineNTelephonePayImg = "<img src='" + Server.MapPath("~/Images/telephone_online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlineNTelephonePayImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card calling ");
PaymentList.Append(Bill.TemplateTelephone);
PaymentList.Append(" visit www.mysycous.com</td>");
}
contents = contents.Replace("[PaymentOption]", PaymentList.ToString());
// document.NewPage();
// Step 4: Parse the HTML string into a collection of elements...
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), styles);
// Enumerate the elements, adding each one to the Document...
foreach (var htmlElement in parsedHtmlElements)
{
document.Add(htmlElement as IElement);
}
// writer.CloseStream = false;
document.Close();
writer.Close();
byte[] file = workStream.ToArray();
MemoryStream output = new MemoryStream();
output.Write(file, 0, file.Length);
output.Position = 0;
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-disposition", "attachment; filename=" + PDFName + ""); // open in a new window
Response.OutputStream.Write(output.GetBuffer(), 0, output.GetBuffer().Length);
Response.Flush();
}
catch (Exception ex)
{
//workStream.Dispose();
//output.Dispose();
document.Dispose();
}
}
示例11: GenerateEmail
//.........这里部分代码省略.........
PaymentList.Append("<td valign='top' style='font-size:10px; text-align:center; padding:10px;'>");
String PostOfficeImg = "<img src='" + Server.MapPath("~/Images/payment_card_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(PostOfficeImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append(" Pay by Cash at any Post Office branch using your payment card</td>");
}
if (Bill.BankTransfer == "1")
{
PaymentList.Append("<td valign='top'>");
String BankTransferImg = "<img src='" + Server.MapPath("~/Images/bank_transfer_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(BankTransferImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Our account details for Bank Transfers: ");
if (Bill.SortCode != null)
{
PaymentList.Append("Sort Code " + Bill.SortCode);
}
if (Bill.ClientBankAccountNo != null)
{
PaymentList.Append(" Account Number ");
PaymentList.Append(Bill.ClientBankAccountNo);
}
PaymentList.Append("</td>");
}
if (Bill.TelephonePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String telephonepaypngImg = "<img src='" + Server.MapPath("~/Images/telephone_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(telephonepaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card by calling ");
PaymentList.Append(Bill.TemplateTelephone);
PaymentList.Append("</td>");
}
if (Bill.OnlinePay == "1")
{
PaymentList.Append("<td valign='top' align='center' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlinePaypngImg = "<img src='" + Server.MapPath("~/Images/online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlinePaypngImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card. Visit your online account for App and SMS details");
PaymentList.Append("</td>");
}
if (Bill.OnlineNTelephonePay == "1")
{
PaymentList.Append("<td valign='top' style='font-size:10px; text-align:center; padding:10px;'>");
String OnlineNTelephonePayImg = "<img src='" + Server.MapPath("~/Images/telephone_online_pay_pdf.png") + "' height='30' alt=' '>";
PaymentList.Append(OnlineNTelephonePayImg);
PaymentList.Append("<div style='clear:both'></div>");
PaymentList.Append("Pay by Credit or Debit Card calling ");
PaymentList.Append(Bill.TemplateTelephone);
PaymentList.Append(" visit www.mysycous.com</td>");
}
contents = contents.Replace("[PaymentOption]", PaymentList.ToString());
// document.NewPage();
// Step 4: Parse the HTML string into a collection of elements...
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), styles);
// Enumerate the elements, adding each one to the Document...
foreach (var htmlElement in parsedHtmlElements)
{
document.Add(htmlElement as IElement);
}
writer.CloseStream = false;
document.Close();
output.Dispose();
BAL.BillModel.BillSendByMail(DecBill);
}
catch (Exception ex)
{
output.Dispose();
document.Dispose();
return Content(ex.Message.ToString());
}
//-------------------------------------------------------------------------------
return RedirectToAction("Index", "Bill");
}
else
{ return Content("Select View Of Bill "); }
}
catch (Exception ex)
{
return Content("ERROR :" + ex.Message);
}
}
else
{
return RedirectToAction("Index", "Home");
}
}
示例12: SplitWorkerDoWork
private void SplitWorkerDoWork(object sender, DoWorkEventArgs e)
{
object[] args = (object[])e.Argument;
PdfFile pdfFile = (PdfFile)args[0];
PageRangeParser pageRangeParser = (PageRangeParser)args[1];
string destinationPath = (string)args[2];
bool overwriteFile = (bool)args[3];
FileStream outFileStream = null;
Document destinationDoc = null;
PdfCopy pdfCopy = null;
int skippedFiles = 0;
string exportFileName = string.Empty;
string errorMsg = string.Empty;
int exportFileCnt = 0, totalNumberOPages = 0, pageCnt = 0;
EasySplitAndMergePdf.Helper.PageRange[] pageRanges = null;
if (pageRangeParser.TryParse(out pageRanges) != Define.Success)
{
errorMsg = "An error occurred while parsing PDF page ranges" + pageRangeParser.ErrorMsg;
}
else if ((totalNumberOPages = pageRanges.Sum(range => range.PageCount)) < 1)
{
errorMsg = "The number of PDF pages to extract from source file is zero.";
}
else
{
pdfFile.Reader.RemoveUnusedObjects();
while (exportFileCnt < pageRanges.Length && !splitBackgroundWorker.CancellationPending)
{
exportFileName = destinationPath + (exportFileCnt + 1).ToString("D4") + ".pdf";
if (FileHelpers.FileIsAvailable(exportFileName, overwriteFile, out outFileStream, out errorMsg) == Define.Success)
{
destinationDoc = new Document();
pdfCopy = new PdfCopy(destinationDoc, outFileStream);
destinationDoc.Open();
splitBackgroundWorker.ReportProgress(pageCnt * 100 / totalNumberOPages,
string.Format("Creating and processing PDF file: {0}", exportFileName));
if (pageRanges[exportFileCnt].Pages != null)
{
int pageArrayIndex = 0;
while (pageArrayIndex < pageRanges[exportFileCnt].Pages.Length &&
!splitBackgroundWorker.CancellationPending)
{
destinationDoc.SetPageSize(pdfFile.Reader.GetPageSizeWithRotation(pageRanges[exportFileCnt].Pages[pageArrayIndex]));
destinationDoc.NewPage();
pdfCopy.AddPage(pdfCopy.GetImportedPage(pdfFile.Reader, pageRanges[exportFileCnt].Pages[pageArrayIndex]));
splitBackgroundWorker.ReportProgress(++pageCnt * 100 / totalNumberOPages);
pageArrayIndex++;
}
}
else if (pageRanges[exportFileCnt].PageFrom <= pageRanges[exportFileCnt].PageTo)
{
int pageNumber = pageRanges[exportFileCnt].PageFrom;
while (pageNumber <= pageRanges[exportFileCnt].PageTo &&
!splitBackgroundWorker.CancellationPending)
{
destinationDoc.SetPageSize(pdfFile.Reader.GetPageSizeWithRotation(pageNumber));
destinationDoc.NewPage();
pdfCopy.AddPage(pdfCopy.GetImportedPage(pdfFile.Reader, pageNumber));
splitBackgroundWorker.ReportProgress(++pageCnt * 100 / totalNumberOPages);
pageNumber++;
}
}
else if (pageRanges[exportFileCnt].PageFrom > pageRanges[exportFileCnt].PageTo)
{
int pageNumber = pageRanges[exportFileCnt].PageFrom;
while (pageNumber >= pageRanges[exportFileCnt].PageTo &&
!splitBackgroundWorker.CancellationPending)
{
destinationDoc.SetPageSize(pdfFile.Reader.GetPageSizeWithRotation(pageNumber));
destinationDoc.NewPage();
pdfCopy.AddPage(pdfCopy.GetImportedPage(pdfFile.Reader, pageNumber));
splitBackgroundWorker.ReportProgress(++pageCnt * 100 / totalNumberOPages);
pageNumber--;
}
}
//Exception on document.Close() when doc is empty
//if (pages.Count == 0) { throw new IOException("The document has no pages.") };
//When canceling pages.Count could be zero therefore skip cleanup.
if (destinationDoc != null &&
!splitBackgroundWorker.CancellationPending)
{
destinationDoc.Close();
destinationDoc.Dispose();
destinationDoc = null;
}
if (pdfCopy != null &&
!splitBackgroundWorker.CancellationPending)
{
pdfCopy.Close();
pdfCopy.Dispose();
pdfCopy = null;
}
if (outFileStream != null)
//.........这里部分代码省略.........
示例13: MergePDFs
public string MergePDFs(string[] transids)
{
string targetPDF = "PaymentReceipts" + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString() + ".pdf";
targetPDF = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\PDF\\" + targetPDF;
using (FileStream stream = new FileStream(targetPDF, FileMode.Create))
{
Document pdfDoc = new Document();
PdfCopy pdf = new PdfCopy(pdfDoc, stream);
pdfDoc.Open();
var files = Directory.GetFiles(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\PDF\\Temp\\");
Console.WriteLine("Merging files count: " + files.Length);
int i = 1;
foreach (string file in transids)
{
Console.WriteLine(i + ". Adding: " + file);
pdf.AddDocument(new PdfReader(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\PDF\\Temp\\" + file + ".pdf"));
i++;
}
if (pdfDoc != null)
{
pdfDoc.Close();
pdfDoc.Dispose();
}
return targetPDF;
}
}
示例14: HTMLToPdfTemp
public string HTMLToPdfTemp(string HTML, string FilePath)
{
//FilePath = FilePath.ToString() +DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString();
Document document = new Document();
try
{
PdfWriter.GetInstance(document, new FileStream(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\PDF\\Temp\\" + FilePath.ToString() + ".pdf", FileMode.Create));
}
catch (IOException ex)
{
PdfWriter.GetInstance(document, new FileStream(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\PDF\\Temp\\" + FilePath.ToString() + ".pdf", FileMode.Create));
}
document.Open();
//iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("~/Images/logo.png"));
//pdfImage.ScaleToFit(200, 200);
//pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING;
//pdfImage.SetAbsolutePosition(20, 730);
//iTextSharp.text.Image pdfsign = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("~/Images/sign.png"));
//pdfsign.ScaleToFit(150, 150);
//pdfsign.Alignment = iTextSharp.text.Image.ALIGN_BOTTOM;
//pdfsign.SetAbsolutePosition(400, 365);
// document.Add(pdfImage);
// document.Add(pdfsign);
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(HTML));
document.Close();
document.Dispose();
return FilePath + ".pdf";
}