PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 1:45 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Document templates
PostPosted: Fri Oct 19, 2012 8:21 am 
Offline

Joined: Fri Oct 19, 2012 7:58 am
Posts: 8
Hi,

I'm new to MigraDoc and PdfSharp and from what I've seen it looks very good.
I'm currently facing an issue with the implementation of MigraDoc. I'm developing a web application in ASP.Net/C# that generates PDF reports. Up to now the reports were hard coded in the C# code which is very annoying when the client needs an update (recompile and everything).

Is it possible to create a base document template with markups that a generic C# code could interpret and replace?

I've been trying with MigraDoc's native format (mdddl) and managed to replace markups in the following way :
Code:
\document
[
  DefaultPageSetup
  [
   PageFormat = A4
  ]
]
{
  \section
  {
    \paragraph
    [
      Style = "Normal"
    ]
    {
      Agent : <%AgentName%>
    }
  }
}

Then when loaded into the Document object (DdlReader.DocumentFromFile(_path + "MigraDoc.mdddl");) I can run through the DocumentObjectCollection and replace the markups using a regex.

Everything works fine when using text or date elements but sometimes I need to add tables. If the table format is static, that is fixed columns and headers, all would be easy as I can use the "Comment" attribute to give the table's name. But in some cases I don't know which table I'll use because in the case of no data, I'll have a single cell in the table saying "No data found".

How can I get round this?

Did anybody come up with this kind of issue? Does anyone work with MigraDoc this way?
Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Document templates
PostPosted: Wed Oct 24, 2012 1:05 pm 
Offline

Joined: Fri Oct 19, 2012 7:58 am
Posts: 8
Hi,

I ended up creating my own library that interprets the comments value of items and looks in all DocumentObject objects to replace markups.

If it can be useful to others, let me know...


Top
 Profile  
Reply with quote  
 Post subject: Re: Document templates
PostPosted: Tue Nov 27, 2012 8:02 am 
Offline

Joined: Fri Oct 19, 2012 7:58 am
Posts: 8
Hi,

I'm back with my templates and encounter an issue : Table cell split across pages.
To explain, let's take a simple example : users - profiles - roles

So, I have X users, each user can have Y profiles and each profile can have Z roles. If I retrieve this from the DB, I'll have :
  • either a table with X*Y*Z rows
  • or a table with X rows, with a column that contains a table with Y rows that, itself, has a column that contains a table with Z rows
  • or a DataSet with 3 tables : users, profiles, roles

This is not the complicated part and getting data is not the subject here.

What I'm looking for now is in my MigraDoc template, be able to make a part where :
  • for each user, present it's information as paragraphs
  • for each user, present it's profiles and for each profile, present it's information as paragraphs
  • for each profile, present it's roles and for each role, present it's information as paragraphs

The easy way is to have a table with a cell that contains the paragraphs and a table with a cell that contains the paragraphs and so on...
The down side of this method is that table cells cannot be split over pages therefore, limiting the amount of data per user.

I'm looking for an alternative solution that allows splitting over pages. Any ideas?


Top
 Profile  
Reply with quote  
 Post subject: Re: Document templates
PostPosted: Tue Nov 27, 2012 9:45 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!
TNTPOP wrote:
I'm looking for an alternative solution that allows splitting over pages. Any ideas?
How about that: do not use "RowSpan" (MergeDown) for users and profiles. So there is one role per row and there is no need to split a row.

With each cell you can set the four borders independently. The profile spans several rows (roles), but if you only set the top border of the first cell and the bottom border of the last cell, it looks like one big cell. Same for users.

Or start a new table for each profile with a header like "<username>|<profilename>|Roles". Mark this as header so it will be repeated when a pagebreak occurs.

If there aren't too many roles, you could put all roles together in a single row so you only have to make several rows in the user column look like a big cell.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Document templates
PostPosted: Tue Nov 27, 2012 10:32 am 
Offline

Joined: Fri Oct 19, 2012 7:58 am
Posts: 8
Ok, I'll push it a bit further because there's a presentation issue.
So for each user I need :
Code:
// user 1
<paragraph>User : <%iter_value%></paragraph>
   <paragraph>Name : <%user_name%></paragraph>
   <paragraph>First name : <%user_firstname%></paragraph>
   <paragraph>Location : <%user_location></paragraph>
   // profile 1
   <paragraph>Profiles</paragraph>
     <paragraph>Profile : <%profile_name%></paragraph>
     <paragraph>Description : <%profile_desc%></paragraph>
     <paragraph>Roles</paragraph>
      // role 1
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      // role 2
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      // role 3
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
     // profile 2
     <paragraph>Profile : <%profile_name%></paragraph>
     <paragraph>Description : <%profile_desc%></paragraph>
     <paragraph>Roles</paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
// user 2
<paragraph>User : <%iter_value%></paragraph>
   <paragraph>Name : <%user_name%></paragraph>
   <paragraph>First name : <%user_firstname%></paragraph>
   <paragraph>Location : <%user_location></paragraph>
   <paragraph>Profiles</paragraph>
     <paragraph>Profile : <%profile_name%></paragraph>
     <paragraph>Description : <%profile_desc%></paragraph>
     <paragraph>Roles</paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
     <paragraph>Profile : <%profile_name%></paragraph>
     <paragraph>Description : <%profile_desc%></paragraph>
     <paragraph>Roles</paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>
      <paragraph>Role : <%role_name%></paragraph>
      <paragraph>Description : <%role_desc%></paragraph>

I use the paragraph object just so you can focus but there might be something else.
In my current version I have this :
Code:
<table>
   <row>
      <cell>
         <paragraph>Name : <%user_name%></paragraph>
         <paragraph>First name : <%user_firstname%></paragraph>
         <paragraph>Location : <%user_location></paragraph>
         <paragraph>Profiles</paragraph>
         <table>
            <row>
               <cell>
                  <paragraph>Profile : <%profile_name%></paragraph>
                  <paragraph>Description : <%profile_desc%></paragraph>
                  <paragraph>Roles</paragraph>
                  <table>
                     <row>
                        <cell>
                           <paragraph>Role : <%role_name%></paragraph>
                           <paragraph>Description : <%role_desc%></paragraph>
                        </cell>
                     </row>
                  </table>
               </cell>
            </row>
         </table>
      </cell>
   </row>
</table>

Detecting it's a template table, I clone the first row and repeat for each instance of the dataset. I go in depth recursively to fill the other tables. This method gives 1 row per user block, so user's information cannot exceed 1 page which, in some cases, can be too short.


Top
 Profile  
Reply with quote  
 Post subject: Re: Document templates
PostPosted: Mon Dec 10, 2012 9:37 am 
Offline

Joined: Fri Oct 19, 2012 7:58 am
Posts: 8
Hi all,

I'm back with some news on this.
I've changed the way to work with templates. That is, I use standard objects with a comment, example :
Code:
\paragraph
[
   Comment = "<%template(DetailAgent)%>"
   Style = "Normal"
   Format
   {
      Alignment = Left
   }
]
{
   <%resource(lblRemboursement)%> <%DIV(<%RefundAgent%>;100)\{C2\}%>
}

My new code would detect this and create the document. This will bypass the split row issue I had in the previous version.
I can also put several templates and all would work fine.

If you are interested in what I have done and want to help, PM me.


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

All times are UTC


Who is online

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