Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Printing RTF files in Word using Response.ContentType

Reply
Thread Tools

Printing RTF files in Word using Response.ContentType

 
 
Larry Neylon
Guest
Posts: n/a
 
      07-21-2009
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.


 
Reply With Quote
 
 
 
 
Daniel Crichton
Guest
Posts: n/a
 
      07-22-2009
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.


> 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.


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.

--
Dan


 
Reply With Quote
 
 
 
 
Neil Gould
Guest
Posts: n/a
 
      07-22-2009
Larry Neylon wrote:
> 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,

--
Neil Gould
Terra Tu Technical Publishing
www.TerraTu.com



 
Reply With Quote
 
Larry Neylon
Guest
Posts: n/a
 
      07-22-2009
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.


 
Reply With Quote
 
Neil Gould
Guest
Posts: n/a
 
      07-23-2009
Larry Neylon wrote:
> 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,

--
Neil Gould
Terra Tu Technical Publishing
www.TerraTu.com


 
Reply With Quote
 
Larry Neylon
Guest
Posts: n/a
 
      07-23-2009
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: what do you think on my summary on C, for 13-15 years studentin .rtf format [to cut and paste in a .rtf file] Kleuskes & Moos C Programming 8 10-13-2011 08:51 AM
RTF files to DAT files phrogee Computer Support 11 05-04-2005 04:05 AM
1.5, rtf & word Ike Java 2 10-25-2004 06:54 PM
JSP export RTF/MS Word Dev880 Java 4 04-08-2004 02:44 AM
Doing a 'mail merge' with RTF files (aka RTF templates) Tony Perl Misc 2 08-27-2003 08:12 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57