iTextSharp.text.pdf.PdfAnnotation.SetAppearance C# (CSharp) Метод

SetAppearance() публичный Метод

public SetAppearance ( PdfName ap, PdfTemplate template ) : void
ap PdfName
template PdfTemplate
Результат void
        public void SetAppearance(PdfName ap, PdfTemplate template)
        {
            PdfDictionary dic = (PdfDictionary)Get(PdfName.AP);
            if (dic == null)
                dic = new PdfDictionary();
            dic.Put(ap, template.IndirectReference);
            Put(PdfName.AP, dic);
            if (!form)
                return;
            if (templates == null)
                templates = new Dictionary<PdfTemplate,object>();
            templates[template] = null;
        }

Same methods

PdfAnnotation::SetAppearance ( PdfName ap, string state, PdfTemplate template ) : void

Usage Example

Пример #1
0
// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        Rectangle rect = new Rectangle(100, 400, 500, 800);
        rect.Border = Rectangle.BOX;
        rect.BorderWidth = 0.5f;
        rect.BorderColor = new BaseColor(0xFF, 0x00, 0x00);
        document.Add(rect);

        PdfIndirectObject streamObject = null;
        using (FileStream fs = 
          new FileStream(RESOURCE, FileMode.Open, FileAccess.Read))
        {
          PdfStream stream3D = new PdfStream(fs, writer);
          
          stream3D.Put(PdfName.TYPE, new PdfName("3D"));
          stream3D.Put(PdfName.SUBTYPE, new PdfName("U3D"));
          stream3D.FlateCompress();
          streamObject = writer.AddToBody(stream3D);
          stream3D.WriteLength();
        }
            
        PdfDictionary dict3D = new PdfDictionary();
        dict3D.Put(PdfName.TYPE, new PdfName("3DView"));
        dict3D.Put(new PdfName("XN"), new PdfString("Default"));
        dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
        dict3D.Put(new PdfName("MS"), PdfName.M);
        dict3D.Put(
          new PdfName("C2W"),
          new PdfArray(
            new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }
          )
        );
        dict3D.Put(PdfName.CO, new PdfNumber(235));

        PdfIndirectObject dictObject = writer.AddToBody(dict3D); 
            
        PdfAnnotation annot = new PdfAnnotation(writer, rect);
        annot.Put(PdfName.CONTENTS, new PdfString("3D Model"));
        annot.Put(PdfName.SUBTYPE, new PdfName("3D"));
        annot.Put(PdfName.TYPE, PdfName.ANNOT);
        annot.Put(new PdfName("3DD"), streamObject.IndirectReference);
        annot.Put(new PdfName("3DV"), dictObject.IndirectReference);
        PdfAppearance ap = writer.DirectContent.CreateAppearance(
          rect.Width, rect.Height
        );
        annot.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
        annot.SetPage();

        writer.AddAnnotation(annot);      
      }
    }