本文整理汇总了C#中iTextSharp.text.Chunk类的典型用法代码示例。如果您正苦于以下问题:C# Chunk类的具体用法?C# Chunk怎么用?C# Chunk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chunk类属于iTextSharp.text命名空间,在下文中一共展示了Chunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src) {
// Create a table with named actions
Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
PdfPTable table = new PdfPTable(4);
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Chunk first = new Chunk( ((char)220).ToString() , symbol);
first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
table.AddCell(new Phrase(first));
Chunk previous = new Chunk( ((char)172).ToString(), symbol);
previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
table.AddCell(new Phrase(previous));
Chunk next = new Chunk( ((char)174).ToString(), symbol);
next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
table.AddCell(new Phrase(next));
Chunk last = new Chunk( ((char)222).ToString(), symbol);
last.SetAction(new PdfAction(PdfAction.LASTPAGE));
table.AddCell(new Phrase(last));
table.TotalWidth = 120;
// Create a reader
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream()) {
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
// Add the table to each page
PdfContentByte canvas;
for (int i = 0; i < reader.NumberOfPages; ) {
canvas = stamper.GetOverContent(++i);
table.WriteSelectedRows(0, -1, 696, 36, canvas);
}
}
return ms.ToArray();
}
}
示例2: PageEventTest01
public void PageEventTest01() {
String fileName = "pageEventTest01.pdf";
MemoryStream baos = new MemoryStream();
Document doc = new Document(PageSize.LETTER, 144, 144, 144, 144);
PdfWriter writer = PdfWriter.GetInstance(doc, baos);
writer.PageEvent = new MyEventHandler();
writer.SetTagged();
doc.Open();
Chunk c = new Chunk("This is page 1");
doc.Add(c);
doc.Close();
File.WriteAllBytes(OUTPUT_FOLDER + fileName, baos.ToArray());
baos.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + fileName, TEST_RESOURCES_PATH + fileName, OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例3: GeneratePdfElement
public override iTextSharp.text.IElement GeneratePdfElement()
{
ChunkStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;
iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(Text, (iText.Font)style.Font);
return chunk;
}
示例4: GetFormattedText
public static IT.Chunk GetFormattedText(Text text)
{
IT.Chunk formattedChuck = new IT.Chunk(text.TextContent);
formattedChuck.Font = GetFormattedFont(text.Font);
return formattedChuck;
}
示例5: CreatePdf
// ---------------------------------------------------------------------------
/**
* Creates a PDF document.
* @param stream Stream for the new PDF document
*/
public void CreatePdf(Stream stream) {
string RESOURCE = Utility.ResourcePosters;
// 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;
PdfAnnotation annotation;
foreach (Movie movie in PojoFactory.GetMovies()) {
phrase = new Phrase(movie.MovieTitle);
chunk = new Chunk("\u00a0\u00a0");
annotation = PdfAnnotation.CreateFileAttachment(
writer, null,
movie.MovieTitle, null,
Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
string.Format("img_{0}.jpg", movie.Imdb)
);
annotation.Put(PdfName.NAME, new PdfString("Paperclip"));
chunk.SetAnnotation(annotation);
phrase.Add(chunk);
document.Add(phrase);
document.Add(PojoToElementFactory.GetDirectorList(movie));
document.Add(PojoToElementFactory.GetCountryList(movie));
}
}
}
示例6: ApplyForText
public void ApplyForText(PdfContentByte cb, IDictionary<String, String> css, Chunk chunk)
{
SetStrokeAndFillColor(cb, css);
SetStrokeAndFill(cb, css);
try
{
Font font = new Font(Font.FontFamily.COURIER, 6, Font.NORMAL, BaseColor.BLACK);
Font font2 = chunk.Font;
BaseFont bf2 = font2.BaseFont;
//BaseFont bf = ;
if (bf2 == null)
{
cb.SetFontAndSize(font.GetCalculatedBaseFont(false), font2.Size);
}
else
{
cb.SetFontAndSize(bf2, font2.Size);
}
} catch { }
}
示例7: 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);
}
}
}
示例8: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable footer = new PdfPTable(3);
footer.SetWidths(new float[] { 88f, 7f, 5f });
footer.WidthPercentage = 100;
footer.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);
PdfPCell emptycell = new PdfPCell();
emptycell.Border = 0;
footer.AddCell(emptycell);
Chunk text = new Chunk(string.Format(GlobalStringResource.PageOfFooter,
document.PageNumber), FontFactory.GetFont(FontFactory.HELVETICA, 8));
PdfPCell footerCell = new PdfPCell(new Phrase(text));
footerCell.Border = 0;
footerCell.HorizontalAlignment = Element.ALIGN_RIGHT;
footer.AddCell(footerCell);
PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total));
cell.Border = 0;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
footer.AddCell(cell);
footer.WriteSelectedRows(0, -1, 50, (document.BottomMargin - 10), writer.DirectContent);
}
示例9: 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));
}
}
}
示例10: Write
// ===========================================================================
public void Write(Stream stream) {
// step 1
using (Document document = new Document()) {
// step 2
PdfWriter.GetInstance(document, stream).InitialLeading = 16;
// step 3
document.Open();
// add the ID in another font
Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE);
// step 4
using (var c = AdoDB.Provider.CreateConnection()) {
c.ConnectionString = AdoDB.CS;
using (DbCommand cmd = c.CreateCommand()) {
cmd.CommandText =
"SELECT country,id FROM film_country ORDER BY country";
c.Open();
using (var r = cmd.ExecuteReader()) {
while (r.Read()) {
var country = r.GetString(0);
var ID = r.GetString(1);
document.Add(new Chunk(country));
document.Add(new Chunk(" "));
Chunk id = new Chunk(ID, font);
// with a background color
id.SetBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
// and a text rise
id.SetTextRise(6);
document.Add(id);
document.Add(Chunk.NEWLINE);
}
}
}
}
}
}
示例11: Add
/**
* Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
*
* @param o the object to add.
* @return true if adding the object succeeded
*/
public override bool Add(Object o) {
if (o is ListItem) {
ListItem item = (ListItem) o;
Chunk chunk = new Chunk(preSymbol, symbol.Font);
switch (type ) {
case 0:
chunk.Append(((char)(first + list.Count + 171)).ToString());
break;
case 1:
chunk.Append(((char)(first + list.Count + 181)).ToString());
break;
case 2:
chunk.Append(((char)(first + list.Count + 191)).ToString());
break;
default:
chunk.Append(((char)(first + list.Count + 201)).ToString());
break;
}
chunk.Append(postSymbol);
item.ListSymbol = chunk;
item.SetIndentationLeft(symbolIndent, autoindent);
item.IndentationRight = 0;
list.Add(item);
return true;
} else if (o is List) {
List nested = (List) o;
nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
first--;
list.Add(nested);
return true;
} else if (o is String) {
return this.Add(new ListItem((string) o));
}
return false;
}
示例12: MakeReport
// public static SimpleAttendanceList GetInstance(Selection selection,
// Rectangle pageSize,
// string reportFile) {
//
// if (instance == null)
// instance = new SimpleAttendanceList(selection, pageSize, reportFile);
// else {
// instance.selection = selection;
// instance.reportFile = reportFile;
// }
//
// if (!this.doc.IsOpen())
// this.doc.Open();
//
// return instance;
// }
public override void MakeReport()
{
// Subtitle = Event name
Chunk c = new Chunk(this.selection.Events[0].Name,
FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.BOLD));
Paragraph par = new Paragraph(c);
par.Alignment = Rectangle.ALIGN_CENTER;
this.doc.Add(par);
// List
Table t = new Table(2);
t.Border = 0;
t.DefaultCellBorder = 0;
Cell cell = new Cell();
cell.HorizontalAlignment = Element.ALIGN_CENTER;
t.DefaultCell = cell; // Default cell
Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE);
cell = new Cell();
Chunk texto = new Chunk("Nombre y Apellido", fuenteTitulo);
cell.Add(texto);
t.AddCell(cell);
cell = new Cell();
texto = new Chunk("¿Asistió?", fuenteTitulo);
cell.Add(texto);
t.AddCell(cell);
Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10);
Font fuenteSi = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
fuenteSi.Color = Color.BLUE;
Font fuenteNo = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
fuenteNo.Color = Color.RED;
foreach (Person p in this.selection.Persons) {
cell = new Cell();
texto = new Chunk(p.Name + " " + p.Surname, fuenteDatos);
cell.Add(texto);
t.AddCell(cell);
cell = new Cell();
if (AttendancesManager.Instance.Attended(p, this.selection.Events[0]))
texto = new Chunk("Si", fuenteSi);
else
texto = new Chunk("No", fuenteNo);
cell.Add(texto);
t.AddCell(cell);
}
this.doc.Add(t);
}
示例13: ResolveDoubleQuotedFontFamily
public void ResolveDoubleQuotedFontFamily() {
Tag t = new Tag(null);
t.CSS["color"] = "#000000";
t.CSS["font-family"] = "\"Helvetica\"";
t.CSS["font-size"] = "12pt";
Chunk c = new Chunk("default text for chunk creation");
applier.Apply(c, t);
Assert.AreEqual("Helvetica", c.Font.Familyname);
}
示例14: Text
public Text(Chunk chunk, IDictionary<String, String> css, IList<int> dx, IList<int> dy) : base(css)
{
this.chunk = chunk;
this.x = 0;
this.y = 0;
this.relative = true;
this.dx = dx;
this.dy = dy;
}
示例15: SetUp
public void SetUp() {
LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
t = new Tag(null);
t.CSS["color"] = "#000000";
t.CSS["font-family"] = "Helvetica";
t.CSS["font-size"] = "12pt";
c = new Chunk("default text for chunk creation");
applier.Apply(c, t);
}