PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 6:35 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Get Table-Height
PostPosted: Wed Apr 13, 2011 7:14 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
Hi,

I am new to PDFSharp and MigraDoc and been trying to create an Pdf looking like my attachmenent.
First I tried it with PDFSharp only and run into the problem to add the text with a right alignment.

Than I tried to get these as a MigraDoc-Table with two columns.
No problem with the alignment.
But there is a problem when I want to write 'details of ship' rotated to vertical. In MigraDoc I haven't found a way to do that, with PDFSharp the rotation is easy going but I have to know the height of the MigraDoc-Table to fit the rectangle to the table.
The table-object has no Height-Property.
The Row-object has a Height-Property but this ist always 0.

If the entry for the 'owner' on the form is very long the cell makes a word-wrap and the height of the table increases.

Any ideas how I can catch this information at creating time?

I hope my question (and my english) was understandable.
Thanks in advance
Reiner


Attachments:
File comment: the wanted
creating PDF.jpg
creating PDF.jpg [ 18.47 KiB | Viewed 22519 times ]
Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Thu Apr 14, 2011 3:58 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi, Reiner,

it seems the vertical text is static.
So a simple solution: use "images" for the vertical text (the advanced version would be PDF files of the appropriate page size, some programs can do that; PNGs with white letters on transparent background should also work, resolution should be 300 DPI or more).

You can use MergeDown to have cells that span several rows. Centering the cell content should also work.
So this would be an all MigraDoc solution (with a little hack).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Thu Apr 14, 2011 4:34 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
Hi Thomas,

thank you for your answer.

The vertical text is only "kind of" static.
I have this kind of tableview often in the paper design.
Every string is configurable in a database to get an easy changing possibility.
So, if I try to load the vertical text as an image/file into a cell, I have to create these images/files at runtime.

For today I found a workaround:
- I set the rowheight by my own
- so I can calculate the height of the table (rowheight * Rows.count)
+ printed lines * Rows.Count + some kind of correction

It works not perfectly but one pixel more or less is good enough for today.


Do you know, why the table object has no height property?
Is it only known at rendering?
And if so, couldn't it tell me the height AFTER rendering the object?

When I have time, I have to take a look, if I couldn't add this property to the code.

Greetings
Reiner


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Mon Apr 18, 2011 7:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
I'm trying to convince the decision maker that we need placeholders in MigraDoc - placeholders that can be filled using PDFsharp after MigraDoc made its rendering.

Look here for GetRenderInfoFromPage:
viewtopic.php?p=1960#p1960

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Tue Apr 19, 2011 5:26 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
Thank you for this hint.

I now started ower and created the whole thing new as a MigraDoc-Document.
After done that I will try the solution you suggested.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Thu Apr 21, 2011 3:58 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
After created the whole thing with MigraDoc I found another possibility to get what I want with MigraDoc methods only.
I created the first column and merged the rows for this column down til the last row.
Because I only want to fill in text I needed another possibility to rotate the text.
My code for that now looks as follows:
Code:
            Dim Zelle As Cell = tbl.Rows(0).Cells(0)
            Zelle.Shading.Color = Colors.Aquamarine
            Dim Frame As TextFrame = Zelle.AddTextFrame()
            Frame.Width = Zelle.Width
            Frame.Height = Zelle.Height
            Frame.FillFormat.Color = Farbe2

            Frame.Orientation = TextOrientation.Upward
            Dim para As Paragraph = Frame.AddParagraph("remarks")

The text in the TextFrame looks correct.
The only problem with that idea is that the Cell has no Width- and Height-Property.
I could use the height of the cells row but the cell is mergeddown so I need more than that.

I tried to add the Width- and Height-Property to the MigraDoc.DocumentObjectModel like this:

Code:
    /// <summary>
    /// Gets or sets the width of the cell (merged cells included).
    /// </summary>
    public double Width
    {
        get
        {
            if (this.mergeRight != 0)
            {
                // for each merged Column add the Column.Width
                this.width = 0;
                for (int index = 0; index <= this.mergeRight; ++index)
                {
                 double tmpWidth = this.table.Columns[index].width;
                 this.width +=  tmpWidth;
                }
            }
            else
            {
            this.width = this.Column.width.Value;
            };

            return this.width;
        }
        set
        {
            this.Column.width.Value = value;
        }
    }
    [DV]
    internal Double width = 0;

    /// <summary>
    /// Gets or sets the height of the cell (merged cells included).
    /// </summary>
    public double Height
    {
        get
        {
            if (this.mergeDown != 0)
            {
                // for each merged Column add the Column.Width
                this.height = 0;
                for (int index = 0; index <= this.mergeDown; ++index)
                {
                    double tmpHeight = this.table.Rows[index].height    ;
                    this.height+= tmpHeight;
                }
            }
            else
            {
                this.height = this.row.height.Value;
            };
            return this.height;
        }
        set
        {
            this.Row.height.Value = value;
        }
    }
    [DV]
    internal Double height = 0;


It's not so fare from what I wanted but it creats a NullReference-Error during runtime which is fixed during debugging.
Is anybody interrested in this property and could help me out to fix the problem?
It's a little bit difficult for me, because I never where programming in this language.

Thanks in advance.
Greetings
Reiner


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Tue Apr 26, 2011 9:51 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
As I wrote I tried to get the whole tink working with a TextFrame.
Everything went fine until I recognized that I have a table that can grow over the end of page.
There I need the the 90 degrees rotated text/column repeated on the next page.

