Create PDF from OpenXml

I am trying to find an SDK that can generate PDF from OpenXml. I used the Open Xml Power Tools to convert open XML and html and using iTextSharp to parse Html to PDF. But the result is a very scary looking PDF.

I have not tried iText RTF parser yet. If I go in that direction, I will need an RTF converter that will make simple conversion a double nightmare.

It almost seems like I can write my own converter based on the powerful OpenXml to html converter tools. Any recommendations are appreciated. I really can’t get into a professional converter at this time, because licenses are too expensive (Aspose Word / TxText).


I thought I would put some more effort into my investigation. I went back to the conversion utility "http://msdn.microsoft.com/en-us/library/ff628051.aspx" and looked at its code. Given the biggest thing he missed, was reading basic styles and creating a style attribute. PDF looked much better with the restriction of not handling the font of the regular font. Further investigation tomorrow. I hope I did something like this / ran into strange problems and could shed some light.




    private static StringDictionary GetStyle(XElement el)
    {
        IEnumerable jcL = el.Elements(W.jc);
        IEnumerable spacingL = el.Elements(W.spacing);
        IEnumerable rPL = el.Elements(W.rPr);

        StringDictionary sd = new StringDictionary();

        if (HasAttribute(jcL, W.val)) sd.Add("text-align", GetAttribute(jcL, W.val));

        // run prop exists
        if (rPL.Count() > 0)
        {
            XElement r = rPL.First();
            IEnumerable ftL = el.Elements(W.rFonts);

            if (r.Element(W.b) != null) sd.Add("font-weight", "bolder");
            if (r.Element(W.i) != null) sd.Add("font-style", "italic");
            if (r.Element(W.u) != null) sd.Add("text-decoration", "underline");
            if (r.Element(W.color) != null && HasAttribute(r.Element(W.color), W.val)) sd.Add("color", "#" + GetAttribute(r.Element(W.color), W.val));
            if (r.Element(W.rFonts) != null )
            {
                // 
                if(HasAttribute(r.Element(W.rFonts), W.cs)) sd.Add("font-family", GetAttribute(r.Element(W.rFonts), W.cs));
                else if (HasAttribute(r.Element(W.rFonts), W.hAnsi)) sd.Add("font-family", GetAttribute(r.Element(W.rFonts), W.hAnsi));
            }
            if (r.Element(W.sz) != null && HasAttribute(r.Element(W.sz), W.val)) sd.Add("font-size", GetAttribute(r.Element(W.sz), W.val) + "pt");
        }

        return sd.Keys.Count > 0 ? sd : null;
    }


+5
source share
1 answer

availabe, , , . ( ) Word WordprocessingML Open XML, , :

Word Automations Services ( SharePoint) .NET .

+1

All Articles