本文整理汇总了C#中iTextSharp.text.pdf.ColumnText类的典型用法代码示例。如果您正苦于以下问题:C# ColumnText类的具体用法?C# ColumnText怎么用?C# ColumnText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColumnText类属于iTextSharp.text.pdf命名空间,在下文中一共展示了ColumnText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: OnOpenDocument
// we override the onOpenDocument method
public override void OnOpenDocument(PdfWriter writer, Document document)
{
_bf = _normalFont.GetCalculatedBaseFont(false);
_cb = writer.DirectContent;
_ct = new ColumnText(_cb);
base.OnOpenDocument(writer, document);
}
示例3: CalculateTextHeight
public Unit CalculateTextHeight(string text, Unit width)
{
var ct = new ColumnText(null) { Leading = (float) leading };
ct.AddText(new Phrase(text, Font));
ct.SetSimpleColumn(0, 0, (float) width.Points, float.MaxValue);
ct.Go(true);
var test = ct.LinesWritten*ct.Leading.points();
return test;
}
示例4: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document(PageSize.A4.Rotate()))
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
ColumnText column = new ColumnText(writer.DirectContent);
List<string> days = PojoFactory.GetDays();
// COlumn definition
float[][] x = {
new float[] { document.Left, document.Left + 380 },
new float[] { document.Right - 380, document.Right }
};
// Loop over the festival days
foreach (string day in days)
{
// add content to the column
column.AddElement(GetTable(day));
int count = 0;
float height = 0;
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
// render the column as long as it has content
while (ColumnText.HasMoreText(status))
{
// add the top-level header to each new page
if (count == 0)
{
height = AddHeaderTable(document, day, writer.PageNumber);
}
// set the dimensions of the current column
column.SetSimpleColumn(
x[count][0], document.Bottom,
x[count][1], document.Top - height - 10
);
// render as much content as possible
status = column.Go();
// go to a new page if you've reached the last column
if (++count > 1)
{
count = 0;
document.NewPage();
}
}
document.NewPage();
}
}
}
示例5: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src
* @param src the original PDF
* @param stationery the resulting PDF
*/
public byte[] ManipulatePdf(byte[] src, byte[] stationery)
{
ColumnText ct = new ColumnText(null);
string SQL =
@"SELECT country, id FROM film_country
ORDER BY country
";
using (var c = AdoDB.Provider.CreateConnection())
{
c.ConnectionString = AdoDB.CS;
using (DbCommand cmd = c.CreateCommand())
{
cmd.CommandText = SQL;
c.Open();
using (var r = cmd.ExecuteReader())
{
while (r.Read())
{
ct.AddElement(new Paragraph(
24, new Chunk(r["country"].ToString())
));
}
}
}
}
// Create a reader for the original document and for the stationery
PdfReader reader = new PdfReader(src);
PdfReader rStationery = new PdfReader(stationery);
using (MemoryStream ms = new MemoryStream())
{
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Create an imported page for the stationery
PdfImportedPage page = stamper.GetImportedPage(rStationery, 1);
int i = 0;
// Add the content of the ColumnText object
while (true)
{
// Add a new page
stamper.InsertPage(++i, reader.GetPageSize(1));
// Add the stationary to the new page
stamper.GetUnderContent(i).AddTemplate(page, 0, 0);
// Add as much content of the column as possible
ct.Canvas = stamper.GetOverContent(i);
ct.SetSimpleColumn(36, 36, 559, 770);
if (!ColumnText.HasMoreText(ct.Go()))
break;
}
}
return ms.ToArray();
}
}
示例6: DrawItem
public override void DrawItem(PdfWriter pdfWriter,
ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
{
if (pdfWriter == null) {
throw new ArgumentNullException("pdfWriter");
}
if (converter == null) {
throw new ArgumentNullException("converter");
}
base.DrawItem(pdfWriter,converter);
iTextSharp.text.Font font = null;
if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point) {
font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
BaseFont.IDENTITY_H,
this.StyleDecorator.Font.Size,
(int)this.StyleDecorator.Font.Style,
this.StyleDecorator.PdfForeColor);
} else {
font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
BaseFont.IDENTITY_H,
UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point,
(int)this.StyleDecorator.Font.Style,
this.StyleDecorator.PdfForeColor);
}
base.Decorate();
PdfContentByte contentByte = base.PdfWriter.DirectContent;
CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font);
ColumnText columnText = new ColumnText(contentByte);
iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment);
string formatedText = this.text;
if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) {
formatedText = StandardFormatter.FormatOutput(this.text,this.StyleDecorator.FormatString,
this.StyleDecorator.DataType,String.Empty);
}
Chunk chunk = new Chunk(formatedText,font);
columnText.AddText(chunk);
columnText.Go();
}
示例7: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// step 1
using (Document document = new Document(PageSize.A4.Rotate()))
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
ColumnText ct = new ColumnText(writer.DirectContent);
int column = 0;
ct.SetSimpleColumn(
COLUMNS[column, 0], COLUMNS[column, 1],
COLUMNS[column, 2], COLUMNS[column, 3]
);
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
float y;
Image img;
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
y = ct.YLine;
img = Image.GetInstance(
Path.Combine(RESOURCE, movie.Imdb + ".jpg")
);
img.ScaleToFit(80, 1000);
AddContent(ct, movie, img);
status = ct.Go(true);
if (ColumnText.HasMoreText(status))
{
column = (column + 1) % 4;
if (column == 0)
{
document.NewPage();
}
ct.SetSimpleColumn(
COLUMNS[column, 0], COLUMNS[column, 1],
COLUMNS[column, 2], COLUMNS[column, 3]
);
y = COLUMNS[column, 3];
}
ct.YLine = y;
ct.SetText(null);
AddContent(ct, movie, img);
status = ct.Go();
}
}
}
示例8: Write
// ===========================================================================
public override 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
PdfContentByte canvas = writer.DirectContent;
DrawRectangles(canvas);
ColumnText ct = new ColumnText(canvas);
ct.Alignment = Element.ALIGN_JUSTIFIED;
ct.Leading = 14;
int column = 0;
ct.SetColumns(
new float[] { 36, 806, 36, 670, 108, 670, 108, 596, 36, 596, 36, 36 },
new float[] { 296, 806, 296, 484, 259, 484, 259, 410, 296, 410, 296, 36 }
);
ct.SetColumns(LEFT[column], RIGHT[column]);
// ct.SetColumns(LEFT[column], RIGHT[column]);
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
Phrase p;
float y;
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
y = ct.YLine;
p = CreateMovieInformation(movie);
ct.AddText(p);
status = ct.Go(true);
if (ColumnText.HasMoreText(status))
{
column = Math.Abs(column - 1);
if (column == 0)
{
document.NewPage();
DrawRectangles(canvas);
}
ct.SetColumns(LEFT[column], RIGHT[column]);
y = 806;
}
ct.YLine = y;
ct.SetText(p);
status = ct.Go();
}
}
}
示例9: Write
// ===========================================================================
public override 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
ColumnText ct = new ColumnText(writer.DirectContent)
{
Alignment = Element.ALIGN_JUSTIFIED,
ExtraParagraphSpace = 6,
Leading = 14,
Indent = 10,
RightIndent = 3,
SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO
};
int column = 0;
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
ct.SetSimpleColumn(
COLUMNS[column][0], COLUMNS[column][1],
COLUMNS[column][2], COLUMNS[column][3]
);
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
ct.AddText(CreateMovieInformation(movie));
status = ct.Go();
if (ColumnText.HasMoreText(status))
{
column = Math.Abs(column - 1);
if (column == 0)
{
document.NewPage();
}
ct.SetSimpleColumn(
COLUMNS[column][0], COLUMNS[column][1],
COLUMNS[column][2], COLUMNS[column][3]
);
ct.YLine = COLUMNS[column][3];
status = ct.Go();
}
}
}
}
示例10: Write
// ===========================================================================
public override 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
ColumnText ct = new ColumnText(writer.DirectContent);
int column = 0;
ct.SetSimpleColumn(
COLUMNS[column][0], COLUMNS[column][1],
COLUMNS[column][2], COLUMNS[column][3]
);
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
Phrase p;
float y;
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
y = ct.YLine;
p = CreateMovieInformation(movie);
ct.AddText(p);
status = ct.Go(true);
if (ColumnText.HasMoreText(status))
{
column = Math.Abs(column - 1);
if (column == 0)
{
document.NewPage();
}
ct.SetSimpleColumn(
COLUMNS[column][0], COLUMNS[column][1],
COLUMNS[column][2], COLUMNS[column][3]
);
y = COLUMNS[column][3];
}
ct.YLine = y;
ct.SetText(p);
status = ct.Go(false);
}
}
}
示例11: Write
// ===========================================================================
public virtual 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
IEnumerable<Movie> movies = PojoFactory.GetMovies();
ColumnText ct = new ColumnText(writer.DirectContent);
foreach (Movie movie in movies)
{
ct.AddText(CreateMovieInformation(movie));
ct.AddText(Chunk.NEWLINE);
}
ct.Alignment = Element.ALIGN_JUSTIFIED;
ct.ExtraParagraphSpace = 6;
ct.SetLeading(0, 1.2f);
ct.FollowingIndent = 27;
int linesWritten = 0;
int column = 0;
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
while (ColumnText.HasMoreText(status))
{
ct.SetSimpleColumn(
COLUMNS[column][0], COLUMNS[column][1],
COLUMNS[column][2], COLUMNS[column][3]
);
ct.YLine = COLUMNS[column][3];
status = ct.Go();
linesWritten += ct.LinesWritten;
column = Math.Abs(column - 1);
if (column == 0) document.NewPage();
}
ct.AddText(new Phrase("Lines written: " + linesWritten));
ct.Go();
}
}
示例12: Go
public void Go()
{
var outputFile = Helpers.IO.GetClassOutputPath(this);
var imagePath = Helpers.IO.GetInputFilePath("100x100.jpg");
var imageSpacerPath = Helpers.IO.GetInputFilePath("20x20.png");
var testText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
using (FileStream stream = new FileStream(
outputFile,
FileMode.Create,
FileAccess.Write))
{
using (Document document = new Document())
{
Image img = Image.GetInstance(imagePath);
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// writer.InitialLeading = 108;
document.Open();
// document.Add(new Paragraph(img.Height.ToString()));
img.Alignment = Image.ALIGN_LEFT | Image.TEXTWRAP;
img.BorderWidth = 10;
img.ScaleToFit(1000, 72);
document.Add(img);
//img.BorderColor = BaseColor.RED;
var p = new Paragraph();
p.Add(testText);
document.Add(p);
PdfContentByte cb = writer.DirectContent;
ColumnText ct = new ColumnText(cb);
ct.SetSimpleColumn(new Phrase(new Chunk(testText, FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.NORMAL))),
46, 190, 530, 36, 25, Element.ALIGN_LEFT | Element.ALIGN_TOP);
ct.Go();
// document.Add(new Paragraph(testText));
// document.Add(new Chunk(testText));
}
}
}
示例13: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream) {
// step 1
using (Document document = new Document(PageSize.A4)) {
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
BaseFont bf = BaseFont.CreateFont(
"c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, true
);
Font font = new Font(bf, 14);
document.Add(new Paragraph("Movie title: Nina's Tragedies"));
document.Add(new Paragraph("directed by Savi Gabizon"));
ColumnText column = new ColumnText(writer.DirectContent);
column.SetSimpleColumn(36, 770, 569, 36);
column.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
column.AddElement(new Paragraph(MOVIE, font));
column.Go();
}
}
示例14: DrawItem
public override void DrawItem(PdfWriter pdfWriter,
ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
{
if (pdfWriter == null) {
throw new ArgumentNullException("pdfWriter");
}
if (converter == null) {
throw new ArgumentNullException("converter");
}
base.DrawItem(pdfWriter,converter);
base.Decorate();
PdfContentByte contentByte = base.PdfWriter.DirectContent;
iTextSharp.text.Font font = CreateFontFromFactory(this.StyleDecorator);
CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font);
ColumnText columnText = new ColumnText(contentByte);
if (StyleDecorator.RightToLeft.ToString() == "Yes") {
columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
}
iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment);
string formatedText = this.Text;
if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) {
formatedText = StandardFormatter.FormatOutput(this.Text,this.StyleDecorator.FormatString,
this.StyleDecorator.DataType,String.Empty);
}
Chunk chunk = new Chunk(formatedText,font);
columnText.AddText(chunk);
columnText.Go();
}
示例15: NestedTablesTest01
public void NestedTablesTest01() {
String output = "nestedTablesTest.pdf";
String cmp = "cmp_nestedTablesTest.pdf";
Stopwatch timer = new Stopwatch();
timer.Start();
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, File.Create(outFolder + output));
doc.Open();
ColumnText column = new ColumnText(writer.DirectContent);
column.SetSimpleColumn(72, 72, 523, 770);
column.AddElement(CreateNestedTables(15));
column.Go();
doc.Close();
timer.Stop();
Console.WriteLine(timer.ElapsedMilliseconds);
CompareDocuments(output, cmp, false);
}