本文整理汇总了C#中iTextSharp.text.Document.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Add方法的具体用法?C# Document.Add怎么用?C# Document.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePdf
public override byte[] CreatePdf(List<PdfContentParameter> contents, string[] images, int type)
{
var document = new Document();
float docHeight = document.PageSize.Height - heightOffset;
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
document.SetMargins(50, 50, 10, 40);
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
writer.PageEvent = new HeaderFooterHandler(type);
document.Open();
document.Add(contents[0].Table);
for (int i = 0; i < images.Length; i++)
{
document.NewPage();
float subtrahend = document.PageSize.Height - heightOffset;
iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]);
pool.Alignment = 3;
pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
//pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
document.Add(pool);
}
document.Close();
return output.ToArray();
}
示例2: Write
public void Write(string outputPath, FlowDocument doc)
{
Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
Font textFont = new Font(baseFont, DEFAULT_FONTSIZE, Font.NORMAL, BaseColor.BLACK);
Font headingFont = new Font(baseFont, DEFAULT_HEADINGSIZE, Font.BOLD, BaseColor.BLACK);
using (FileStream stream = new FileStream(outputPath, FileMode.Create))
{
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
foreach (Block i in doc.Blocks) {
if (i is System.Windows.Documents.Paragraph)
{
TextRange range = new TextRange(i.ContentStart, i.ContentEnd);
Console.WriteLine(i.Tag);
switch (i.Tag as string)
{
case "Paragraph": iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(range.Text, textFont);
par.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(par);
break;
case "Heading": iTextSharp.text.Paragraph head = new iTextSharp.text.Paragraph(range.Text, headingFont);
head.Alignment = Element.ALIGN_CENTER;
head.SpacingAfter = 10;
pdfDoc.Add(head);
break;
default: iTextSharp.text.Paragraph def = new iTextSharp.text.Paragraph(range.Text, textFont);
def.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(def);
break;
}
}
else if (i is System.Windows.Documents.List)
{
iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
list.SetListSymbol("\u2022");
list.IndentationLeft = 15f;
foreach (var li in (i as System.Windows.Documents.List).ListItems)
{
iTextSharp.text.ListItem listitem = new iTextSharp.text.ListItem();
TextRange range = new TextRange(li.Blocks.ElementAt(0).ContentStart, li.Blocks.ElementAt(0).ContentEnd);
string text = range.Text.Substring(1);
iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(text, textFont);
listitem.SpacingAfter = 10;
listitem.Add(par);
list.Add(listitem);
}
pdfDoc.Add(list);
}
}
if (pdfDoc.PageNumber == 0)
{
iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(" ");
par.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(par);
}
pdfDoc.Close();
}
}
示例3: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
BaseFont bf;
Font font;
for (int i = 0; i < 3; i++)
{
bf = BaseFont.CreateFont(
MOVIES[i][0], MOVIES[i][1], BaseFont.NOT_EMBEDDED
);
font = new Font(bf, 12);
document.Add(new Paragraph(bf.PostscriptFontName, font));
for (int j = 2; j < 5; j++)
{
document.Add(new Paragraph(MOVIES[i][j], font));
}
document.Add(Chunk.NEWLINE);
}
}
}
示例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: VerticalPositionTest0
public void VerticalPositionTest0() {
String file = "vertical_position.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
writer.PageEvent = new CustomPageEvent();
PdfPTable table = new PdfPTable(2);
for (int i = 0; i < 100; i++) {
table.AddCell("Hello " + i);
table.AddCell("World " + i);
}
document.Add(table);
document.NewPage();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++) {
sb.Append("some more text ");
}
document.Add(new Paragraph(sb.ToString()));
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);
}
}
示例6: CreatePDF
private void CreatePDF()
{
MemoryStream MStream = new MemoryStream();
Document document = new Document(PageSize.A4, 80, 50, 30, 65);
try
{
PdfWriter writer = PdfWriter.GetInstance(document, MStream);
document.Open();
document.Add(new iTextSharp.text.Paragraph("This is test and must work"));
string h = "<a>dsfdfsdf</a><br><br><h1>sdfsdfsd</h1>";
TextReader sReader = new StringReader(h);
List<IElement> l = HTMLWorker.ParseToList(sReader,new StyleSheet());
foreach (IElement i in l)
{
document.Add(i);
}
document.Close();
}
catch (Exception e)
{
throw e;
}
//stampo pdf
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=myPDFNew.pdf");
Response.BinaryWrite(MStream.GetBuffer());
Response.End();
}
示例7: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
document.Add(new Paragraph(
"Movies featuring River Phoenix", FilmFonts.BOLD
));
document.Add(CreateParagraph(
"My favorite movie featuring River Phoenix was ", "0092005"
));
document.Add(CreateParagraph(
"River Phoenix was nominated for an academy award for his role in ", "0096018"
));
document.Add(CreateParagraph(
"River Phoenix played the young Indiana Jones in ", "0097576"
));
document.Add(CreateParagraph(
"His best role was probably in ", "0102494"
));
}
}
示例8: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
PdfPTable table = CreateTable1();
document.Add(table);
table = CreateTable2();
table.SpacingBefore = 5;
table.SpacingAfter = 5;
document.Add(table);
table = CreateTable3();
document.Add(table);
table = CreateTable4();
table.SpacingBefore = 5;
table.SpacingAfter = 5;
document.Add(table);
table = CreateTable5();
document.Add(table);
}
}
示例9: CreateDocument
public void CreateDocument( List< ScanDetails > info, string path )
{
var doc = new Document( PageSize.A4 );
PdfWriter.GetInstance( doc, new FileStream( path, FileMode.Create ) );
doc.Open();
doc.Add( new Paragraph() );
PdfPTable table = new PdfPTable( 4 ) { WidthPercentage = 100 };
//header
PdfPCell cell = new PdfPCell { BackgroundColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase( "URL" ) };
table.AddCell( cell );
cell.Phrase = new Phrase( "Response" );
table.AddCell( cell );
cell.Phrase = new Phrase( "Size" );
table.AddCell( cell );
cell.Phrase = new Phrase( "Page Title" );
table.AddCell( cell );
//rows
foreach( var item in info )
{
table.AddCell( item.Url.ToString() );
table.AddCell( item.Response );
table.AddCell( item.Size.ToString() );
table.AddCell( item.PageTitle );
}
doc.Add( table );
doc.Close();
}
示例10: TestIncompleteTableAdd
public virtual void TestIncompleteTableAdd() {
const String file = "incomplete_add.pdf";
Document document = new Document(PageSize.LETTER);
PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.OpenOrCreate));
document.Open();
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitRows = false;
table.Complete = false;
for (int i = 0; i < 5; i++) {
table.AddCell("Header " + i);
}
for (int i = 0; i < 500; i++) {
if (i % 5 == 0) {
document.Add(table);
}
table.AddCell("Test " + i);
}
table.Complete = true;
document.Add(table);
document.Close();
CompareTablePdf(file);
}
示例11: TestNoChangeInSetSkipFirstHeader
public virtual void TestNoChangeInSetSkipFirstHeader() {
Document document = new Document();
Stream stream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, stream);
document.Open();
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitRows = false;
table.Complete = false;
for (int i = 0; i < 5; ++i) {
table.AddCell("Header " + i);
}
table.AddCell("Cell 1");
document.Add(table);
Assert.False(table.SkipFirstHeader);
table.Complete = true;
for (int i = 1; i < 5; i++) {
table.AddCell("Cell " + i);
}
document.Add(table);
document.Close();
stream.Close();
}
示例12: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
Phrase phrase;
Chunk chunk;
foreach (Movie movie in PojoFactory.GetMovies())
{
phrase = new Phrase(movie.MovieTitle);
chunk = new Chunk("\u00a0");
chunk.SetAnnotation(PdfAnnotation.CreateText(
writer, null, movie.MovieTitle,
string.Format(INFO, movie.Year, movie.Duration),
false, "Comment"
));
phrase.Add(chunk);
document.Add(phrase);
document.Add(PojoToElementFactory.GetDirectorList(movie));
document.Add(PojoToElementFactory.GetCountryList(movie));
}
}
}
示例13: GeneratePdfReport
public static void GeneratePdfReport(string filepath)
{
FileStream fileStream = new FileStream(filepath, FileMode.Create);
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, fileStream);
document.SetPageSize(PageSize.A3);
document.Open();
var paragraph = new Paragraph("Aggregated Sales Report",
FontFactory.GetFont("Arial", 19, Font.BOLD));
paragraph.SpacingAfter = 20.0f;
paragraph.Alignment = 1;
document.Add(paragraph);
PdfPTable mainTable = new PdfPTable(1);
var reports = GetDayReports();
foreach (var dayReport in reports)
{
var headerCell = new PdfPCell(new Phrase("Date: " + dayReport.FormattedDate));
headerCell.BackgroundColor = new BaseColor(175, 166, 166);
mainTable.AddCell(headerCell);
var table = GenerateReportTable(dayReport);
mainTable.AddCell(table);
}
document.Add(mainTable);
document.Close();
}
示例14: Write
// ===========================================================================
public void Write(Stream stream) {
// step 1
using (Document document = new Document()) {
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
// Image in colorspace DeviceGray
byte[] gradient = new byte[256];
for (int i = 0; i < 256; i++) {
gradient[i] = (byte) i;
}
Image img1 = Image.GetInstance(256, 1, 1, 8, gradient);
img1.ScaleAbsolute(256, 50);
document.Add(img1);
// Image in colorspace RGB
byte[] cgradient = new byte[256 * 3];
for (int i = 0; i < 256; i++) {
cgradient[i * 3] = (byte) (255 - i);
cgradient[i * 3 + 1] = (byte) (255 - i);
cgradient[i * 3 + 2] = (byte) i;
}
Image img2 = Image.GetInstance(256, 1, 3, 8, cgradient);
img2.ScaleAbsolute(256, 50);
document.Add(img2);
Image img3 = Image.GetInstance(16, 16, 3, 8, cgradient);
img3.ScaleAbsolute(64, 64);
document.Add(img3);
}
}
示例15: buildPDF
/// <summary>
/// Costruisce e spedisce PDF con lettera corrente
/// </summary>
protected void buildPDF()
{
string fileName = "Visita " + DALRuntime.getNomePazienteConSaluto(DALRuntime.IdMQuest) + ".pdf";
fileName = fileName.Replace(' ', '_');
Document pdfDoc = new Document();
this.Response.Clear();
this.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", System.IO.Path.GetFileName(fileName)));
this.Response.ContentType = "application/pdf";
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
// Aggiunge l'intestazione dell'utente
string sIntestazione = DALRuntime.getTestata();
// Definisce un font piu' piccolo
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, true);
Font ftTimes10Italic = new Font(bfTimes, 10, Font.ITALIC);
Paragraph pIntestazione = new Paragraph(sIntestazione, ftTimes10Italic);
pdfDoc.Add(pIntestazione);
Font ftTimes10Normal = new Font(bfTimes, 10, Font.NORMAL);
string sLettera = memLettera.Text;
Paragraph pBody = new Paragraph(sLettera, ftTimes10Normal);
pdfDoc.Add(pBody);
pdfDoc.Close();
this.Response.Flush();
this.Response.End();
}