PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 30, 2024 9:10 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Jun 20, 2012 3:39 pm 
Offline

Joined: Wed Jun 20, 2012 3:29 pm
Posts: 1
Visual Studio 2010 with ASP.NET/VB.NET
Downloaded the files and have them in my project. Just trying to work my way through the "Hello MigraDoc" example and having troubles. Downloaded the Help CHM file so have that for a reference also. The examples are in C# so working through that conversion, but the attributes and intellisense options provided do not correspond to the examples. I can create a document and put the "Hello World" on the page, but trying to show a 1 column/1 row table with information in just 1 cell doesn't show up. I'm sure it's something pretty basic, but it's just eluding me. I get no errors and just have the "Hello World" at the top of the page. What am I missing? Thanks in advance for helping this old fart out on this...... :)

Here's my code:

Code:
Dim document As MigraDoc.DocumentObjectModel.Document = New MigraDoc.DocumentObjectModel.Document
        Dim style As MigraDoc.DocumentObjectModel.Styles = New MigraDoc.DocumentObjectModel.Styles
        Dim table As MigraDoc.DocumentObjectModel.Tables.Table = New MigraDoc.DocumentObjectModel.Tables.Table
        Dim Newcolumn As MigraDoc.DocumentObjectModel.Tables.Columns = New MigraDoc.DocumentObjectModel.Tables.Columns
        Dim row As MigraDoc.DocumentObjectModel.Tables.Row = New MigraDoc.DocumentObjectModel.Tables.Row

        document.Info.Title = "Hello, MigraDoc"
        document.Info.Subject = "Demonstrates an excerpt of the capabilities of MigraDoc."
        document.Info.Author = "Stefan Lange"

        document.AddSection.AddParagraph.AddFormattedText("Hello World", TextFormat.Bold)

        document.AddSection.AddTable()

        table.AddColumn.Format.Borders.Left.Width = 2
        table.AddColumn.Format.Borders.Bottom.Width = 2
        table.AddColumn.Format.Alignment = ParagraphAlignment.Center

        row.Cells(0).AddParagraph("First Cell")

        MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "c:\tempWorking\MigraDoc.mdddl")

        Dim renderer As New PdfDocumentRenderer(True, PdfSharp.Pdf.PdfFontEmbedding.Always)
        renderer.Document = document
        renderer.RenderDocument()

        Dim filename As String = "c:\tempWorking\HelloMigraDoc.pdf"
        renderer.PdfDocument.Save(filename)
        Process.Start(filename)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 21, 2012 8:19 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Hi!

You should call something like "row = table.AddRow()" before setting the paragraph in the row.
You also need "table = document.AddSection.AddTable()".

Your code creates a table without any rows and without any columns in the section (therefore you see nothing). You also create a table with three columns but without any rows and a row without table (no reference to the decument).
Use the return value of table.AddColumn if you want to set more than a single property of the column.

The AddXxx methods return the newly created object. Assign this to a variable to set more than one property.

You don't need these New statements:
Code:
        Dim style As MigraDoc.DocumentObjectModel.Styles = New MigraDoc.DocumentObjectModel.Styles
        Dim table As MigraDoc.DocumentObjectModel.Tables.Table = New MigraDoc.DocumentObjectModel.Tables.Table
        Dim Newcolumn As MigraDoc.DocumentObjectModel.Tables.Columns = New MigraDoc.DocumentObjectModel.Tables.Columns
        Dim row As MigraDoc.DocumentObjectModel.Tables.Row = New MigraDoc.DocumentObjectModel.Tables.Row

The document has Styles, access them to change them (IIRC document.Styles). Tables, columns, and rows will be created by AddXxx methods.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 83 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