本文整理汇总了C#中iTextSharp.text.Document.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Open方法的具体用法?C# Document.Open怎么用?C# Document.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Go
public void Go()
{
var outputFile = Helpers.IO.GetClassOutputPath(this);
var fixedHtml = FixBrokenServerControlMarkup(HTML);
using (FileStream stream = new FileStream(
outputFile,
FileMode.Create,
FileAccess.Write))
{
using (var document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(
document, stream
);
document.Open();
using (var xmlSnippet = new StringReader(fixedHtml))
{
XMLWorkerHelper.GetInstance().ParseXHtml(
writer, document, xmlSnippet
);
}
}
}
}
示例2: ExportToPDF
private void ExportToPDF()
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
//To Export all pages
this.gvExportToPdf.AllowPaging = false;
//this.BindGridView();
this.gvExportToPdf.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=DashboardReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}
}
示例3: InitializeDocument
private void InitializeDocument()
{
MemoryStream baos = new MemoryStream();
document = new Document();
writer = PdfWriter.GetInstance(document, baos);
document.Open();
}
示例4: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
document.SetPageSize(PageSize.A5);
document.SetMargins(36, 72, 108, 180);
document.SetMarginMirroring(true);
// step 3
document.Open();
// step 4
document.Add(new Paragraph(
"The left margin of this odd page is 36pt (0.5 inch); " +
"the right margin 72pt (1 inch); " +
"the top margin 108pt (1.5 inch); " +
"the bottom margin 180pt (2.5 inch).")
);
Paragraph paragraph = new Paragraph();
paragraph.Alignment = Element.ALIGN_JUSTIFIED;
for (int i = 0; i < 20; i++)
{
paragraph.Add("Hello World! Hello People! " +
"Hello Sky! Hello Sun! Hello Moon! Hello Stars!"
);
}
document.Add(paragraph);
document.Add(new Paragraph(
"The right margin of this even page is 36pt (0.5 inch); " +
"the left margin 72pt (1 inch).")
);
}
}
示例5: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// Use old example to create PDF
MovieTemplates mt = new MovieTemplates();
byte[] pdf = Utility.PdfBytes(mt);
using (ZipFile zip = new ZipFile())
{
using (MemoryStream ms = new MemoryStream())
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfPTable table = new PdfPTable(2);
PdfReader reader = new PdfReader(pdf);
int n = reader.NumberOfPages;
PdfImportedPage page;
for (int i = 1; i <= n; i++)
{
page = writer.GetImportedPage(reader, i);
table.AddCell(Image.GetInstance(page));
}
document.Add(table);
}
zip.AddEntry(RESULT, ms.ToArray());
}
zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
zip.Save(stream);
}
}
示例6: TextLeadingTest
public void TextLeadingTest() {
String file = "phrases.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
Phrase p1 = new Phrase("first, leading of 150");
p1.Leading = 150;
document.Add(p1);
document.Add(Chunk.NEWLINE);
Phrase p2 = new Phrase("second, leading of 500");
p2.Leading = 500;
document.Add(p2);
document.Add(Chunk.NEWLINE);
Phrase p3 = new Phrase();
p3.Add(new Chunk("third, leading of 20"));
p3.Leading = 20;
document.Add(p3);
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file, OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例7: CreateAllSamples
virtual public void CreateAllSamples() {
bool success = true;
foreach (String str in list) {
try {
Console.WriteLine(str);
Document doc = new Document();
PdfWriter writer = null;
try {
writer = PdfWriter.GetInstance(doc,
new FileStream(TARGET + "/" + str + "Test.pdf", FileMode.Create));
}
catch (DocumentException e) {
Console.WriteLine(e);
}
doc.Open();
StreamReader bis = File.OpenText(RESOURCE_TEST_PATH + "/snippets/" + str + "snippet.html");
XMLWorkerHelper helper = XMLWorkerHelper.GetInstance();
helper.ParseXHtml(writer, doc, bis);
doc.Close();
}
catch (Exception e) {
Console.Write(e);
success = false;
}
}
if (!success) {
Assert.Fail();
}
}
示例8: initFile
protected void initFile(bool bBlackAndWhite = false)
{
m_doc = new Document();
string folder = Settings.Default["pdffolder"].ToString() + m_strFolder;
System.IO.Directory.CreateDirectory(folder );
string fileName = folder + "/"+m_strTitle;
if (bBlackAndWhite)
fileName += "BW.pdf";
else
fileName += ".pdf";
m_writer = PdfWriter.GetInstance(m_doc, new System.IO.FileStream(fileName, System.IO.FileMode.Create));
m_doc.Open();
m_fSmall = new iTextSharp.text.Font();
m_fSmall.Size = 10;
m_fBig = new iTextSharp.text.Font();
m_fBig.Size = 40;
m_fBig.Color = bBlackAndWhite ? BaseColor.BLACK : getNextColor();
// m_fBig.SetStyle("bold");
m_fNorm = new iTextSharp.text.Font();
m_fNorm.Size = 20;
m_fNorm.Color = new BaseColor(m_colorText);
m_doc.Add(new Paragraph("Name:____________________________________________ Date:______________"/*, fSmall*/));
m_doc.Add(new Paragraph(m_strTitle, m_fBig));
m_doc.Add(new Paragraph(" "));
}
示例9: 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;
}
示例10: Export
public static void Export(DetailsView dvGetStudent)
{
int rows = dvGetStudent.Rows.Count;
int columns = dvGetStudent.Rows[0].Cells.Count;
int pdfTableRows = rows;
iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(2, pdfTableRows);
PdfTable.BorderWidth = 1;
PdfTable.Cellpadding = 0;
PdfTable.Cellspacing = 0;
for (int rowCounter = 0; rowCounter < rows; rowCounter++)
{
for (int columnCounter = 0; columnCounter < columns; columnCounter++)
{
string strValue = dvGetStudent.Rows[rowCounter].Cells[columnCounter].Text;
PdfTable.AddCell(strValue);
}
}
Document Doc = new Document();
PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream);
Doc.Open();
Doc.Add(PdfTable);
Doc.Close();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=StudentDetails.pdf");
HttpContext.Current.Response.End();
}
示例11: generatePDFButton_Click
protected void generatePDFButton_Click(object sender, EventArgs e)
{
PdfPTable pdfPTable = new PdfPTable(CreatedStudentInformationGridView.HeaderRow.Cells.Count);
foreach (TableCell headerCell in CreatedStudentInformationGridView.HeaderRow.Cells)
{
PdfPCell pfdPCell = new PdfPCell(new Phrase(headerCell.Text));
//pfdPCell.BackgroundColor = new BaseColor(newCenterGridView.HeaderStyle.ForeColor);
pdfPTable.AddCell(pfdPCell);
}
foreach (GridViewRow gridViewRow in CreatedStudentInformationGridView.Rows)
{
foreach (TableCell tableCell in gridViewRow.Cells)
{
PdfPCell pfdPCell = new PdfPCell(new Phrase(tableCell.Text));
//pfdPCell.BackgroundColor = new BaseColor(newCenterGridView.HeaderStyle.ForeColor);
pdfPTable.AddCell(pfdPCell);
}
}
Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
pdfDocument.Open();
pdfDocument.Add(pdfPTable);
pdfDocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=NewCenter.pdf");
Response.Write(pdfDocument);
Response.Flush();
Response.End();
}
示例12: TryCreatePdf
public bool TryCreatePdf(string nameBank)
{
try
{
using (FileStream file = new FileStream(String.Format(path,nameBank), FileMode.Create))
{
Document document = new Document(PageSize.A7);
PdfWriter writer = PdfWriter.GetInstance(document, file);
/// Create metadate pdf file
document.AddAuthor("");
document.AddLanguage("pl");
document.AddSubject("Payment transaction");
document.AddTitle("Transaction");
/// Create text in pdf file
document.Open();
document.Add(new Paragraph(_przelew+"\n"));
document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n",nameBank)));
document.Add(new Paragraph(DateTime.Now.ToString()));
document.Close();
writer.Close();
file.Close();
return true;
}
}
catch (SystemException ex)
{
return false;
}
}
示例13: Go
public void Go()
{
var outputFile = Helpers.IO.GetClassOutputPath(this);
var parsedHtml = RemoveImage(HTML);
Console.WriteLine(parsedHtml);
using (var xmlSnippet = new StringReader(parsedHtml))
{
using (FileStream stream = new FileStream(
outputFile,
FileMode.Create,
FileAccess.Write))
{
using (var document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(
document, stream
);
document.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(
writer, document, xmlSnippet
);
}
}
}
}
示例14: GenerateReport
/// <summary>
/// Save a pdf file in "../../test.pdf".
/// </summary>
/// <param name="deals">Expect Collection of objects that have Name, Address, ProductName and formula.</param>
public void GenerateReport(IEnumerable<PdfReportModel> deals)
{
FileStream fileStream = new FileStream(ReportsPath, FileMode.Create, FileAccess.Write, FileShare.None);
Rectangle pageSize = new Rectangle(PageSize.A4);
Document reportDocument = new Document(pageSize);
PdfWriter pdfWriter = PdfWriter.GetInstance(reportDocument, fileStream);
var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 17);
reportDocument.Open();
PdfPTable reportTable = new PdfPTable(6);
reportTable.HorizontalAlignment = Element.ALIGN_LEFT;
PdfPCell headerCell = new PdfPCell(new Phrase("Produced products information", boldFont));
headerCell.Colspan = 6;
headerCell.HorizontalAlignment = 0;
reportTable.AddCell(headerCell);
this.PutHeadCells(reportTable);
foreach (var deal in deals)
{
reportTable.AddCell(deal.ProductName);
reportTable.AddCell(deal.Quantity);
reportTable.AddCell(deal.PricePerUnit);
reportTable.AddCell(deal.Formula);
reportTable.AddCell(deal.Address);
reportTable.AddCell(deal.Total);
}
reportDocument.Add(reportTable);
reportDocument.Close();
}
示例15: 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);
}
}