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,如需转载请自行联系原作者
相关文章
|
BI
Cloud Call Center
Cloud Call Center
172 2
《Alibaba_Cloud_Whitepaper_-_Data_Security_is_Now_More_Important_Than_Ever.pdf》电子版地址
Alibaba_Cloud_Whitepaper_-_Data_Security_is_Now_More_Important_Than_Ever.pdf
94 0
《Alibaba_Cloud_Whitepaper_-_Data_Security_is_Now_More_Important_Than_Ever.pdf》电子版地址
成功解决OSError: cannot open resource self.font = core.getfont(font, size, index, encoding, layout_engin
成功解决OSError: cannot open resource self.font = core.getfont(font, size, index, encoding, layout_engin
|
Java API
Access restriction: The type 'BASE64Decoder' is not API (restriction on required library xxx)
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79913071 ...
2861 0
|
安全
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?
1524 0