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, 50505050);
        
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(
250500);
            cb.LineTo(
250800);
            cb.MoveTo(
50700);
            cb.LineTo(
400700);
            cb.MoveTo(
50650);
            cb.LineTo(
400650);
            cb.MoveTo(
50600);
            cb.LineTo(
400600);
            cb.Stroke();
            cb.BeginText();
            cb.SetFontAndSize(bf, 
12);
            
string text = "Sample text for alignment";
            cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, text 
+ " Center"2507000);
            cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, text 
+ " Right"2506500);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text 
+ " Left"2506000);
            cb.SetTextMatrix(
100400);
            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);
        }
    }
}
posted on 2006-07-31 16:46  RubyPDF  阅读(1997)  评论(8编辑  收藏  举报