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.
Tables question...

 
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
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Fri Aug 15, 2008 8:23 am    Post subject: Tables question... Reply with quote

Hello PDfSharp people!

I'm using PDFSharp to make a report from an SQL database, but I'm having trouble getting PDFsharp to insert a table.

I think I should use MigraDoc for the table, but i'm not sure how to integrate it into PDFsharp just for the table.

Any help would be appreciated!

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



Joined: 13 Aug 2008
Posts: 7

PostPosted: Fri Aug 15, 2008 8:41 am    Post subject: Reply with quote

okay, I've found the tables sample in the Migradoc samples. and I think I've created a table, but I cant get it to display in the PDF I generate with PDFsharp.

anyone have any ideas?
Back to top
View user's profile Send private message
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Fri Aug 15, 2008 9:05 am    Post subject: Reply with quote

figured it out, code for anyone that wants it:

Code:
private void ConsumptionReport(string PageTitle, string SubTitle, PdfPage pg, XGraphics Xgfx)
        {

            //table?
            //got to make the table in migradoc and then merge it into PDFsharp
            //for no apparent reason....

            //MigraDoc make:
         
            // HACKČ
            Xgfx.MUH = PdfFontEncoding.Unicode;
            Xgfx.MFEH = PdfFontEmbedding.Default;
            //  MigraDoc document for rendering.
            Document doc = new Document();
            Section sec = doc.AddSection();

            //add table to document:

            Table tbl = new Table();
            tbl.Borders.Width = 0.75;

            Column col = tbl.AddColumn(Unit.FromCentimeter(2));
           
            col.Format.Alignment = ParagraphAlignment.Center;
            col = tbl.AddColumn(Unit.FromCentimeter(5));
            Cell cell;
            Row row = tbl.AddRow();
            row.Shading.Color = Colors.PaleGreen;
            cell = row.Cells[0];
            cell.AddParagraph("Savings");
            cell = row.Cells[1];
            cell.AddParagraph("Manager");

            row = tbl.AddRow();
            row.Shading.Color = Colors.White;
            cell = row.Cells[0];


            tbl.SetEdge(0, 0, 1, 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.Black);
            doc.LastSection.Add(tbl);

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(Xgfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), XUnit.FromCentimeter(12), tbl);
           


            //end table

            //END MigraDoc
           
Back to top
View user's profile Send private message
Thomas Hoevel



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

PostPosted: Mon Aug 18, 2008 8:15 am    Post subject: Reply with quote

Hi!
garethterrace wrote:
//for no apparent reason....

At first, there was MigraDoc (using a different PDF library).
Then we developed PDFsharp as the new base of MigraDoc - merging PDFsharp and MigraDoc was not possible at that time.

Now we include samples that show how to merge MigraDoc and PDFsharp.

MigraDoc creates documents - creating as many pages as required, as PDF, RTF, or printout.
PDFsharp deals with pages and PDF objects.

So be happy that there is some integration.
If we had time for a complete redesign, there would be seamless integration ...
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Wed Aug 27, 2008 1:56 pm    Post subject: Reply with quote

thanks for clarifying Tom,

I'm having real trouble creating a table at run time, my code looks as follows - but it isnt working correctly (not all the cells are filled.



Code:
List<Row> lstRows = new List<Row>();
            List<Column> lstCols = new List<Column>();
// HACKČ
            Xgfx.MUH = PdfFontEncoding.Unicode;
            Xgfx.MFEH = PdfFontEmbedding.Default;
            //  MigraDoc document for rendering.
            Document doc = new Document();
            Section sec = doc.AddSection();

            //add table to document:

            Table tbl = new Table();
            tbl.Borders.Width = 0.75;

            for (int i = 0; i < cols; i++)
            {
                //draw columns first
                Column col = tbl.AddColumn(Unit.FromCentimeter(3));
                 col.Format.Alignment = ParagraphAlignment.Center;
                 col = tbl.AddColumn(Unit.FromCentimeter(5));
                 col.Format.Alignment = ParagraphAlignment.Center;
                lstCols.Add(col);
            }
            for (int i = 0; i < rows; i++)
            {
               //draw rows
                Row row = tbl.AddRow();
            row.VerticalAlignment = VerticalAlignment.Center;
            row.Height = Unit.FromMillimeter(7);
            row.Shading.Color = Colors.LightGray;
            lstRows.Add(row);
            }
            //now fill with cells
            for (int i = 0; i < cols; i++)
            {
                    //found a column

                for (int j = 0; j < rows -1; j++)
                {
                    Cell cell = new Cell();
                        cell = lstRows[i].Cells[j];
                        cell.AddParagraph("Data");
                  } 
             }

tbl.SetEdge(0, 0, cols, rows, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.0, Colors.Black);
            doc.LastSection.Add(tbl);

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(Xgfx, XUnit.FromMillimeter(x), XUnit.FromMillimeter(y), XUnit.FromCentimeter(wdth), tbl);
           



Am I right in thinking that should work??
Back to top
View user's profile Send private message
Thomas Hoevel



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

PostPosted: Wed Aug 27, 2008 2:22 pm    Post subject: Reply with quote

Look here: "lstRows[i].Cells[j];"
I think you swapped i and j here ...
Why "j < rows -1", not "j < rows"?

You don't need lstRow and lstCol. You don't need "new Cell()".

I'd start with:
Code:
Table table = document.LastSection.AddTable();


You can use table.Rows[x] and table.Columns[x] and row.Cells[x].

MigraDoc documents can persist as text files.
If my documents don't look as they should, I look at the persisted document.

Here's how to get it (after composing; I'd call it immediately before rendering):
Code:
#if DEBUG
      string strDirectory = Path.GetDirectoryName(pdfFilename);
      DdlWriter dw = new DdlWriter(Path.Combine(strDirectory, @"samplepdf.mdddl"));
      dw.WriteDocument(document);
      dw.Close();
#endif

_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Wed Aug 27, 2008 2:27 pm    Post subject: Reply with quote

Thanks!

Just realised I'd been chopping and changing code all day and had loads of rubbish in there which didnt need to be there.

the only major problem i'm having is populating the cells, how do I access row[x].cell[y]?
Back to top
View user's profile Send private message
Thomas Hoevel



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

PostPosted: Wed Aug 27, 2008 2:33 pm    Post subject: Reply with quote

Cell cell = tbl.Rows[y].Cells[x];
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
garethterrace



Joined: 13 Aug 2008
Posts: 7

PostPosted: Wed Aug 27, 2008 2:37 pm    Post subject: Reply with quote

diamond!

this is my first time with C# and also my first time with an external library, thanks for your help, I'm getting used to it slowly...
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