Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Saving rtf-file

Saving rtf-file

Scheduled Pinned Locked Moved Visual Basic
question
23 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jtpaa

    Yes. The user, who opens the file must have Word or similar program to read the rtf-file. But, the user (end user), who creates the rtf-file with my application does not necessarily have MS Word.

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #21

    The RTF specification is extensive, and programs that accept and/or generate RTF documents pick and choose what subset of commands they use. I performed a little test using Wordpad 6.0 (on Vista), creating, printing, storing and inspecting a simple RTF file both in portrait and in landscape. My observations include: - margin information was not stored in the document itself. - paper orientation was not stored in the document itself. - both are settings for Wordpad, not for the document; when you open Wordpad, you get what you had last time in Wordpad. As Wordpad seems to consider these app settings rather than document settings, I expect it will ignore the relevant commands if they were present in the file (I haven't tested this). FYI: Wordpad can show much more complex RTF documents than it allows the user to create; as an example, it can show tables, graphs, and images; things it doesn't offer the means for to insert in an empty document. :)

    Luc Pattyn [My Articles] Nil Volentibus Arduum

    J 1 Reply Last reply
    0
    • L Luc Pattyn

      The RTF specification is extensive, and programs that accept and/or generate RTF documents pick and choose what subset of commands they use. I performed a little test using Wordpad 6.0 (on Vista), creating, printing, storing and inspecting a simple RTF file both in portrait and in landscape. My observations include: - margin information was not stored in the document itself. - paper orientation was not stored in the document itself. - both are settings for Wordpad, not for the document; when you open Wordpad, you get what you had last time in Wordpad. As Wordpad seems to consider these app settings rather than document settings, I expect it will ignore the relevant commands if they were present in the file (I haven't tested this). FYI: Wordpad can show much more complex RTF documents than it allows the user to create; as an example, it can show tables, graphs, and images; things it doesn't offer the means for to insert in an empty document. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      J Offline
      J Offline
      jtpaa
      wrote on last edited by
      #22

      Thanks for clarifying WordPad behaviour. So, the WordPad does not care about document page setting. But, if the user opens document for example with MS Word, then these settings coul be used. I managed to set the rtf-code by following way. I dont know whether it's clever way or not, but MS Word understood it and opened document in landscape. The created and saved rtf-file is reopened, page settings are inserted into rtf-code, and finally file is saved again.

      Me.rtbPrint.SaveFile(Me.SaveFileDialog.FileName, RichTextBoxStreamType.RichText)
      Dim FILE_NAME As String = Me.SaveFileDialog.FileName
      Dim objReader As New System.IO.StreamReader(FILE_NAME)
      Dim sString = objReader.ReadToEnd
      objReader.Close()
      sString = sString.Insert(6, "\paperw15840\paperh12240\margl720\margr144\margt720\margb288\lndscpsxn")
      Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
      objWriter.Write(sString)
      objWriter.Close()

      Hope, that the code is seen properly.

      L 1 Reply Last reply
      0
      • J jtpaa

        Thanks for clarifying WordPad behaviour. So, the WordPad does not care about document page setting. But, if the user opens document for example with MS Word, then these settings coul be used. I managed to set the rtf-code by following way. I dont know whether it's clever way or not, but MS Word understood it and opened document in landscape. The created and saved rtf-file is reopened, page settings are inserted into rtf-code, and finally file is saved again.

        Me.rtbPrint.SaveFile(Me.SaveFileDialog.FileName, RichTextBoxStreamType.RichText)
        Dim FILE_NAME As String = Me.SaveFileDialog.FileName
        Dim objReader As New System.IO.StreamReader(FILE_NAME)
        Dim sString = objReader.ReadToEnd
        objReader.Close()
        sString = sString.Insert(6, "\paperw15840\paperh12240\margl720\margr144\margt720\margb288\lndscpsxn")
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
        objWriter.Write(sString)
        objWriter.Close()

        Hope, that the code is seen properly.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #23

        I can't comment in any detail on Word as I avoid it as much as I can; I do know Word creates pretty complex output files (whether RTF or HTML), and behaves differently from one version to the next. FWIW: there are other RTF-compatible programs, such as WordPad++. They might offer the functionality you require without having the complexities and cost of Word. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups