PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 4:24 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Jun 12, 2015 6:45 pm 
Offline

Joined: Wed Oct 29, 2014 3:46 pm
Posts: 4
I am using pdf sharp to export a chart legend. I am using a forloop and a table to display the properties. There is actually only one property. The Subdivision name. The object has the right rgb color to use. How can I apply a squares next to it just as chart legends display the series's? forgive me for the variable names, I am going off a example.

Code:
 //Writting Table Header Text
                textformater.DrawString(" Color", tableheader, XBrushes.Black, snoColumn);
                textformater.DrawString(" Subdivision Name", tableheader, XBrushes.Black, snoStudentName);


                foreach (var item in data)
                {
                    y = y + 30;
                    XRect snoColumnVal = new XRect(35, y, 70, height);
                    XRect snoStudentNameVal = new XRect(100, y, 250, height);
                    textformater.DrawString(item.Color, tableheader, XBrushes.Black, snoColumnVal);
                    textformater.DrawString(item.Name, tableheader, XBrushes.Black, snoStudentNameVal);

                }


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 13, 2015 6:55 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Answered here:
http://stackoverflow.com/a/30815707/1015447

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 15, 2015 3:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Some sample code:
Code:
struct RowItem
{
    public int R, G, B;
    public string Text;
}

static void Demo()
{
    var data = new[]
                   {
                       new RowItem{R = 255, G = 0, B = 0, Text = "Red row"},
                       new RowItem{R = 0, G = 255, B = 0, Text = "Green row"},
                       new RowItem{R = 255, G = 255, B = 0, Text = "Yellow row"},
                       new RowItem{R = 0, G = 0, B = 255, Text = "Blue row"},
                       new RowItem{R = 255, G = 0, B = 255, Text = "Purple row"},
                       new RowItem{R = 0, G = 255, B = 255, Text = "Cyan row"},
                       new RowItem{R = 0, G = 0, B = 0, Text = "Black row"}
                   };

    var document = new PdfDocument();

    PdfPage page = document.AddPage();
    XGraphics gfx = XGraphics.FromPdfPage(page);
    var textformater = new XTextFormatter(gfx);
    XFont font = new XFont("Segoe UI", 20, XFontStyle.Regular);
    int y = 50;
    textformater.DrawString(" Color", font, XBrushes.Black, new XRect(35, y, 70, 25));
    textformater.DrawString(" Subdivision Name", font, XBrushes.Black, new XRect(100, y, 250, 25));

    foreach (var item in data)
    {
        y = y + 30;
        XRect snoColumnVal = new XRect(35, y, 60, 25);
        XRect snoStudentNameVal = new XRect(100, y, 250, 25);
        var brush = new XSolidBrush(XColor.FromArgb(255, item.R, item.G, item.B));
        //gfx.DrawRectangle(XPens.Black, brush, snoColumnVal);
        gfx.DrawRectangle(brush, snoColumnVal);
        textformater.DrawString(item.Text, font, XBrushes.Black, snoStudentNameVal);
    }
    const string filename = "HelloWorld_tempfile.pdf";
    document.Save(filename);
    // ...and start a viewer.
    Process.Start(filename);
}

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group