PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
Table problem: How to remove the space between two columns?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
paeppi



Joined: 17 Sep 2008
Posts: 5
Location: Munich

PostPosted: Wed Sep 17, 2008 1:12 pm    Post subject: Table problem: How to remove the space between two columns? Reply with quote

Hi,

I create a Table which has two colums. Every cell gets a background color by setting cell.Format.Shading.Color to some color.

The table printed out by this action has a ~ 0.5 cm space between the Columns, though I checked every Format in debugger (the one of the table, the row, the columns, and the cells) and all numeric (unit) values are 0. How do I remove the space, or better change it to be only 0.1 cm?

Here is the code creating the table:

Code:
PdfDocument outputPdf = new PdfDocument();
PdfPage page0 = outputPdf.AddPage();

Document doc = new Document();
Section tableSection = doc.AddSection();

Table myTable = tableSection.AddTable();

Column column1 = myTable.AddColumn(Unit.FromCentimeter(10));
Column column2 = myTable.AddColumn(Unit.FromCentimeter(5));
column1.Format.Alignment = ParagraphAlignment.Left;
column2.Format.Alignment = ParagraphAlignment.Right;

string color1 = "0xd5dadc";
string color2 = "0xb2b9be";
bool colorAlter = true;

for(int i = 0; i < 10; i++)
{
    Cell cell;
    Row row = myTable.AddRow();

    cell = row.Cells[0];
    cell.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse(colorAlter ? color1 : color2));
    cell.AddParagraph("Row " + i + ", Cell 1");

    cell = row.Cells[1];
    cell.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse(colorAlter ? color1 : color2));
    cell.AddParagraph("Row " + i + ", Cell 2");
    colorAlter = !colorAlter;
}

DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
docRenderer.PrepareDocument();
XGraphics gfx = XGraphics.FromPdfPage(page0);
docRenderer.RenderPage(gfx, 1, PageRenderOptions.All);

outputPdf.Save("TablesTest1.pdf");
Process.Start("TablesTest1.pdf");


Here is, in case you are lazy and don't want to run the code yourself, a short snapshot of what the output looks like:



Thanks for your answer,
paeppi
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Sep 18, 2008 8:07 am    Post subject: Reply with quote

Hi!

Try setting the Color for the Row.
IIRC you only have to set the color once for the row and not for every cell.
Colors are inherited. A cell has its own color - or uses the Row's color - or uses the Column's color (or was it the other way around?). Maybe there's even a table color as a last resort,

You can set the Color for Cells to highlight them. You can also set the paragraph shading of the text in the cell to highlight something.

But here you only have to set the row color.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
paeppi



Joined: 17 Sep 2008
Posts: 5
Location: Munich

PostPosted: Fri Sep 19, 2008 12:41 am    Post subject: Reply with quote

Hi,

thanks for your fast reply. Wink

I tried all three, coloring the background of the columns, of the table and of the rows, and nothing seems to be able to remove the white space between the two columns. I guess the white space there is just not part of anything in the table.

My source looks now like this (myTable1 is the one with the column colors, myTable2 the one with the color in the table):

Code:
PdfDocument outputPdf = new PdfDocument();
PdfPage page0 = outputPdf.AddPage();

Document doc = new Document();
Section tableSection = doc.AddSection();

/* Table containing Columns with background color */
Table myTable1 = tableSection.AddTable();
Column table1_column1 = myTable1.AddColumn(Unit.FromCentimeter(10));
Column table1_column2 = myTable1.AddColumn(Unit.FromCentimeter(5));
table1_column1.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xaaeeaa"));
table1_column2.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xaaeeaa"));

Row table1_rowWithoutColor = myTable1.AddRow();
table1_rowWithoutColor.Cells[0].AddParagraph("Row without color, Cell 1");
table1_rowWithoutColor.Cells[1].AddParagraph("Row without color, Cell 2");

string color1 = "0xd5dadc";
string color2 = "0xb2b9be";
bool colorAlter = true;
for(int i = 0; i < 5; i++)
{
    Row row = myTable1.AddRow();
    row.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse(colorAlter ? color1 : color2));
    row.Cells[0].AddParagraph("Row " + i + ", Cell 1");
    row.Cells[1].AddParagraph("Row " + i + ", Cell 2");
    colorAlter = !colorAlter;
}

