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

    Hello Is it possible to save richtextbox-text so, that the page is in landscape format ? 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. What's wrong ?

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

    you're using windows form richtextbox?

    J 1 Reply Last reply
    0
    • L Lost User

      you're using windows form richtextbox?

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

      Yes, Windows form RichTextBox.

      L 1 Reply Last reply
      0
      • J jtpaa

        Yes, Windows form RichTextBox.

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

        check here.. http://lmgtfy.com/?q=Save+RFT+file+in+landscape+%2B+A4+mode%3F[^]

        L 1 Reply Last reply
        0
        • L Lost User

          check here.. http://lmgtfy.com/?q=Save+RFT+file+in+landscape+%2B+A4+mode%3F[^]

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

          You managed to spell "RTF" wrong.

          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

            You managed to spell "RTF" wrong.

            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
            #6

            What if the end user does not have Microsoft Word ? Is there a way to set the rtf-code without using Microsoft Word ? Can it be done trough RichTextBox-object ?

            L 1 Reply Last reply
            0
            • J jtpaa

              What if the end user does not have Microsoft Word ? Is there a way to set the rtf-code without using Microsoft Word ? Can it be done trough RichTextBox-object ?

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

              I'm sorry I don't understand. You say you want to save a RTF file and set its page settings to landscape, and you have some links to resolve that. Obviously any user that wants to read the file will need some program that accepts RTF, either MS Word or similar.

              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

                I'm sorry I don't understand. You say you want to save a RTF file and set its page settings to landscape, and you have some links to resolve that. Obviously any user that wants to read the file will need some program that accepts RTF, either MS Word or similar.

                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
                #8

                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 L 3 Replies 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
                  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
                                          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