none
Auto-fit HTML page onto Word page? RRS feed

  • Question

  • We have a WPF C# app that reads in an HTML file, opens a new Word Doc from that HTML file, makes various changes to the XML behind the Word Doc, then saves the final Word Doc.  One of the new requirements is to auto-fit each HTML page onto a Word page, condensing each page only where it is necessary.  Unless there is a shortcut, I believe that I would need to calculate the exact twips needed to display each piece of text, while considering paper size, font family, font size, left and right margins, top and bottom margins, headers and footers, indents, justification, condensed character spacing, table line thickness, etc., etc.  Then once I think I have filled a Word page, but I have remaining data on the HTML page, I would have to slightly condense the character spacing for that page, and start the page fitting process again, repeating this process until the entire HTML page fit onto the Word page, and then repeating the entire process for every page in the doc.  I would be practically writing my own Word engine inside my app!  Does anyone have a shortcut?  Thanks. 

    (note: I have considered the "shrink to fit" or "shrink one page" option available in the print preview, which reduces the doc by one page, but this does not satisfy the requirement)

    Tuesday, March 23, 2010 8:57 PM

Answers

  • Hi Dave,

    Thanks for your reply.

    It is so complex to accomplish this task of calculating the size of text by Open XML SDK currently that we suggest you trying other technologies such as VSTO. You may try to ask questions in forum Visual Studio Tools for Office.

    Hope this helps.

    Thanks,

    Lu

    • Marked as answer by DaveMSDN123 Tuesday, March 30, 2010 4:20 PM
    Tuesday, March 30, 2010 8:10 AM

All replies

  • Even if a shortcut does not exist, I would consider this question to be helpfully answered if one of the experts could at least confirm that it would require a significant coding effort (perhaps similar to what I had described) to accomplish something like this.
    Friday, March 26, 2010 1:00 PM
  • Hi DaveMSDN123,

    Thanks for your question.

    One thing I need to ensure from your description is that is your need to calculate the size of a text in Word document or in the HTML page? If you need to know the size of the text in Word, it is not so easy to accomplish by the Open XML SDK, for we have to consider fonts, margins and many other facts as mentioned in your post. Open XML SDK doesn't support such layout application behavior.

    Thanks,

    Lu

    Monday, March 29, 2010 2:48 AM
  • Yes, I'm talking about calculating the size of text in the Word doc, not the HTML page.  The HTML files are usually about 60 pages long, containing a "div" with "id=PGBRK" at each page break.  I would have to process one HTML page at a time, opening with Word using Open XML SDK, check to see if it all fits into one Word page, and if not then condense just enough until it does fit, then continue page by page while appending to the Word doc.  I can not find any way to do this, and after reading your reply, I don't think I'm going to find it.

    Thanks,

    Dave

    Monday, March 29, 2010 2:06 PM
  • Hi Dave,

    Thanks for your reply.

    It is so complex to accomplish this task of calculating the size of text by Open XML SDK currently that we suggest you trying other technologies such as VSTO. You may try to ask questions in forum Visual Studio Tools for Office.

    Hope this helps.

    Thanks,

    Lu

    • Marked as answer by DaveMSDN123 Tuesday, March 30, 2010 4:20 PM
    Tuesday, March 30, 2010 8:10 AM