本文整理汇总了C#中iTextSharp.text.Phrase类的典型用法代码示例。如果您正苦于以下问题:C# Phrase类的具体用法?C# Phrase怎么用?C# Phrase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Phrase类属于iTextSharp.text命名空间,在下文中一共展示了Phrase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMovieInformation
// ---------------------------------------------------------------------------
/**
* Creates a Phrase containing information about a movie.
* @param movie the movie for which you want to create a Paragraph
*/
public Phrase CreateMovieInformation(Movie movie)
{
Phrase p = new Phrase();
p.Font = FilmFonts.NORMAL;
p.Add(new Phrase("Title: ", FilmFonts.BOLDITALIC));
p.Add(PojoToElementFactory.GetMovieTitlePhrase(movie));
p.Add(" ");
if (!string.IsNullOrEmpty(movie.OriginalTitle))
{
p.Add(new Phrase("Original title: ", FilmFonts.BOLDITALIC));
p.Add(PojoToElementFactory.GetOriginalTitlePhrase(movie));
p.Add(" ");
}
p.Add(new Phrase("Country: ", FilmFonts.BOLDITALIC));
foreach (Country country in movie.Countries)
{
p.Add(PojoToElementFactory.GetCountryPhrase(country));
p.Add(" ");
}
p.Add(new Phrase("Director: ", FilmFonts.BOLDITALIC));
foreach (Director director in movie.Directors)
{
p.Add(PojoToElementFactory.GetDirectorPhrase(director));
p.Add(" ");
}
p.Add(new Chunk("Year: ", FilmFonts.BOLDITALIC));
p.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
p.Add(new Chunk(" Duration: ", FilmFonts.BOLDITALIC));
p.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
p.Add(new Chunk(" minutes", FilmFonts.NORMAL));
p.Add(new LineSeparator(0.3f, 100, null, Element.ALIGN_CENTER, -2));
return p;
}
示例2: OnEndPage
//重写 关闭一个页面时
public override void OnEndPage(PdfWriter writer, Document document)
{
try
{
Font font = new Font(basefont, defaultFontSize);
Phrase head = new Phrase(header, font);
PdfContentByte cb = writer.DirectContent;
//页眉显示的位置
ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, head,
document.Right - 10 + document.LeftMargin, document.Top + 10, 0);
if (PAGE_NUMBER)
{
Phrase footer = new Phrase("第 " + writer.PageNumber + " / " + " "+" 頁", font);
cb = writer.DirectContent;
//tpl = cb.CreateTemplate(100, 100);
//模版 显示总共页数
cb.AddTemplate(tpl, document.Left / 2 + document.Right / 2 , document.Bottom - 10);//调节模版显示的位置
//页脚显示的位置
ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, footer,
document.Left / 2+document.Right/ 2+23, document.Bottom - 10, 0);
}
}
catch (Exception ex)
{
throw new Exception("HeaderAndFooterEvent-->OnEndPage-->" + ex.Message);
}
}
示例3: GenerateReportTable
private static PdfPTable GenerateReportTable(DayReport report)
{
PdfPTable table = new PdfPTable(5);
string[] headerTitles = {"Product", "Quantity", "Unit Price", "Location", "Sum"};
foreach (var title in headerTitles)
{
Phrase phrase = new Phrase(title);
phrase.Font = FontFactory.GetFont("Arial", 14, Font.BOLD);
PdfPCell cell = new PdfPCell(phrase);
cell.BackgroundColor = new BaseColor(175, 166, 166);
table.AddCell(cell);
cell.Padding = 0;
}
foreach (var sale in report.Sales)
{
table.AddCell(sale.ProductName);
table.AddCell(sale.MeasureFormatted);
table.AddCell(sale.UnitPrice.ToString());
table.AddCell(sale.Supermarket);
table.AddCell(sale.Sum.ToString());
}
PdfPCell footerCell = new PdfPCell(new Phrase("Total sum for " + report.FormattedDate + ": "));
footerCell.Colspan = 4;
footerCell.HorizontalAlignment = 2;
table.AddCell(footerCell);
table.AddCell(new Phrase(report.TotalSum.ToString()));
return table;
}
示例4: AddText
/// <summary>
/// <para>座標を指定してテキストを追加します。</para>
/// <para>PDF では用紙左上が座標基準 (0, 0) である点に注意してください。</para>
/// </summary>
/// <param name="text">追加するテキスト</param>
/// <param name="fontSize">フォントサイズ</param>
/// <param name="x">X 座標</param>
/// <param name="y">Y座標</param>
public void AddText(string text, int fontSize, int x, int y)
{
// 左下の座標
float llx = x;
float lly = 0f;
// 右上の座標
float urx = this.Page.Width;
float ury = y;
var pcb = this.Writer.DirectContent;
var ct = new ColumnText(pcb);
var font = new Font(this.BaseFont, fontSize, Font.NORMAL);
var phrase = new Phrase(text, font);
ct.SetSimpleColumn(
phrase,
llx,
lly,
urx,
ury,
0,
Element.ALIGN_LEFT | Element.ALIGN_TOP
);
// 以下を実行して反映する (消さないこと)
ct.Go();
}
示例5: GetFormattedCell
private static PDF.PdfPCell GetFormattedCell(TableCell cell)
{
PDF.PdfPCell formattedCell = new PDF.PdfPCell();
Element[] cellElements = cell.SubElements;
foreach (Element temp in cellElements)
{
switch (temp.GetElementType())
{
//TODO: Add other enum values
case ElementType.Text:
IT.Phrase phrase = new IT.Phrase(TextFormatter.GetFormattedText((Text)temp));
formattedCell.AddElement(phrase);
break;
case ElementType.Paragraph:
formattedCell.AddElement(ParagraphFormatter.GetFormattedParagraph((Paragraph)temp));
break;
case ElementType.Table:
formattedCell.AddElement(TableFormatter.GetFormattedTable((Table)temp));
break;
case ElementType.Image:
formattedCell.AddElement(ImageFormatter.GetFormattedImage((Image)temp));
break;
}
}
return formattedCell;
}
示例6: Go
public void Go()
{
// GetClassOutputPath() implementation left out for brevity
var outputFile = Helpers.IO.GetClassOutputPath(this);
using (FileStream stream = new FileStream(
outputFile,
FileMode.Create,
FileAccess.Write))
{
Random random = new Random();
StreamUtil.AddToResourceSearch(("iTextAsian.dll"));
string chunkText = " 你好世界 你好你好,";
var font = new Font(BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12);
using (Document document = new Document())
{
PdfWriter.GetInstance(document, stream);
document.Open();
Phrase phrase = new Phrase();
Chunk chunk = new Chunk("", font);
for (var i = 0; i < 1000; ++i)
{
var asterisk = new String('*', random.Next(1, 20));
chunk.Append(
string.Format("[{0}] {1} ", asterisk, chunkText)
);
}
chunk.SetSplitCharacter(new CustomSplitCharacter());
phrase.Add(chunk);
document.Add(phrase);
}
}
}
示例7: Add
public void Add(Athlete athete)
{
var data =
new IT.Phrase(athete.Id.ToString() ,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
var cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase(athete.Surname + " " + athete.Name,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase(" ",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_TITLE, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
}
示例8: 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));
}
}
}
示例9: 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);
}
}
示例10: OnChapter
/**
* Initialize one of the headers, based on the chapter title;
* reset the page number.
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onChapter(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document, float,
* com.itextpdf.text.Paragraph)
*/
public override void OnChapter(
PdfWriter writer, Document document,
float paragraphPosition, Paragraph title)
{
header[1] = new Phrase(title.Content);
pagenumber = 1;
}
示例11: Phrase
/**
* Copy constructor for <CODE>Phrase</CODE>.
*/
public Phrase(Phrase phrase)
: base()
{
this.AddAll(phrase);
leading = phrase.Leading;
font = phrase.Font;
hyphenation = phrase.hyphenation;
}
示例12: SpecialInstructions
private static IElement SpecialInstructions(string commentsOrSpecialInstructions)
{
var c = new Phrase("\nCOMMENTS OR SPECIAL INSTRUCTIONS:\n", ElementFactory.StandardFontBold);
var c1 = ElementFactory.GetPhrase(commentsOrSpecialInstructions, ElementFactory.Fonts.Standard);
var c2 = new Phrase("\n\n\n", ElementFactory.StandardFont);
var p = new Paragraph { c, c1, c2 };
return p;
}
示例13: SetTable
private void SetTable(string titleString, int year)
{
var ed =
new IT.Phrase("Trofeo Luca De Gerone" + year.ToString() ,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_TITLE + 2, IT.Font.BOLD)
);
var title =
new IT.Phrase(titleString,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_TITLE, IT.Font.BOLD)
);
//pett, nome , tempo
float[] widths = {1f,6f,4f};
table = new IT.pdf.PdfPTable(widths);
table.HeaderRows = 2;
table.DefaultCell.Border = IT.Rectangle.NO_BORDER;
// edizione
var cell = new IT.pdf.PdfPCell(ed);
cell.HorizontalAlignment = IT.Element.ALIGN_CENTER;
cell.Colspan = COLUMNS;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
// intesatazione
cell = new IT.pdf.PdfPCell(title);
cell.HorizontalAlignment = IT.Element.ALIGN_CENTER;
cell.Colspan = COLUMNS;
cell.PaddingBottom = PAD_BOTTOM;
cell.GrayFill = 0.90F;
table.AddCell(cell);
// riga vuota
//table.AddCell(GetEmptyRow());
var data =
new IT.Phrase("Pett.",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase("Nome",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase("Tempo",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_RIGHT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
}
示例14: fillRow
private void fillRow(PdfPTable table) {
for (int j = 0; j < 3; j++) {
Phrase phrase = new Phrase("value");
PdfPCell cell = new PdfPCell(phrase);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell);
}
}
示例15: ClientAddress
private static IElement ClientAddress(string clientAddress)
{
var p = new Phrase("\n\nTO:\n", ElementFactory.StandardFontBold);
var p2 = new Phrase(clientAddress, ElementFactory.StandardFont);
var x = new Paragraph() { Leading = 0, MultipliedLeading = 0.8f };
x.Add(p);
x.Add(p2);
return x;
}