现在的位置: 首页 > 综合 > 正文

align2: Example code of Early Access iText

2011年08月16日 ⁄ 综合 ⁄ 共 1723字 ⁄ 字号 评论关闭
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);
        }
    }
}

抱歉!评论已关闭.