Printing RTF files in Word using Response.ContentType

Discussion in 'ASP General' started by Larry Neylon, Jul 21, 2009.

  1. Larry Neylon

    Larry Neylon Guest

    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.
    Larry Neylon, Jul 21, 2009
    #1
    1. Advertising

  2. 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
    Daniel Crichton, Jul 22, 2009
    #2
    1. Advertising

  3. Larry Neylon

    Neil Gould Guest

    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
    Neil Gould, Jul 22, 2009
    #3
  4. Larry Neylon

    Larry Neylon Guest

    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.
    Larry Neylon, Jul 22, 2009
    #4
  5. Larry Neylon

    Neil Gould Guest

    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
    Neil Gould, Jul 23, 2009
    #5
  6. Larry Neylon

    Larry Neylon Guest

    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.
    Larry Neylon, Jul 23, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bart Vanwesemael
    Replies:
    1
    Views:
    508
    William F. Robertson, Jr.
    Jul 28, 2003
  2. sonic

    contenttype rtf question

    sonic, Jan 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,490
    sonic
    Jan 14, 2005
  3. Bill
    Replies:
    0
    Views:
    366
  4. Katie
    Replies:
    8
    Views:
    249
    Anthony Jones
    Aug 17, 2006
  5. Tony
    Replies:
    2
    Views:
    263
Loading...

Share This Page