4

While I doubt it, if I open up a word document using OpenXML sdk in C# and add some info, is there any way for me to see if it still fits one page?

If it doesn't I wan't to reduce font size on specific items I added until it fits.

I could write this algorithm if I had the current size in relation to page size with margins and all that.

amurra
  • 15,221
  • 4
  • 70
  • 87
Ingó Vals
  • 4,788
  • 14
  • 65
  • 113
  • 1
    I'm not aware of anything for the OpenXML SDK which does this for you already, but as you say, it could be done. Not too bad for simple text only; worse if there are images and tables; and complex in the general case though. – JasonPlutext Jun 24 '11 at 23:01
  • No images but this is mostly based on variable number of items in a table. – Ingó Vals Jun 26 '11 at 13:06

1 Answers1

1

I ran across this example on another site, don't know if it'll work in your case, as it requires the Office PIA...

var app = new Word.Application();
var doc = app.Documents.Open("path/to/file");
doc.Repaginate()

var pageNumber = doc.BuiltInDocumentProperties("Number of Pages").Value as int;
Chester Husk
  • 1,408
  • 12
  • 14
  • Thank you for your input. Not sure what PIA stands for but it seems you actually have to run a word app and that's a no no. I'm thinking I have to look at the `Validate` object in the OPenXml namespace and see if it can do anything similiar. – Ingó Vals Jul 01 '11 at 12:55
  • 1
    Oh, sorry. PIA is a Primary Interop Assembly. They are provided by Microsoft to help automate Office applications. I think this site will help you navigate the Open XML file and find the page node: http://rmanimaran.wordpress.com/2010/08/03/programatically-get-count-pagesslidessheet-in-microsoft-wordpowerpointexcel-2007/ – Chester Husk Jul 01 '11 at 18:11
  • Problem is that the docProps/app.xml is probably generated by Microsoft word and is not included if I create the docx in C#. – Ingó Vals Jul 06 '11 at 14:40