2013-03-01 107 views
0

我使用itextsharp預定義頁面大小填充了下拉列表。
我需要選定的頁面尺寸傳遞到:無法投射'System.String'類型的對象來鍵入'iTextSharp.text.Rectangle'

pdfDoc = new Document(dropdownlist.selectedvalue, 50, 50, 50, 50); 

我得到錯誤

無法轉換類型 'System.String' 輸入 「iTextSharp.text的對象。矩形「

我該如何傳遞代表最常見紙張大小的矩形對象,並從下拉菜單中選擇

如何將字符串投射到iTextSharp.text.Rectangle

在此先感謝

回答

1

不能一個StringiTextSharp.text.Rectangle,因爲它們是完全不同的班級,沒有隱含的翻譯。

但有一個實用工具類PageSize您可能感興趣的

namespace iTextSharp.text { 
    /// <summary> 
    /// The PageSize-object contains a number of read only rectangles representing the most common paper sizes. 
    /// </summary> 
    /// <seealso cref="T:iTextSharp.text.RectangleReadOnly"/> 
    public class PageSize { 
     [...] 
     /** 
     * This method returns a Rectangle based on a String. 
     * Possible values are the the names of a constant in this class 
     * (for instance "A4", "LETTER",...) or a value like "595 842" 
     */ 
     public static Rectangle GetRectangle(String name) { 
      [...] 
     } 
    } 
} 

您可以嘗試使用此方法來檢索RectangleString

相關問題