So I tried to set the HeaderColumn-Property to True.
But the MergeDown-Property of the Cell throw the whole table on the next page.
I haven't found a possibility to make a pagebreak throughout the mergedcells and my inserted textframe.
That's not so nice, cause I already saw the finishing line.

Therefore I remered this one:
Quote:
I'm trying to convince the decision maker that we need placeholders in MigraDoc - placeholders that can be filled using PDFsharp after MigraDoc made its rendering.

Look here for GetRenderInfoFromPage:
viewtopic.php?p=1960#p1960

And getting stuck with that also.
I tried to set InternalsVisibleTo to my assembly with no effect.
I used this code:
Code:
[assembly: InternalsVisibleTo("TestPDFs,PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd725a769b81d7" +
"77182e479e45d77fb96ab0aa2a78a179e2154113ac0f181d70bd6b80f4d6df7fa5860b25ae49d3" +
"5240ca24e2f65bcfbb9d5fde4d19c182e27eae5f4ca0312a4487236d9c88dec8e54f44a45e6c25" +
"36c24a2e1b93c72ce01fadaf6d37f8758a0de9cb6fca3b718fda7e50b9b7b3b454f62671d7ea5a" +
"50781ab4")]

Where 'TestPDFs' is the assembly name of my application (with the reference to migraDoc.DLLs).

I recompiled the Rendering.dll but could not access the internal properties.

I than tried to make these properties public, but after I made RenderInfo-class and Layoutinfo.class public, I recognized that I have to make every propery public to get a value out. That's kind of logical but a long way for me to go.

I hope I missed something in your suggestion?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Wed Apr 27, 2011 6:58 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
ReinerWolff wrote:
I tried to set InternalsVisibleTo to my assembly with no effect.
I used this code:
Code:
[assembly: InternalsVisibleTo("TestPDFs,PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd725a769b81d7" +
"77182e479e45d77fb96ab0aa2a78a179e2154113ac0f181d70bd6b80f4d6df7fa5860b25ae49d3" +
"5240ca24e2f65bcfbb9d5fde4d19c182e27eae5f4ca0312a4487236d9c88dec8e54f44a45e6c25" +
"36c24a2e1b93c72ce01fadaf6d37f8758a0de9cb6fca3b718fda7e50b9b7b3b454f62671d7ea5a" +
"50781ab4")]

Where 'TestPDFs' is the assembly name of my application (with the reference to migraDoc.DLLs).

I cannot verify the PublicKey for you as it depends on the StrongName Key of your assembly.

Also see here:
http://msdn.microsoft.com/en-us/library ... ibute.aspx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Wed Apr 27, 2011 2:54 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
Sorry to bother you again.

Finally I get the InternalsVisibleTo-thing working. Thank you for that.
I can read out the table position and width/height. I can see the finishing line already - I believe.

But I'm getting headache mixing the code with PDFSharp drawing methods.
I post the rendering code with the question in the line with the highest indent:
Code:
        Dim docRenderer As MigraDoc.Rendering.DocumentRenderer
        docRenderer = New MigraDoc.Rendering.DocumentRenderer(Dok.Dokument)
        docRenderer.PrepareDocument()
        Dim pageCount As Integer = docRenderer.FormattedDocument.PageCount

        For j As Integer = 1 To pageCount
            Dim docObjects As MigraDoc.Rendering.RenderInfo() = docRenderer.GetRenderInfoFromPage(j) '.GetDocumentObjectsFromPage(i + 1)
            '            If Not docObjects Then 'And docObjects.Length > 0) Then
            If docObjects.Length > 0 Then
                For k As Integer = 0 To docObjects.Length - 1
                    Debug.Print(docObjects(k).GetType.Name)
                    Select Case docObjects(k).GetType.Name
                        Case "TableRenderInfo"
                            Dim tblSize As MigraDoc.Rendering.RenderInfo = docObjects(k)
                            Dim rect As PdfSharp.Drawing.XRect = Dok.GetXRectFromArea(tblSize.LayoutInfo.ContentArea)
                            'Q: How to use PDFSharp to draw on this page? How to get the PDFSharp.page?
                            'How to add text via PDFSharp at this point?

                    End Select
                Next k
            End If
        Next j

        'Render the PDF-Document ...
        Dim Render As MigraDoc.Rendering.PdfDocumentRenderer = New MigraDoc.Rendering.PdfDocumentRenderer(True, PdfSharp.Pdf.PdfFontEmbedding.Always)
        Render.Document = Dok.Dokument
        Render.RenderDocument()

        ' ... and save it to a file ...
        Dim filename As String = "HelloWorld.pdf"
        Render.PdfDocument.Save(filename)
        ' ...and start a viewer.
        Process.Start(filename)
Can you take a brief look and give me a hint how to edit the page with PDFSharp?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Thu Apr 28, 2011 7:11 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Prepare the page by calling "PdfPage page = document.AddPage();" and "XGraphics gfx = XGraphics.FromPdfPage(page);".

Call "docRenderer.RenderPage(gfx, idx + 1);" to draw the page.

Then use PDFsharp to draw other stuff on that page.

See Create Page Two in this sample:
http://www.pdfsharp.net/wiki/MixMigraDo ... Page_Two_2
It draws several MigraDoc pages on one PDFsharp page, so it needs some transfer.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Table-Height
PostPosted: Thu Apr 28, 2011 1:53 pm 
Offline

Joined: Wed Apr 13, 2011 6:39 pm
Posts: 21
Thank you.
It looks exactly like I wanted it, perfect.

I looked at this sample before, but needed the hint that the MigraDoc-Renderer doesn't need the container and I have to do it page by (MigraDoc)Page.

So this one can be closed, I hope.


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

All times are UTC


Who is online

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