align2: Example code of Early Access iText

简介:
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);
        }
    }
}
 
 
本文转自 RubyPdf 的中文博客博客园博客,原文链接: http://www.cnblogs.com/hardrock/archive/2006/07/31/464184.html,如需转载请自行联系原作者
相关文章
编译mate-control-center:error: required directory ./help does not exist
编译mate-control-center:error: required directory ./help does not exist
101 0
ukui-control-center编译
ukui-control-center编译
107 0
|
应用服务中间件 Android开发
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
137 0
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
|
安全
Securing the Data Center in a Cloud First World
Looking for steps to protect your data center infrastructure with a multilayered, automated approach to security?
1515 0
Data Security Is Now More Important Than Ever
In this whitepaper, we will explore current trends in cybercrime, China’s data protection landscape and measures data center operators can take to secure businesses‘ cloud-based data storage.
1428 0