本文整理匯總了C#中iTextSharp.text.Document.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# Document.Close方法的具體用法?C# Document.Close怎麽用?C# Document.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MergePdfs
public static byte[] MergePdfs(IEnumerable<byte[]> inputFiles)
{
MemoryStream outputStream = new MemoryStream();
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, outputStream);
document.Open();
PdfContentByte content = writer.DirectContent;
foreach (byte[] input in inputFiles)
{
PdfReader reader = new PdfReader(input);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, i);
int rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
content.AddTemplate(page, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
else
{
content.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
document.Close();
return outputStream.ToArray();
}
示例2: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
filePdf = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.InternetCache), "PDF_Temp.pdf");
var document = new Document(PageSize.LETTER);
// Create a new PdfWriter object, specifying the output stream
var output = new FileStream(filePdf, FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
BaseFont bf = BaseFont.CreateFont (BaseFont.HELVETICA, BaseFont.CP1252, false);
iTextSharp.text.Font font = new iTextSharp.text.Font (bf, 16, iTextSharp.text.Font.BOLD);
var p = new Paragraph ("Sample text", font);
document.Add (p);
document.Close ();
writer.Close ();
//Close the Document - this saves the document contents to the output stream
document.Close();
writer.Close ();
}
示例3: CreateTmpPDFFile
public static void CreateTmpPDFFile(string tmpPDFFile, string jpgFile)
{
Document doc = new Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
try
{
string pdfFilePath = tmpPDFFile;
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(pdfFilePath, FileMode.Create));
doc.Open();//Open Document to write
////Write some content into pdf file
//Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
// Now image in the pdf file
string imageFilePath = jpgFile;
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
//Resize image depend upon your need
//jpg.ScalePercent(20);
jpg.ScaleToFit(600f, 950f);
//Give space before image
//jpg.SpacingBefore = 30f;
//Give some space after the image
//jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
//doc.Add(paragraph); // add paragraph to the document
doc.Add(jpg); //add an image to the created pdf document
doc.Close();
}
catch (DocumentException docEx)
{
//handle pdf document exception if any
}
catch (IOException ioEx)
{
// handle IO exception
}
catch (Exception ex)
{
// ahndle other exception if occurs
}
finally
{
//Close document and writer
doc.Close();
}
}
示例4: DoPdf
public void DoPdf()
{
PdfPTable pdfPTable = new PdfPTable(diseaseWiseReportGridView.HeaderRow.Cells.Count);
foreach (TableCell headerCell in diseaseWiseReportGridView.HeaderRow.Cells)
{
PdfPCell pdfCell = new PdfPCell(new Phrase(headerCell.Text));
pdfPTable.AddCell(pdfCell);
}
int count = 1;
foreach (GridViewRow gridViewRow in diseaseWiseReportGridView.Rows)
{
if (count != 0)
foreach (TableCell tableCell in gridViewRow.Cells)
{
PdfPCell pdfCell = new PdfPCell(new Phrase(tableCell.Text));
pdfPTable.AddCell(pdfCell);
}
count++;
}
Document document = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter.GetInstance(document, Response.OutputStream);
//PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("test.pdf", FileMode.Create));
Paragraph diseaseName = new Paragraph("Disease Name: " + diseaseDropDownList.SelectedItem.Text);
Paragraph strartingDate = new Paragraph("Starting Date: " + firstdateTextBox.Text);
Paragraph lastdate = new Paragraph("Last Date: " + lastdateTextBox.Text);
Paragraph text = new Paragraph("\n\n");
document.Open();
document.Add(diseaseName);
document.Add(strartingDate);
document.Add(lastdate);
document.Add(text);
document.Add(pdfPTable);
document.Close();
Response.ContentType = "Application";
Response.AppendHeader("content-disposition", "attachment;filename=DiseaseWiseReport.pdf");
Response.Write(document);
Response.Flush();
Response.End();
document.Close();
}
開發者ID:Ramcste,項目名稱:CommunityMedicineAutomationWithMasterPage,代碼行數:50,代碼來源:DiseaseWiseReportUI.aspx.cs
示例5: CreateCards
/// <summary>
/// Creates a MemoryStream but does not dispose it.
/// </summary>
/// <param name="members"></param>
/// <param name="expiration"></param>
/// <returns></returns>
public static MemoryStream CreateCards(IEnumerable<Member> members, DateTime expiration)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(CARD_WIDTH, CARD_HEIGHT));
MemoryStream memStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memStream);
writer.CloseStream = false;
doc.Open();
foreach (var member in members)
{
foreach (var passport in new[] { false, true})
{
Render_FrontBase(writer.DirectContentUnder, expiration);
Render_FrontContent(writer.DirectContent, member);
doc.NewPage();
Render_BackBase(writer.DirectContentUnder);
Render_BackContent(writer.DirectContent, member, passport);
doc.NewPage();
}
}
doc.Close();
byte[] buf = new byte[memStream.Position];
memStream.Position = 0;
return memStream;
}
示例6: CreatePdfDocument
public Document CreatePdfDocument(Chart chart, string path)
{
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
(int) chart.ActualWidth,
(int) chart.ActualHeight,
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(chart);
MemoryStream stream = new MemoryStream();
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(stream);
Bitmap bitmap = new Bitmap(stream);
System.Drawing.Image image = bitmap;
System.Drawing.Image resizedImage = ResizeImage(image, image.Width*2, image.Height);
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, new FileStream(path, FileMode.OpenOrCreate));
doc.Open();
Image pdfImage = Image.GetInstance(resizedImage, ImageFormat.Jpeg);
doc.Add(pdfImage);
doc.Close();
return doc;
}
示例7: ExtractPage
/// <summary>
/// Extract a single page from PDF file.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="outputFile">The output file.</param>
/// <param name="pageNumber">The specific page number.</param>
public static void ExtractPage(string sourceFile, string outputFile, int pageNumber)
{
try
{
PdfReader reader = new PdfReader(sourceFile);
if (pageNumber > reader.NumberOfPages)
{
Console.WriteLine("This page number is out of reach.");
return;
}
Document document = new Document();
PdfCopy pdfCopy = new PdfCopy(document, new FileStream(outputFile, FileMode.Create));
document.Open();
PdfImportedPage importedPage = pdfCopy.GetImportedPage(reader, pageNumber);
pdfCopy.AddPage(importedPage);
document.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
示例8: AusgangsrechnungenPDF_Click
private void AusgangsrechnungenPDF_Click(object sender, EventArgs e)
{
string pdfString = "";
Document pdfDoc = new Document();
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() + "\\exportAusgangsrechnungen.pdf",
System.IO.FileMode.Create));
pdfDoc.Open();
foreach (DataGridViewRow row in dataGridViewAusgangsrechnung.SelectedRows)
{
foreach(DataGridViewCell cell in row.Cells)
{
pdfString += cell.Value.ToString() + " ";
}
pdfDoc.Add(new Paragraph (pdfString));
pdfString = "";
}
PdfContentByte cb = writer.DirectContent;
cb.MoveTo(pdfDoc.PageSize.Width, pdfDoc.PageSize.Height);
cb.LineTo(pdfDoc.PageSize.Width / 2, pdfDoc.PageSize.Height);
cb.Stroke();
pdfDoc.Close();
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
iTextSharp.text.pdf.BarcodeQRCode qrcode = new BarcodeQRCode("testing", 50, 50, null);
iTextSharp.text.Image img1 = qrcode.GetImage();
Document doc = new Document();
try
{
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("css") + "/Images.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("GIF"));
doc.Add(img1);
MemoryStream ms = new MemoryStream(img1.OriginalData);
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
// img = returnImage.Save(new Stream(), System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
}
finally
{
doc.Close();
}
}
示例10: Convert
public int Convert(string from, string to)
{
_logger.DebugFormat("Text轉換為Pdf, {0},到:{1}", from, to);
try
{
var content = File.ReadAllText(@from, Encoding.Default);
Document document = new Document();
BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf);
PdfWriter.GetInstance(document, new FileStream(@to, FileMode.Create));
document.Open();
document.Add(new Paragraph(content, font));
document.Close();
return ErrorMessages.Success;
}
catch(Exception ex)
{
throw new ConverterException(ErrorMessages.TextToPdfFailed, ex);
}
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string html = GetHTMLOutput("~/render.aspx?id=1");
if (!string.IsNullOrEmpty(html))
{
string file = Server.MapPath("~/pdf") + "\\using.pdf";
using (Document doc = new Document(PageSize.LETTER, 25, 25, 25, 25))
{
using (PdfWriter pdf = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)))
{
List<IElement> code = HTMLWorker.ParseToList(new StringReader(html), null);
doc.Open();
foreach (IElement el in code)
{
doc.Add(el);
}
doc.Close();
}
}
}
}
示例12: ParseXfaOnlyXML
virtual public void ParseXfaOnlyXML() {
StreamReader bis = File.OpenText(RESOURCE_TEST_PATH + SNIPPETS + TEST + "snippet.html");
Document doc = new Document(PageSize.A4);
float margin = utils.ParseRelativeValue("10%", PageSize.A4.Width);
doc.SetMargins(margin, margin, margin, margin);
PdfWriter writer = null;
try {
writer = PdfWriter.GetInstance(doc, new FileStream(
TARGET + TEST + "_charset.pdf", FileMode.Create));
}
catch (DocumentException e) {
Console.WriteLine(e);
}
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc = new HtmlPipelineContext(null);
hpc.SetAcceptUnknown(true)
.AutoBookmark(true)
.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
.CharSet(Encoding.GetEncoding("ISO-8859-1"));
IPipeline pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
doc.Open();
XMLParser p = new XMLParser(true, worker);
p.Parse(bis);
doc.Close();
}
示例13: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
Page.Title = "Contact List";
MemoryStream PDFData = new MemoryStream();
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, PDFData);
// step 3: we open the document
document.Open();
// step 4: we add a paragraph to the document
document.Add(new Paragraph(DateTime.Now.ToString()));
Contact oContact = new Contact();
DataTable dtContact = oContact.LoadAll();
int numRow = dtContact.Rows.Count;
int numCol = 5;
iTextSharp.text.Table aTable = new iTextSharp.text.Table(numCol, numRow);
aTable.AutoFillEmptyCells = true;
aTable.Padding = 1;
aTable.Spacing = 1;
Cell cell = new Cell(new Phrase("Contact List", FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD)));
cell.Header = true;
cell.Colspan = numCol;
cell.BackgroundColor = Color.LIGHT_GRAY;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
aTable.AddCell(cell);
for (int i = 0; i < dtContact.Rows.Count; i++)
{
for (int n = 1; n <= numCol; n++)
aTable.AddCell(dtContact.Rows[i][n].ToString());
}
document.Add(aTable);
// step 5: we close the document
document.Close();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.Charset = string.Empty;
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
Response.AddHeader("Content-Disposition",
"attachment; filename=" + Title.Replace(" ", "").Replace(":", "-") + ".pdf");
Response.OutputStream.Write(PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();
}
示例14: btnExpotGraph_Click
protected void btnExpotGraph_Click(object sender, EventArgs e)
{
//code obtained from here: http://www.aspsnippets.com/Articles/Export-ASPNet-Chart-Control-to-PDF-Document-using-iTextSharp-Library.aspx. Used under the site's license.
if (cboFileSelectionGraExp.SelectedIndex == 0)
{
string timeStamp = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() +
"-" + DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString();
Document pdfDoc = new Document(new RectangleReadOnly(1248,816), 88f, 88f, 10f, 10f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
using (MemoryStream stream = new MemoryStream())
{
Chart1.SaveImage(stream, ChartImageFormat.Png);
iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
chartImage.ScalePercent(75f);
pdfDoc.Add(chartImage);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Chart_" + timeStamp + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}
示例15: btnExport_Click
protected void btnExport_Click(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
//To Export all pages
grid_monthly_attendanceDetailed.AllowPaging = false;
//this.BindGrid();
grid_monthly_attendanceDetailed.RenderBeginTag(hw);
grid_monthly_attendanceDetailed.HeaderRow.RenderControl(hw);
foreach (GridViewRow row in grid_monthly_attendanceDetailed.Rows)
{
row.RenderControl(hw);
}
grid_monthly_attendanceDetailed.FooterRow.RenderControl(hw);
grid_monthly_attendanceDetailed.RenderEndTag(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Report.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}