473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I shrink the size of Word documents by changing the format-settings?

I've created a solution who exported Access reports (graphics/tables) to a Word- and a PDF-format. Therefor I use PDFSharp and PDFFocus.
The PDF document is okay. But the Word-document looks good. Only the size of the Word-document, it has to send by e-mail, is much too big (17MB).

I have to open the Word document again to change the PageSettings to be sure, that the page-margins and the print orientation are correct.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using Microsoft.Office.Interop.Word;
  3.  
  4. namespace PageSetup
  5. {
  6.     class TestPageOrientation
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var app = new Microsoft.Office.Interop.Word.Application();
  11.             app.Visible = true;
  12.  
  13.             //Load Document
  14.             Document document = app.Documents.Open(@"C:\Temp\myDocument.docx");
  15.  
  16.             // I've added this rows below. ...And that works
  17.             document.Sections.First.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
  18.             document.Sections.Last.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
  19.             document.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
  20.  
  21.             // ... and this. But the LeftMargin I can leave it.
  22.             document.PageSetup.LeftMargin = 1.00F;
  23.             document.Save();
  24.         }
  25.     }
  26. }
  27.  
I don't know how it works in the Word-library source. But I've tried WdOrientation.wdOrientPortrait and once I was surprised. I saw this page in Landscape-format.

I think there is something wrong with my document sections, because the documents (with a lot of tables, graphics and a image) is much too big. And that's only after using this method.

So my next question is: How can I shrink the size of this Word document?

And what do I have to do to limit the amount of format-settings in this word-document?
Jul 31 '12 #1
1 2488
When I open the saved document and then I click on Save As, then I see that Word want to save it as a RTF-document. That could be the problem for this oversized document (22Mb).

Is there an option in the Word-component that will save your document in a Word-97-format?

Such as:
Expand|Select|Wrap|Line Numbers
  1. document.OptimizeForWord97 = true;
  2. document.DocumentFormat = WdDocumentFormat.WdWord97;
  3. document.Save();
  4.  
Can someone tell me the real syntax?

Thank you
Aug 8 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sudha | last post by:
Hi I need to write a c# program which has to merge selected word documents into one word document. Kindly advise the efficient way to achieve this. Thanks in advance sudha
8
by: Jason Steeves | last post by:
Can someone please point me in the right direction for displaying word documents onto a webpage? The word documents will contain text/tables/pictures. I am new to this and can't quite find what I...
5
by: vinod | last post by:
Hi, I intend to send word documents thru mail to my clients. I don't want my clients to save the word document to there system and i don't want them to print the word documents. How can i...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
2
by: David | last post by:
Using the article from this link, http://www.codeproject.com/aspnet/wordapplication.asp, I have been playing with generating Word documents using an ASP.NET application. The only short coming...
3
by: richi | last post by:
Hello, i'm hoping that somebody can point me in the right direction with my problem. I have been tasked with creating a simple browser based application that will allow the user to upload Word...
6
by: Justin | last post by:
Hi all, i need some help over here... i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a...
6
by: cyusman | last post by:
Hi, We have just moved our application to a new webfarm server environment which utilizing hardware load balancing, SSL off-loading and HTTP compression off-loading.My application is running on...
2
by: bbasberg | last post by:
Hello, I have been asked to move a paragraph to a new location in over 360 Word documents. I was shocked to find out that changing an attached template will only affect documents produced from...
20
MMcCarthy
by: MMcCarthy | last post by:
This problem was proposed to me but not really my area of expertise so I thought I would open it up to the forum to see if anyone had any bright ideas. The problem is generating Microsoft Word...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.