Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:13:25+00:00 2026-06-12T04:13:25+00:00

i’ve got a task to convert docx document to Pdf. I’ve decided to take

  • 0

i’ve got a task to convert docx document to Pdf. I’ve decided to take this approach:
convert docx to html, then pass html to ItextSharp. Few week i’ve been looking all over google, codeplex, sourceforge and stackoverflow and so on for a solution thow to make this conversion, until I found Eric White blog. At firs impression he made great tool for working with OpenXml documents. But when I tried to test it I’ve got an error about null reference. Error occurs when reading header (RevisionAccepter class)

 public static void AcceptRevisions(WordprocessingDocument doc)
    {
        AcceptRevisionsForPart(doc.MainDocumentPart);
        foreach (var part in doc.MainDocumentPart.HeaderParts) //part is null
            AcceptRevisionsForPart(part); //null ref exception here
        foreach (var part in doc.MainDocumentPart.FooterParts)
            AcceptRevisionsForPart(part);
        if (doc.MainDocumentPart.EndnotesPart != null)
            AcceptRevisionsForPart(doc.MainDocumentPart.EndnotesPart);
        if (doc.MainDocumentPart.FootnotesPart != null)
            AcceptRevisionsForPart(doc.MainDocumentPart.FootnotesPart);
    }

code I use for conversion (same as in example)

private void conv()
    {
        byte[] byteArray = File.ReadAllBytes(textBox1.Text);
        using (MemoryStream memoryStream = new MemoryStream())
        {                

            memoryStream.Write(byteArray, 0, byteArray.Length);
            using (WordprocessingDocument doc =
                WordprocessingDocument.Open(memoryStream, true))
            {
                HtmlConverterSettings settings = new HtmlConverterSettings()
                {
                    PageTitle = "My Page Title"

                };
                XElement html = HtmlConverter.ConvertToHtml(doc, settings);

                File.WriteAllText("Test.html", html.ToStringNewLineOnAttributes());
            }
        }
    }

nameSpaces:

using System.Xml;
using System.Xml.Xsl;
using OpenXmlPowerTools;
using System.Xml.Linq;
using DocumentFormat.OpenXml.Packaging;

I tried to pass documents created by word 2010, with header and without and still getting errors in the same place. Maybe I’m passing document incorrectly or something with the document itself.

Maybe there is another way to convert docx to pdf without using comercial components, like Apose.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:13:27+00:00Added an answer on June 12, 2026 at 4:13 am

    found the problem. Errors was occuring because of different references between power tools project and main project.
    DocumentFormat.OpenXml version on my project was 2.5.5513.0 and on power tools – 2.0.5022.0
    After making references to the same resource everything went fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.