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);
}
}
}
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);
}
}
}
本文转自
RubyPdf 的中文博客博客园博客,原文链接:
http://www.cnblogs.com/hardrock/archive/2006/07/31/464184.html,如需转载请自行联系原作者