PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue May 22, 2018 12:12 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: MigraDocXML
PostPosted: Sun Apr 15, 2018 5:07 pm 
Offline

Joined: Sun Apr 15, 2018 4:52 pm
Posts: 2
Hi everyone, first time here on the forums, though I've been using MigraDoc for probably around a year now as a part of my job to automate PDF file generation from a system I'm working on. As much as I think MigraDoc is a great library for creating PDFs, I've been finding it to be getting quite limiting recently due to the fact that all the design work has to be done in .NET code, so this weekend I started working on a library to design files for MigraDoc in XML instead.

There's still loads that hasn't been done yet, but the fundamentals for creating quite simple PDFs are in place and I thought you might find it interesting/useful for your own projects.

I've got a project page set up on gitlab over here that you can take a look at:
https://gitlab.com/jamescoyle/MigraDocXML

And here's an example of some of the XML:
Code:
<Document ImagePath="{Model.ImagePath}">

    <Style Target="Paragraph">
        <Setters Font.Name="Calibri" SpaceBefore="2mm" SpaceAfter="2mm"/>
    </Style>

    <Style Target="Paragraph" Name="Title">
        <Setters Font.Size="20" Font.Bold="true" Alignment="Center"/>
    </Style>

    <Style Target="Paragraph" Name="Address">
        <Setters SpaceBefore="0" SpaceAfter="0"/>
    </Style>

    <Section PageSetup.DifferentFirstPageHeaderFooter="true"
             PageSetup.BottomMargin="3.5cm">

        <Header IsPrimary="true" IsFirstPage="true">
            <p Alignment="Right">
                <Text>Page </Text><PageField/><Text> of </Text><NumPagesField/>
            </p>
        </Header>

        <Footer IsFirstPage="true">
            <Table>
                <Style Target="Row">
                    <Setters Alignment="Center"/>
                </Style>

                <Style Target="Paragraph">
                    <Setters SpaceBefore="0" SpaceAfter="0"/>
                </Style>

                <Column Width="15cm"/>

                <Row>
                    <Cell Index="0">
                        <p><Image Name="Generic Bank Logo.jpeg" Width="4cm"></Image></p>
                    </Cell>
                </Row>
                <Row C0="For all your non-specific banking needs"/>
            </Table>
        </Footer>

        <p Style="Title">{Model.AccountHolder}'s Monthly Statement</p>

        <p Style="Address">{Model.Address.Line1}</p>
        <p Style="Address">{Model.Address.Town}</p>
        <p Style="Address">{Model.Address.County}</p>
        <p Style="Address">{Model.Address.Country}</p>
        <p Style="Address" SpaceAfter="1cm">{Model.Address.Postcode}</p>

        <If Var="Model.AccountBalance" Criteria="&lt;0">
            <p Font.Color="Red" Font.Bold="true">Your account is currently overdrawn, you need to either earn more money, or spend less</p>
        </If>

        <p>Your monthly transactions</p>
        <Table Borders.Color="Gray">
            <Column Width="5cm"/>
            <Column Width="7cm"/>
            <Column Width="3cm"/>

            <Row Heading="true" Font.Bold="true" C0="Date" C1="Description" C2="Price"/>

            <ForEach Var="tx" In="Model.Transactions">
                <Row Font.Color="{tx.Colour}" C0="{tx.Date#dd MMM yyyy}" C1="{tx.Name}" C2="{tx.Value#C}"/>
            </ForEach>
        </Table>

    </Section>

</Document>


Let me know your thoughts


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDocXML
PostPosted: Sun Apr 15, 2018 7:16 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 373
Location: CCAA
Hi!
James Coyle wrote:
As much as I think MigraDoc is a great library for creating PDFs, I've been finding it to be getting quite limiting recently due to the fact that all the design work has to be done in .NET code, so this weekend I started working on a library to design files for MigraDoc in XML instead.[...]
Let me know your thoughts
MigraDoc always aupported MigraDoc DDL. I do not (yet) see the point of re-inventing the wheel using XML syntax when MDDDL existed previously.
In the old days there even was an editor that allowed mixing MDDDL and C# in a way similar to the razor syntax that allows mixing HTML and C#.
We got used to creating documents from code and the technology that allows mixing MDDDL and C# was abandoned many years ago.

Are there advantages of XML over MDDDL? A schema file could make the difference, allowing VS to help with syntax checks and IntelliSense. I don't see a schema file in your sample code.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDocXML
PostPosted: Sun Apr 15, 2018 10:25 pm 
Offline

Joined: Sun Apr 15, 2018 4:52 pm
Posts: 2
Hi Thomas

I always got the impression that MDDDL was for saving a document that had already been designed for the purpose of debugging more than anything. I'll admit, I've not really done much with DDLs, but from the samples that are available I've never seen any way that they allow you to pass in data to be inserted within your document. It could be that this is supported and I've just missed it, there doesn't seem to be too much online regarding what you can do with DDLs.

You mention there used to be an editor for mixing MDDDL & C#, does that still exist in any form? I'd be interested to see how it was implemented. Also, did that then mean that the files were compiled? Because that was the one issue I had with razor pages when I wanted to make a small layout change to my pages and had to redeploy my web app to do so.

Regarding advantages of XML or MDDDL...I don't think the format of the file itself isn't really what's significant, the reason I chose to store files as xml is just because it's pretty much become industry standard format for defining document layouts. Also, you're right, I don't currently have a schema file, which could actually be very helpful. For the time being I've just been making sure the library actually works.

I wrote this project mainly for myself as I can really see this providing a huge boost to how I work with MigraDoc. I'll try and win you over to my library :D if only because I'd love to know that other people are getting use out of it too. The problem this is aiming to solve for me is that I've found the documents I produce for customers often seem to be running off pretty much the exact same data, but with each of them having different requests of how they want things laid out. With the way I'm using migradoc at the moment it means either lots of conditional logic or else customer-specific plugins just for document layout changes, neither of which are at all ideal. Storing the layout outside of my assembly along with information of how data should be populated into it means I just need to change one xml file.

James


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group