PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Aug 14, 2018 8:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 22 posts ] 
Author Message
PostPosted: Wed Jul 08, 2009 1:29 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I have a page with multiple tables on, all of which position nicely in migradoc, I have however created a graphic using the PDFSharp functions like drawRectangle etc. I would like to be able to position this under a table, I can do this by specifically stating coordinates which will put it under the table, but when the table size changes, the graphic doesnt move up/down accordingly.

Is there a way to create a graphic using PDFSharp commands, but then add it to a a MigraDoc section so it will layout correctly?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 13, 2009 9:30 am 
Offline
empira Employee
User avatar

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

It should be possible: just add a MigraDoc object of appropriate size as a placeholder and add a Tag to this object (a user-defined object class that contains information what to draw).

Create the PDF document page by page and draw the PDFsharp objects over the placeholder.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 14, 2009 2:08 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi Thomas,

I have basically got thsi working - using a TextFrame as the placeholder, but it always returns its Left and Top properties as 0. I am the textframe the the appropriate cell, but I cant seem to get the co-ordinates out which i need for positioning the drawing.

any ideas?

Mike


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 14, 2009 2:42 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
mikesowerbutts wrote:
Hi Thomas,

I have basically got thsi working - using a TextFrame as the placeholder, but it always returns its Left and Top properties as 0.

Have you called Left and Top after executing "docRenderer.PrepareDocument()"?

Here's a code snippet:
Code:
this.docRenderer = new DocumentRenderer(this.doc);
this.docRenderer.PrepareDocument();
int pageCount = this.docRenderer.FormattedDocument.PageCount;
for (int idx = 0; idx < pageCount; idx++)
{
  DocumentObject[] docObjects = this.docRenderer.GetDocumentObjectsFromPage(idx + 1);
  if (docObjects != null && docObjects.Length > 0)
  {
     [...] // indentify your textframe here (add an appropriate Tag to it when you add it)
  }
}

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2009 1:39 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi Thomas,

I am trying to detect the cell I have added the placeholder to using the following code:
Code:
public List<DocumentObject> getDocumentObjectsWithTag()
        {
            List<DocumentObject> _objs = new List<DocumentObject>();
            DocumentRenderer _renderer = new DocumentRenderer(document);
            _renderer.PrepareDocument();
            int pageCount = _renderer.FormattedDocument.PageCount;
            for (int idx = 1; idx <= pageCount; idx++)
            {
              DocumentObject[] docObjects = _renderer.GetDocumentObjectsFromPage(idx);
              if (docObjects != null && docObjects.Length > 0)
              {
                  for (int g = 0; g < docObjects.Length; g++)
                  {
                      if (docObjects[idx].GetType() == typeof(MigraDoc.DocumentObjectModel.Tables.Table))
                      {
                          MigraDoc.DocumentObjectModel.Tables.Table _tbl = (MigraDoc.DocumentObjectModel.Tables.Table)docObjects[idx];
                          if (_tbl.Comment != "")
                          {

                          }
                          for (int r = 0; r < _tbl.Rows.Count; r++)
                          {
                              for (int c = 0; c < _tbl.Columns.Count; c++)
                              {
                                  try
                                  {
                                      Cell _c = _tbl[r, c];
                                      if (_c.Tag != null)
                                      {
                                          _objs.Add(_c.Elements[0]);
                                      }
                                  }
                                  catch
                                  {

                                  }
                              }
                          }
                      }
                  }
              }
            }
            return _objs;
        }

I can detect the appropriate cell before the document is rendered, but since incorporating the prepare document etc. you mentioned in your last post, all of the .Tag and .Comment properties for every DocumentObject (and cells in the tables) seems to be set to either null or "".

This then means that I cant find the appropriate cell, to then get the placeholder etc. etc.

I am so close with this, but so far still!

please help!

Mike


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2009 2:24 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
I see
Code:
for (int g = 0; g < docObjects.Length; g++)

