您的位置:首页 > 其它

align2: Example code of Early Access iText

2006-07-31 16:46 513 查看
using System;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
public class align2
{

[STAThread]
public static void Main(string[] args)
{
// creation of the document with a certain size and certain margins
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try
{
// creation of the different writers
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"e:\java\pdfalign2.Pdf", FileMode.Create));

document.Open();
BaseFont bf = BaseFont.CreateFont("Helvetica", "Cp1252", false);
PdfContentByte cb = writer.DirectContent;
cb.SetLineWidth(0f);
cb.MoveTo(250, 500);
cb.LineTo(250, 800);
cb.MoveTo(50, 700);
cb.LineTo(400, 700);
cb.MoveTo(50, 650);
cb.LineTo(400, 650);
cb.MoveTo(50, 600);
cb.LineTo(400, 600);
cb.Stroke();
cb.BeginText();
cb.SetFontAndSize(bf, 12);
string text = "Sample text for alignment";
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250, 700, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, text + " Right", 250, 650, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text + " Left", 250, 600, 0);
cb.SetTextMatrix(100, 400);
cb.SetFontAndSize(bf, 14);
cb.ShowText("Text at position 100,400.");
cb.EndText();
document.Close();
System.Console.Out.WriteLine("FIM.");
}
catch (System.Exception de)
{
System.Console.Error.WriteLine(de.Message);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: