Printing RTF files in Word using Response.ContentType

L

Larry Neylon

Hi there,

I've got a legacy app that is creating rtf documents for printing from Word.

The problem I have is that for some users (not all) the Page Size defaults
to Letter, rather than their default A4.

I was hoping to be able to add some actual RTF code inline to force A4 size,
but am unsure how to mix'n'match RTF and HTML.

Sample Code:

Response.Clear()
Response.CacheControl = "Public"
Response.Expires = -1
Response.ExpiresAbsolute = Now() + 1
Response.ContentType = "application/rtf"
Response.AddHeader "Content-Disposition", "attachment;filename=" &
Replace(Request.Form("DB_subject"), " ", "_") & ".rtf"
Response.Write("<html><head></head><body>Test</body></html>")

This opens fine, but I want to force a A4 size using RTF code, e.g.

Response.Write("{\rtf1\paperh16838\paperw11906}")

Playing about with this it either gives me a blank page or the actual html
uncoverted.

Any suggestions on how to force this to A4 or embed the RTF into streamed
HTML.

Thanks alot,
Larry.
 
D

Daniel Crichton

Larry wrote on Tue, 21 Jul 2009 17:22:20 +0100:
Hi there,
I've got a legacy app that is creating rtf documents for printing from
Word.
The problem I have is that for some users (not all) the Page Size
defaults to Letter, rather than their default A4.
I was hoping to be able to add some actual RTF code inline to force A4
size, but am unsure how to mix'n'match RTF and HTML.
Sample Code:
Response.Clear()
Response.CacheControl = "Public"
Response.Expires = -1
Response.ExpiresAbsolute = Now() + 1
Response.ContentType = "application/rtf"
Response.AddHeader "Content-Disposition", "attachment;filename=" &
Replace(Request.Form("DB_subject"), " ", "_") & ".rtf"
Response.Write("<html><head></head><body>Test</body></html>")
This opens fine, but I want to force a A4 size using RTF code, e.g.

Playing about with this it either gives me a blank page or the actual
html uncoverted.
Any suggestions on how to force this to A4 or embed the RTF into
streamed HTML.

When you use only HTML, Word is interpreting it as HTML and formatting it.
Adding the RTF command will stop Word automatically converting the HTML
content, which is what you are seeing. If you want to add RTF commands,
you'll have to format the entire document in RTF, not HTML.
 
N

Neil Gould

Larry said:
Hi there,

I've got a legacy app that is creating rtf documents for printing
from Word.

The problem I have is that for some users (not all) the Page Size
defaults to Letter, rather than their default A4.

I was hoping to be able to add some actual RTF code inline to force
A4 size, but am unsure how to mix'n'match RTF and HTML.

Sample Code:

Response.Clear()
Response.CacheControl = "Public"
Response.Expires = -1
Response.ExpiresAbsolute = Now() + 1
Response.ContentType = "application/rtf"
Response.AddHeader "Content-Disposition", "attachment;filename=" &
Replace(Request.Form("DB_subject"), " ", "_") & ".rtf"
Response.Write("<html><head></head><body>Test</body></html>")

This opens fine, but I want to force a A4 size using RTF code, e.g.

Response.Write("{\rtf1\paperh16838\paperw11906}")

Playing about with this it either gives me a blank page or the actual
html uncoverted.

Any suggestions on how to force this to A4 or embed the RTF into
streamed HTML.
In addition to Daniel's comments:
Unless forced, Word uses the default text formats & page size that the
recipient has set, so by not including any specfic RTF commands, the page
size used by the recipient should prevail. Of course, that has a lot of
implications regarding the general presentation of your document...

Best,
 
L

Larry Neylon

Thanks for the responses guys. I'd kind of guessed that as soon as you put
in some RTF the whole converting HTML stopped. Unfortunately I don't have
the time/budget to convert the code to pure RTF

As far as the Page Layout default is concerned, I've played on the client's
machine and they've got all the defaults set to A4, but when opening this
HTML->RTF it is overriding the default to set it to Letter. Doesn't happen
on all machines and I've spent ages looking into it.

Bit stuck here. I've no idea why the default settings get overridden on
certain machines and no simple way of forcing Word to open the document as
A4.

Oh well, thanks anyway.
 
N

Neil Gould

Larry said:
Thanks for the responses guys. I'd kind of guessed that as soon as
you put in some RTF the whole converting HTML stopped. Unfortunately
I don't have the time/budget to convert the code to pure RTF

As far as the Page Layout default is concerned, I've played on the
client's machine and they've got all the defaults set to A4, but when
opening this HTML->RTF it is overriding the default to set it to
Letter. Doesn't happen on all machines and I've spent ages looking
into it.

Bit stuck here. I've no idea why the default settings get overridden
on certain machines and no simple way of forcing Word to open the
document as A4.

Oh well, thanks anyway.
You may find this helpful:

http://www.codeproject.com/KB/office/Wordyna.aspx

Still, since the problem is not uniform on all machines, it seems that the
problem is unique to a setting on the machines that display the page in US
Letter size.

Best,
 
L

Larry Neylon

Thanks again Neil,

I'd already found that article and have rewritten this to output actual
..docs rather than RTF as per the article.

Am waiting confirmation from the end-user as to whether this is now fixed.

Will post code if so.

Larry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top