PDFsharp & MigraDoc Forum
https://forum.pdfsharp.net/

Document templates
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2169
Page 1 of 1

Author:  TNTPOP [ Fri Oct 19, 2012 8:21 am ]
Post subject:  Document templates

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

Author:  TNTPOP [ Wed Oct 24, 2012 1:05 pm ]
Post subject:  Re: Document templates

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...

Author:  TNTPOP [ Tue Nov 27, 2012 8:02 am ]
Post subject:  Re: Document templates

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?

Author:  Thomas Hoevel [ Tue Nov 27, 2012 9:45 am ]
Post subject:  Re: Document templates

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.

Author:  TNTPOP [ Tue Nov 27, 2012 10:32 am ]
Post subject:  Re: Document templates

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.

Author:  TNTPOP [ Mon Dec 10, 2012 9:37 am ]
Post subject:  Re: Document templates

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/