followed by
Code:
if (docObjects[idx].GetType()


"docObjects[g]" might be worth a try ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2009 3:09 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
good point!

that part of the code is now working! I cant belive that it was such a simple mistake that I literally wasted about 2 hours on!

however, I am back to the same problem as I was a few posts ago, the TextFrame I am using as the placeholder is still returning its Left.Position.Centimeter property (and the same for Top) as 0?

I dont ever specifically set these properties, but i presumed that adding all the PrepareDocument() stuff, would update these properties?

Mike


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 16, 2009 4:13 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
Shame on me - the information you need is "internal".
I should have checked that before writing here ...

You could add a new method
Code:
/// <summary>
/// Gets the render information for document objects that get rendered on the specified page.
/// </summary>
internal RenderInfo[] GetRenderInfoFromPage(int page)
{
  return this.formattedDocument.GetRenderInfos(page);
}

right below "GetDocumentObjectsFromPage" in DocumentRenderer.cs.

In the AssemblyInfo.cs of MigraDoc.Rendering you can add a "[assembly: InternalsVisibleTo(" line for your assembly (or change "internal abstract class RenderInfo" to public and also make GetRenderInfoFromPage public).

What you need is RenderInfo.LayoutInfo.ContentArea.
RenderInfo.DocumentObject will take you to your object.

I can't say whether or not this function will be included in the forthcoming release of PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 21, 2009 2:19 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi Thomas,

I have added the new stuff into the MigraDoc.Rendering.dll - BUT I cant get the assembly change to work correctly - I have
Code:
[assembly: InternalsVisibleTo("MigraDoc.Rendering")]

But I keep getting an error saying strongly named assemblies need a public key or something similar.

Also I changed the RenderInfo class to public anstract, rather than internal abstract and changed the new function I added to DocumentRenderer.cs to public, but I still cant access RenderInfo.LayoutInfo as it is internal? (maybe this will be abailable when the assembly InternalsVisibleTo is fixed?

To be honest im not really sure what I am doing here. Please help!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 21, 2009 3:12 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
"InternalsVisibleTo" does what the name suggests.
You insert it into the AssemblyInfo.cs of the assembly that contains the Internals (i. e. MigraDoc.Rendering) providing assembly name (and public key if your assembly uses a SNK) of the assembly that is to see the internals (i. e. your assembly).

To get the public key, use SN.EXE (applicable only if your assembly uses a strong name key):
sn -p friend_assemblies.snk key.publickey // Extract public key from key.snk into key.publickey
sn -tp key.publickey // Display public key stored in file'key.publickey

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2009 2:58 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
hi Thomas,

got the assembly code working finally!

Now, when I put:
Code:
RenderInfo.

I only see the static method "GetTotalHeight" and not any of the other methods, normally I would instansiate an RenderInfo document to get round this, but as it's an abstract class i cant!

do you think this is actually a workable solution? it just seems to be problem after problem!

Mike


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2009 3:17 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
"GetRenderInfoFromPage" returns the RenderInfo objects you need (see code above, not yet included).

You only see the static methods if you type the classname.
You see all methods if you use an object.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2009 3:31 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
It wont let me point to the method GetRenderInfoFromPage though!

could you please provide some sample code?

im sure I will get there in the end!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2009 3:41 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
"GetRenderInfoFromPage" is the new one you have to add yourself (code given in this thread).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2009 4:10 pm 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi Thomas,

I have this part now working - i stupidly thought the GetRenderInfoFrom page method had to be called through RenderInfo.

the textframe is still returning 0 as its left/top position, even when I set the left/top props of the textframe to 20 when I add it to the table cell!

Mike


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 23, 2009 2:27 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2846
Location: Cologne, Germany
What you need is RenderInfo.LayoutInfo.ContentArea.

RenderInfo contains LayoutInfo.ContentArea and DocumentObject.
Iterate through the RenderInfos to find your tagged DocumentObject and then use the information from LayoutInfo.ContentArea.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 24, 2009 8:41 am 
Offline

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi Thomas,

OK so i can get the top/left of the entire table, but i need to top/left of the textframe contained within one of my table's cells.

In the RenderInfo[] I have all of the 4 TableRenderInfo objects, I can then access the DocumentObject property of each of these and loop through its Cols/Rows to detect the correct cell using the Tag property, but I cant get LayoutInfo for the TextFrame (as i can only seem to access it through the DocumentObject property)

Is there a function like "GetRenderInfoFromDocumentObject" or something which will allow me to retrieve the render info for a nested element such as the TextFrame?


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 22, 2011 3:28 pm 
Offline

Joined: Tue Nov 22, 2011 3:24 pm
Posts: 5
Hi, there.

any success in findong out the exact cell position?
I am as far as you where 2 years ago, so I hope you or anyone remember.

Finding out the tables position is nice but may be not enough. as I want to create a graphic exactly fitting into a specific cell.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 27, 2014 12:57 pm 
Offline

Joined: Fri Jan 25, 2013 7:20 am
Posts: 9
Hi,

I'm facing now the same problem.

I got a TextFrame inside a ParagraphElement inside my Primary footer with a special setter Tag property.
After the document is rendered, I have to find the rendered position of the text frame to append some text.
But all i got is two ParagraphRenderInfo objects if asking the GetRenderInfoFromPage().
Can't find a way to get the document objects tree downwards until I reached the text frame that I has tagged before.

Any suggestion how i can find my tagged textFrame?


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 31, 2014 9:18 am 
Offline

Joined: Thu Oct 30, 2014 9:19 am
Posts: 10
To get the RenderInfo we will need to render/prepare the document first.
I'm using DocumentRenderer.PrepareDocument() and then use the suggested way to get the content height. This works.
However, it takes an extremely long time when you have lots of row and you have to check the height after you added a new row.

Any suggestion? The reason I need to check the height every time is , if the rows are too many to fit for one page we will have to move it to the next page and generate a header based on the information of the rows.


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 02, 2014 7:49 pm 
Offline
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 308
centravanti wrote:
However, it takes an extremely long time when you have lots of row and you have to check the height after you added a new row.
So you start a new table with every new page? No need to render more then just the final table to see whether it fits a single page IMHO.

_________________
Ă–hmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 03, 2014 1:29 am 
Offline

Joined: Thu Oct 30, 2014 9:19 am
Posts: 10
() => true wrote:
centravanti wrote:
However, it takes an extremely long time when you have lots of row and you have to check the height after you added a new row.
So you start a new table with every new page? No need to render more then just the final table to see whether it fits a single page IMHO.


yep, i need to start with a table on every page. Hmm i am not sure that will solve this, because the number of rows of the tables could be different.
If only i could determine the table height every time i add a new row before rendering that would be great


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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