Storing the value of a PdfSharpCore (XPen) enumeration

I’m pretty sure that I’m just missing something simple with this and am going to smack my forehead when someone answers but the dent in my desk is getting pretty large at this point.

I’m tasked with building a organizational library for PdfSharpCore so that our developers can all sync up how we are using it and to allow for swapping it out if we find a better or more useful tool (loose coupling with PdfSharpCore)

We do a lot with stamps on PDFs so I have a structure that we will use to format dynamic stamps. We build the stamps at runtime so that they include the datetime that the document was stamped along with who processed the document

So currently I have the following class built to hold the stamp structure.

public class StampLayout {
    // Class Properties
    public Border border { get; set; }
    public TextObject stampTitle { get; set; }
    public TextObject supplementalText { get; set; }
    public TextObject username { get; set; }
    public DateTime timeStamp { get; set; }

    public struct Border {
        public int XCor { get; set; }
        public int YCor { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int Thickness { get; set; }
        public int Color { get; set; }
    }

    public struct TextObject {
        public string FontName { get; set; }
        public int FontSize { get; set; }
        public string FontStyle { get; set; }
        public string TextValue { get; set; }
        public string FontColor { get; set; }
        public int XCor { get; set; }
        public int YCor { get; set; }
        public string FontFormat { get; set; }
    }
}

The problem that I am having is holding the values for Color and FontColor. They look like they are enums so it should be a matter of just converting the color to an int and storing that. When I try using it, I get the error “Cannot convert int to PdfSharpCore.Drawing.Color”

Changing the variable type now strongly couples the developer’s code to PdfSharpCore, which we want to avoid. My next step would to be to build a conversion method in the library and call it every time I needed to draw something. That seems a bit hackish to me and I would have to make sure color’s were not added, removed or moved for each version of PdfSharpCore.

I just wondered if anyone could think of any simpler means of storing the value of the enum.

2

PDFSharp uses the type XColor for colors. There is no enumeration named Color in PDFSharp as far as I can see.

The type XColor is not a simple enumeration but a struct.

The probably best way to store an XColor value is by storing a set of A,R,G,B values, especially if you maybe later on want to use a different library with a different color type. All will support converting to and from ARGB values.

  • A = Alpha color channel
  • R = Red color channel
  • G = Green color channel
  • B = Blue color channel

The XColor type has this static method to create a XColor value from a set of ARGB values:

public static XColor FromArgb(int alpha, int red, int green, int blue)

To convert a XColor value to ARGB values, just read its properties A, R, G and B.

The A property is a floating point value from 0 to 1. To get the integer representation of a value from 0 to 255 that is expected by the FromArgb method, multiply it with 255.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật