Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a requirement to crate a PDF of XML Records. I think there is no way to directly create pdf from xml but using XSLT or XSL FO i believe it can be done. I have been reading lots of articles searching for the good way to do that using C#.

--> What's the best approach of during this? any example would really be great.

My Scenario:

I have XML that looks like:

<Products>
  <Brand name="Test">
    <Quantity value="2/>
     <Price value="$20"/>
  </Brand>
  <Brand name="Test2">
    <Quantity value="3/>
     <Price value="$30"/>
  </Brand>
  <Brand name="Test3">
    <Quantity value="4/>
     <Price value="$40"/>
  </Brand>
</Products>

How can i create a pdf that will have a table showing all this information?

I know there are lots of similar questions like this but most of them are outdated. Any help really appreciated.

share|improve this question
    
Well, what have you tried? Since you mention FO: have you tried FO? For example fonet.codeplex.net ? Note that FO is not trivial - you need to do a lot more work that you would for HTML, as an example. Also: have you considered any of the html-to-PDF conversion tools? (I used to use HTMLDOC a lot, a few years back). Or any of the low-level PDF creation tools? –  Marc Gravell Jul 11 '13 at 9:11
    
duplicated stackoverflow.com/questions/1674257/… –  Mennan Jul 11 '13 at 9:11
    
As i mentioned they are mostly outdated the last update for FO was on 2009. I am looking for something which can be easily used in C# , and can be taken as best tool for automating the pdf creation through code. I have looked at report.sourceforge.net, itextpdf.com/terms-of-use/index.php, pdfsharp.com/PDFsharp and few more but need feedbacks from those who have used it. –  Bravo11 Jul 11 '13 at 9:15
add comment

1 Answer

up vote 1 down vote accepted

In the past I've used a commercial library called Ibex PDF Creator to generate PDF documents from XML data using the XSL-FO standard that has worked really well.

Here's an example of how I would use it:

XML data:

<DocumentRoot>
    <!-- Some content -->
</DocumentRoot>

XSL-FO layout:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/DocumentRoot">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ibex="http://www.xmlpdf.com/2003/ibex/Format">
            <ibex:properties
                title="Some document"
                subject=""
                author=""
                keywords=""
                creator="" />
            <fo:layout-master-set>
                <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm">
                    <fo:region-body margin-bottom="1cm" margin-top="3cm"/>
                    <fo:region-before extent="20mm"/>
                    <fo:region-after extent="8mm"/>
                    <fo:region-start extent="1mm"/>
                    <fo:region-end extent="1mm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
        </<fo:root>
    </xsl:template>
</xsl:stylesheet>

Generating the PDF document in .NET:

var data = new MemoryStream(dataBytes);
var layout = new MemoryStream(layoutBytes);
var pdf = new MemoryStream();

// Using the Ibex PDF Creator .NET API
var doc = new FODocument();
doc.generate(data, layout, pdf);

I hope this helps.

share|improve this answer
    
Thanks Enrico do you suggest any opensource alternatives? –  Bravo11 Jul 11 '13 at 9:30
    
Personally, I haven't tried any open source alternative for XSL-FO. Since the project I was working on was about building a product, we chose to go with a commercial library for the documentation and support. –  Enrico Campidoglio Jul 11 '13 at 9:39
    
Awesome thanks for your reply. Hope this will help me too. –  Bravo11 Jul 11 '13 at 9:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.