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 

Adding table to document (migradocument and pdfdocument?)

 
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
petersmith



Joined: 28 May 2009
Posts: 5

PostPosted: Thu May 28, 2009 8:14 pm    Post subject: Adding table to document (migradocument and pdfdocument?) Reply with quote

I want to add a table to a document.
I read something that I need to add it to migradocument and then merge with regular document, but I have no idea how :)
I get the error: 'LastSection' is not a member of 'PdfSharp.Pdf.PdfDocument'.

Here's my current code

Dim document As PdfDocument = New PdfDocument

'ADD TABLE

Dim tbl As MigraDoc.DocumentObjectModel.Tables.Table = New MigraDoc.DocumentObjectModel.Tables.Table
tbl.Borders.Width = 0.75
Dim col As Column = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(2))
col.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center
col = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(5))
Dim cell As Cell
Dim row As Row = tbl.AddRow
row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.PaleGreen
cell = row.Cells(0)
cell.AddParagraph("Savings")
cell = row.Cells(1)
cell.AddParagraph("Manager")
row = tbl.AddRow
row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.White
cell = row.Cells(0)
tbl.SetEdge(0, 0, 1, 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, MigraDoc.DocumentObjectModel.Colors.Black)

'LastSection' is not a member of 'PdfSharp.Pdf.PdfDocument'.
document.LastSection.Add(tbl)
Back to top
View user's profile Send private message
trnilse



Joined: 26 May 2009
Posts: 6

PostPosted: Fri May 29, 2009 8:38 am    Post subject: Reply with quote

You cannot add MigraDocs and MigraDoc elements directly to PDFSharp docs, you need to render them with a DocumentRenderer.

See example here http://pdfsharp.net/PDFsharp/index.php?option=com_content&task=view&id=55&Itemid=63

In this example a paragraph is rendered, but you can render a table too in the same way.
Back to top
View user's profile Send private message
petersmith



Joined: 28 May 2009
Posts: 5

PostPosted: Fri May 29, 2009 8:43 am    Post subject: Reply with quote

Yes, I saw some more of these posts, but I cant figure out which lines I need for the rendering of the migradocs objects, I dont see the relation from the rendering to the PDF doc....could you just copy the lines I need here? :)
Back to top
View user's profile Send private message
trnilse



Joined: 26 May 2009
Posts: 6

PostPosted: Fri May 29, 2009 8:57 am    Post subject: Reply with quote

Code:
// 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(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para);


doc = Your MigraDocument
para = Your table (in the example it is a paragraph, but it is same as with tables)
gfx = a graphics object from the PDFdocument you are creating

RenderObject places (renders) the migradoc object on the PDFdocument graphics object at the given x,y coordinates.

Hope it is more clear now...
Back to top
View user's profile Send private message
petersmith



Joined: 28 May 2009
Posts: 5

PostPosted: Fri May 29, 2009 10:52 am    Post subject: Reply with quote

Not entirely, it seems to go better but now I receive the error: Value of '0' is not valid for 'emSize'. 'emSize' should be greater than 0 and less than or equal to System.Single.MaxValue.
Parameter name: emSize

On step through I noticed that this line is causing the crash:
Dim row As MigraDoc.DocumentObjectModel.Tables.Row = tbl.AddRow


This is my code
Dim document As PdfDocument = New PdfDocument

Dim page As PdfPage
For i = 0 To 4

page = document.AddPage
page.Width = XUnit.FromCentimeter(A4Width)
page.Height = XUnit.FromCentimeter(A4Height)
Next i


'ADD TABLE
Dim tbl As MigraDoc.DocumentObjectModel.Tables.Table = New MigraDoc.DocumentObjectModel.Tables.Table
tbl.Borders.Width = 0.75
Dim col As Column = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(2))
col.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center
col = tbl.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(5))
Dim cell As MigraDoc.DocumentObjectModel.Tables.Cell
Dim row As MigraDoc.DocumentObjectModel.Tables.Row = tbl.AddRow
'row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.PaleGreen
'cell = row.Cells(0)
'cell.AddParagraph("Savings")
'cell = row.Cells(1)
'cell.AddParagraph("Manager")
'row = tbl.AddRow
'row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.White
'cell = row.Cells(0)
'tbl.SetEdge(0, 0, 1, 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, MigraDoc.DocumentObjectModel.Colors.Black)



Dim doc As New MigraDoc.DocumentObjectModel.Document
Dim docRenderer As MigraDoc.Rendering.DocumentRenderer = New MigraDoc.Rendering.DocumentRenderer(doc)
docRenderer.PrepareDocument()

page = document.Pages(0)
Dim gfx As XGraphics = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)

' Render the paragraph. You can render tables or shapes the same way.
docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", tbl)
Back to top
View user's profile Send private message
trnilse



Joined: 26 May 2009
Posts: 6

PostPosted: Fri May 29, 2009 11:29 am    Post subject: Reply with quote

Hmm, I can't see any reason that you should get an error there. But you're not adding the table to the migra doc before rendering. Hopefully this will fix it.

Try something like this:

Code:

Dim doc As New MigraDoc.DocumentObjectModel.Document

' new:
Dim section As MigraDoc.DocumentObjectModel.Section = doc.AddSection()
doc.LastSection.Add(tbl)

Dim docRenderer As MigraDoc.Rendering.DocumentRenderer = New MigraDoc.Rendering.DocumentRenderer(doc)
docRenderer.PrepareDocument()
Back to top
View user's profile Send private message
petersmith



Joined: 28 May 2009
Posts: 5

PostPosted: Fri May 29, 2009 5:03 pm    Post subject: Reply with quote

Yeah, that did the trick! Thanks! :)
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