/* placeholder */
tableSection.AddParagraph("\n\n");

/* Table with Background color */
Table myTable2 = tableSection.AddTable();
myTable2.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xeeeeee"));

Column table2_column1 = myTable2.AddColumn(Unit.FromCentimeter(10));
Column table2_column2 = myTable2.AddColumn(Unit.FromCentimeter(5));
Row table2_rowWithoutColor = myTable2.AddRow();

table2_rowWithoutColor.Cells[0].AddParagraph("Row without color, Cell 1");
table2_rowWithoutColor.Cells[1].AddParagraph("Row without color, Cell 2");

DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
docRenderer.PrepareDocument();
XGraphics gfx = XGraphics.FromPdfPage(page0);
docRenderer.RenderPage(gfx, 1, PageRenderOptions.All);

outputPdf.Save("TablesTest1.pdf");
Process.Start("TablesTest1.pdf");


And here is what the result looks like:

Back to top
View user's profile Send private message
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Fri Sep 19, 2008 8:09 am    Post subject: Reply with quote

this is, I think, a borders issue.

Set the tbl.Borders.Visible = false; or the row.borders.visible = false;

or the cell, or one of them!

that should get rid of it I think.
Back to top
View user's profile Send private message
paeppi



Joined: 17 Sep 2008
Posts: 5
Location: Munich

PostPosted: Fri Sep 19, 2008 1:25 pm    Post subject: Reply with quote

Hi,

no, it's not a border issue. I've set every border, the .Border and .Format.Border to Visible = false:

Code:
PdfDocument outputPdf = new PdfDocument();
PdfPage page0 = outputPdf.AddPage();

Document doc = new Document();
Section tableSection = doc.AddSection();

/* Table with Background color */
Table myTable2 = tableSection.AddTable();
myTable2.Format.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xdddddd"));
myTable2.Borders.Visible = false;
myTable2.Format.Borders.Visible = false;

Column table2_column1 = myTable2.AddColumn(Unit.FromCentimeter(10));
Column table2_column2 = myTable2.AddColumn(Unit.FromCentimeter(5));
table2_column1.Borders.Visible = false;
table2_column1.Format.Borders.Visible = false;
table2_column2.Borders.Visible = false;
table2_column2.Format.Borders.Visible = false;
Row table2_rowWithoutColor = myTable2.AddRow();

table2_rowWithoutColor.Borders.Visible = false;
table2_rowWithoutColor.Format.Borders.Visible = false;

table2_rowWithoutColor.Cells[0].AddParagraph("Row without color, Cell 1");
table2_rowWithoutColor.Cells[1].AddParagraph("Row without color, Cell 2");

table2_rowWithoutColor.Cells[0].Borders.Visible = false;
table2_rowWithoutColor.Cells[0].Format.Borders.Visible = false;
table2_rowWithoutColor.Cells[1].Borders.Visible = false;
table2_rowWithoutColor.Cells[1].Format.Borders.Visible = false;

DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
docRenderer.PrepareDocument();
XGraphics gfx = XGraphics.FromPdfPage(page0);
docRenderer.RenderPage(gfx, 1, PageRenderOptions.All);

outputPdf.Save("TablesTest1.pdf");
Process.Start("TablesTest1.pdf");


Result:
Back to top
View user's profile Send private message
paeppi



Joined: 17 Sep 2008
Posts: 5
Location: Munich

PostPosted: Sun Sep 21, 2008 11:03 pm    Post subject: Reply with quote

Any further ideas? I am completely lost, I've no ideas left how to solve the issue.

Maybe someone should move it to the Bug Reports Forum?

Regards,
paeppi
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Mon Sep 22, 2008 12:13 pm    Post subject: Reply with quote

Hi!

Set row.Shading.Color, cell.Shading.Color, &c.

You only set the shading of the text in the cells - therefore the gap!

Set only the shading of the rows and you're done.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
paeppi



Joined: 17 Sep 2008
Posts: 5
Location: Munich

PostPosted: Wed Sep 24, 2008 5:01 pm    Post subject: Reply with quote

Great, that works.. thank you very much!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com