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
    Lost User
    wrote on last edited by
    #9

    In that case your code needs to ensure that the file is fully compliant with the RTF specification.

    Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

    J 1 Reply Last reply
    0
    • L Lost User

      In that case your code needs to ensure that the file is fully compliant with the RTF specification.

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

      Could You explain what you mean?

      L 1 Reply Last reply
      0
      • J jtpaa

        Could You explain what you mean?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #11

        What more can I say? You are saving a file as RTF so you need to ensure that its content follows the RTF format specification. If you still don't understand then I suggest taking a look here[^].

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        J 1 Reply Last reply
        0
        • L Lost User

          What more can I say? You are saving a file as RTF so you need to ensure that its content follows the RTF format specification. If you still don't understand then I suggest taking a look here[^].

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

          Yes you are right, the file must follow rtf-format specification. As I mentioned earlier, I have tried to make the file to follow rtf format by following way: Rtf-file contains parameters of page settings and I have tried to modify those parameters, but with no success. I have not been able to set those parameters at all. Is it so that richtextbox does not allow to set Richtextbox.rtf - value ? I have tried to modify rtf-code by setting the "\landscape" or "\lndscpsxn" parameters into rtf-code by: MyRtb.rtf = "{\rtf1\... or MyRtb.selectedrtf = "{\rtf1\... Those lines don't change MyRTb.rtf value.

          L 1 Reply Last reply
          0
          • J jtpaa

            Yes you are right, the file must follow rtf-format specification. As I mentioned earlier, I have tried to make the file to follow rtf format by following way: Rtf-file contains parameters of page settings and I have tried to modify those parameters, but with no success. I have not been able to set those parameters at all. Is it so that richtextbox does not allow to set Richtextbox.rtf - value ? I have tried to modify rtf-code by setting the "\landscape" or "\lndscpsxn" parameters into rtf-code by: MyRtb.rtf = "{\rtf1\... or MyRtb.selectedrtf = "{\rtf1\... Those lines don't change MyRTb.rtf value.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #13

            Sorry but this makes no sense. Explain clearly what your program is trying to do, show the actual lines of code (surrounded by <pre> tags so it's readable) and what results you get.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            J 1 Reply Last reply
            0
            • L Lost User

              Sorry but this makes no sense. Explain clearly what your program is trying to do, show the actual lines of code (surrounded by <pre> tags so it's readable) and what results you get.

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

              OK There is RichTextBox (MyRtb), which content is saved as rtf-file. Rtf-file contains page formatting data, which I have tried to modify so that the page orientation is Landscape. I have tried to set Document Formatting Property "\landscape" and Section Text Property "\lndscpsxn". Those properties are documented in rtf specification. Code lines, which I used for setting those properties:

              Myrtb.Rtf = "{\rtf1\landscape}"

              Myrtb.Rtf = "{\rtf1\lndscpsxn}"

              Well, it might be that those parameters are not in the right place in rtf-code. But anyway, it seems that those lines do not affect rtf code at all. And the main question is: Is it possible at all (in code) to modify rtf-file so that the page orientation is in Landscape mode ?

              L 1 Reply Last reply
              0
              • J jtpaa

                OK There is RichTextBox (MyRtb), which content is saved as rtf-file. Rtf-file contains page formatting data, which I have tried to modify so that the page orientation is Landscape. I have tried to set Document Formatting Property "\landscape" and Section Text Property "\lndscpsxn". Those properties are documented in rtf specification. Code lines, which I used for setting those properties:

                Myrtb.Rtf = "{\rtf1\landscape}"

                Myrtb.Rtf = "{\rtf1\lndscpsxn}"

                Well, it might be that those parameters are not in the right place in rtf-code. But anyway, it seems that those lines do not affect rtf code at all. And the main question is: Is it possible at all (in code) to modify rtf-file so that the page orientation is in Landscape mode ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #15

                Myrtb.Rtf = "{\rtf1\landscape}
                Myrtb.Rtf = "{\rtf1\lndscpsxn}

                If that is all the code you have I don't see how it can affect anything. Where do you modify the contents of your RTF file before saving it?

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                J 1 Reply Last reply
                0
                • L Lost User

                  Myrtb.Rtf = "{\rtf1\landscape}
                  Myrtb.Rtf = "{\rtf1\lndscpsxn}

                  If that is all the code you have I don't see how it can affect anything. Where do you modify the contents of your RTF file before saving it?

                  Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

                  sText is String, which contains text and linefeeds

                  Myrtb.SelectionColor = Color.Black

                  Myrtb.SelectionFont = New Font("Microsoft Sans Serif", 14, FontStyle.Bold, GraphicsUnit.Point)

                  Myrtb.SelectedText = sText

                  Myrtb.Rtf = "{\rtf1\landscape}

                  Myrtb.Rtf = "{\rtf1\lndscpsxn}

                  Myrtb.SaveFile(Me.SaveFileDialog.FileName, RichTextBoxStreamType.RichText)

                  L 2 Replies Last reply
                  0
                  • J jtpaa

                    sText is String, which contains text and linefeeds

                    Myrtb.SelectionColor = Color.Black

                    Myrtb.SelectionFont = New Font("Microsoft Sans Serif", 14, FontStyle.Bold, GraphicsUnit.Point)

                    Myrtb.SelectedText = sText

                    Myrtb.Rtf = "{\rtf1\landscape}

                    Myrtb.Rtf = "{\rtf1\lndscpsxn}

                    Myrtb.SaveFile(Me.SaveFileDialog.FileName, RichTextBoxStreamType.RichText)

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #17

                    Please format your code properly, it only needs one set of tags around it and should appear thus:

                    Myrtb.SelectionColor = Color.Black
                    Myrtb.SelectionFont = New Font("Microsoft Sans Serif", 14, FontStyle.Bold, GraphicsUnit.Point)

                    You also probably need to uncheck the box titled "Treat my content as plain text, not as HTML ".

                    Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                    1 Reply Last reply
                    0
                    • J jtpaa

                      sText is String, which contains text and linefeeds

                      Myrtb.SelectionColor = Color.Black

                      Myrtb.SelectionFont = New Font("Microsoft Sans Serif", 14, FontStyle.Bold, GraphicsUnit.Point)

                      Myrtb.SelectedText = sText

                      Myrtb.Rtf = "{\rtf1\landscape}

                      Myrtb.Rtf = "{\rtf1\lndscpsxn}

                      Myrtb.SaveFile(Me.SaveFileDialog.FileName, RichTextBoxStreamType.RichText)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #18

                      See here[^] for some suggestions as to formatting; it suggests your \landscape command comes before your text.

                      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                      J 1 Reply Last reply
                      0
                      • L Lost User

                        See here[^] for some suggestions as to formatting; it suggests your \landscape command comes before your text.

                        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

                        Ok, thank you. The only solution offered for this problem in the web is this MS Word solution, and it is quite "rough" programming. So I wonder if it's possible at all (in code) to set/modify rtf-code part of the rtf-file.

                        1 Reply Last reply
                        0
                        • 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
                          #20

                          AFAIK every Windows version includes a copy of WordPad, which natively uses the RTF format. It also is the application associated with the RTF extension until you install something that replaces that association (such as MS Word). I use RTF a lot, I have classes to generate RTF documents, then open them in WordPad for the user to inspect, modify if necessary, print, etc. RTF is a complex language, its manual is hundreds of pages. Generating a valid document is quite doable, altering an existing one can be a real challenge. :)

                          Luc Pattyn [My Articles] Nil Volentibus Arduum

                          1 Reply Last reply
                          0
                          • 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