详解开源免费且稳定实用的.NET PDF打印组件itextSharp(.NET组件介绍

2019-05-26 01:11:55丽君

该方法根据参数获取图片实例的方式比较多,例如:Image,PdfTemplate,PRIndirectReference,byte[],Stream,string ,Uri等等,以上给出了根据Image和byte[]获取ItextSharp的image实例。

 4.Image的ScaleAbsolute():设置图片信息。

public void ScaleAbsolute(float newWidth, float newHeight)
{
  this.plainWidth = newWidth;
  this.plainHeight = newHeight;
  float[] matrix = this.Matrix;
  this.scaledWidth = matrix[6] - matrix[4];
  this.scaledHeight = matrix[7] - matrix[5];
  this.WidthPercentage = 0f;
}

 以上代码可以看出,设置图片的信息主要包括高度、宽度、排列等信息。

 5.Anchor类的Process()方法:重写链接的处理方法。

public override bool Process(IElementListener listener)
{
  try
  {
    bool flag = (this.reference != null) && this.reference.StartsWith("#");
    bool flag2 = true;
    foreach (Chunk chunk in this.Chunks)
    {
      if (((this.name != null) && flag2) && !chunk.IsEmpty())
      {
        chunk.SetLocalDestination(this.name);
        flag2 = false;
      }
      if (flag)
      {
        chunk.SetLocalGoto(this.reference.Substring(1));
      }
      else if (this.reference != null)
      {
        chunk.SetAnchor(this.reference);
      }
      listener.Add(chunk);
    }
    return true;
  }
  catch (DocumentException)
  {
    return false;
  }
}

以上方法可以看到,该方法是在本类中被重写,用以处理链接的相关信息。

6.PageSize:设置纸张的类型。

public class PageSize
{
  // Fields
  public static readonly Rectangle _11X17;
  public static readonly Rectangle A0;
  public static readonly Rectangle A1;
  public static readonly Rectangle A10;
  public static readonly Rectangle A2;
  public static readonly Rectangle A3;
  public static readonly Rectangle A4;
  public static readonly Rectangle A4_LANDSCAPE;
  public static readonly Rectangle A5;
  public static readonly Rectangle A6;
  public static readonly Rectangle A7;
  public static readonly Rectangle A8;
  public static readonly Rectangle A9;
  public static readonly Rectangle ARCH_A;
  public static readonly Rectangle ARCH_B;
  public static readonly Rectangle ARCH_C;
  public static readonly Rectangle ARCH_D;
  public static readonly Rectangle ARCH_E;
  public static readonly Rectangle B0;
  public static readonly Rectangle B1;
  public static readonly Rectangle B10;
  public static readonly Rectangle B2;
  public static readonly Rectangle B3;
  public static readonly Rectangle B4;
  public static readonly Rectangle B5;
  public static readonly Rectangle B6;
  public static readonly Rectangle B7;
  public static readonly Rectangle B8;
  public static readonly Rectangle B9;
  public static readonly Rectangle CROWN_OCTAVO;
  public static readonly Rectangle CROWN_QUARTO;
  public static readonly Rectangle DEMY_OCTAVO;
  public static readonly Rectangle DEMY_QUARTO;
  public static readonly Rectangle EXECUTIVE;
  public static readonly Rectangle FLSA;
  public static readonly Rectangle FLSE;
  public static readonly Rectangle HALFLETTER;
  public static readonly Rectangle ID_1;
  public static readonly Rectangle ID_2;
  public static readonly Rectangle ID_3;
  public static readonly Rectangle LARGE_CROWN_OCTAVO;
  public static readonly Rectangle LARGE_CROWN_QUARTO;
  public static readonly Rectangle LEDGER;
  public static readonly Rectangle LEGAL;
  public static readonly Rectangle LEGAL_LANDSCAPE;
  public static readonly Rectangle LETTER;
  public static readonly Rectangle LETTER_LANDSCAPE;
  public static readonly Rectangle NOTE;
  public static readonly Rectangle PENGUIN_LARGE_PAPERBACK;
  public static readonly Rectangle PENGUIN_SMALL_PAPERBACK;
  public static readonly Rectangle POSTCARD;
  public static readonly Rectangle ROYAL_OCTAVO;
  public static readonly Rectangle ROYAL_QUARTO;
  public static readonly Rectangle SMALL_PAPERBACK;
  public static readonly Rectangle TABLOID;

  // Methods
  static PageSize();
  public PageSize();
  public static Rectangle GetRectangle(string name);
}