form_checkbox:一个在PDF上添加CheckBox的例子(来自itextpdf的ex系列)

有人需要就贴了出来了,这个系列的100多个demo去年已经翻译完毕,一直想不出有什么必要放出来,搁置半年了。
None.gif using  System;
None.gif
using  iTextSharp.text;
None.gif
using  iTextSharp.text.pdf;
None.gif
using  System.IO;
None.gif
public   class  form_checkbox
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
InBlock.gif    
InBlock.gif    [STAThread]
InBlock.gif    
public static void  Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        Document document 
= new Document(PageSize.A4, 50505050);
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// creation of the different writers
InBlock.gif
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"e:\java\form_checkbox.Pdf", FileMode.Create));
InBlock.gif            
InBlock.gif            document.Open();
InBlock.gif            PdfContentByte cb 
= writer.DirectContent;
InBlock.gif            cb.MoveTo(
00);
InBlock.gif            PdfFormField field 
= PdfFormField.CreateCheckBox(writer);
InBlock.gif            PdfAppearance tpOff 
= cb.CreateAppearance(2020);
InBlock.gif            PdfAppearance tpOn 
= cb.CreateAppearance(2020);
InBlock.gif            tpOff.Rectangle(
111818);
InBlock.gif            tpOff.Stroke();
InBlock.gif            
InBlock.gif            tpOn.SetRGBColorFill(
255128128);
InBlock.gif            tpOn.Rectangle(
111818);
InBlock.gif            tpOn.FillStroke();
InBlock.gif            tpOn.MoveTo(
11);
InBlock.gif            tpOn.LineTo(
1919);
InBlock.gif            tpOn.MoveTo(
119);
InBlock.gif            tpOn.LineTo(
191);
InBlock.gif            tpOn.Stroke();
InBlock.gif            
InBlock.gif            field.SetWidget(
new Rectangle(100700120720), PdfAnnotation.HIGHLIGHT_INVERT);
InBlock.gif            field.FieldName
=("Urgent");
InBlock.gif            field.ValueAsName
=("Off");
InBlock.gif            field.AppearanceState
=("Off");
InBlock.gif            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, 
"Off", tpOff);
InBlock.gif            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, 
"On", tpOn);
InBlock.gif            writer.AddAnnotation(field);
InBlock.gif            document.Close();
InBlock.gif            System.Console.Out.WriteLine(
"FIM.");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (System.Exception de)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            System.Console.Error.WriteLine(de.Message);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值