none
Merge RTF files RRS feed

  • Question

  • Hi All,

    We have got a requirement to merge RTF files in Java platform. is there any tools/utility/application available to purchase?

    Thanks,

    Loganathan


    • Edited by .Logan Monday, May 8, 2017 1:27 PM
    Monday, May 8, 2017 1:21 PM

All replies

  • Hello,

    This forum is for developers to discuss development issues when using Word Object Model.

    Your question about purchasing application for Java platform is out of scope, sorry that we could not offer any suggestion, I suggest you post on Java forum. Thanks for your understanding.

    To develop a project to merge RTF files, we could use Documents.Open to open existing rtf files, use Documents.Add
    to create a new file. Then we could use Selection.Copy and Selection.Paste to copy their content into the new created file, then save it into RFT file using
    Document.Save.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 9, 2017 5:53 AM
    Moderator
  • Hi Celeste,

    Thanks for a quick reply. Sorry for the confusion. Any tool which has the support for Unix and windows platform, So that we can invoke/call the tool from Java code for merging 'n' number of RTF files. If you would provide me some suggestion, that will be great. I am a Java developer.

    Thanks,

    Loganathan


    Tuesday, May 9, 2017 12:24 PM
  • Here is a sample to merge files using VBA. 

    I have no experience with Java, but i think you might call the macro in your java application.

    Please visit Calling VBA code from Java
    Sub CombineRtfFile()
    Dim rtf1 As Document
    Dim rtf2 As Document
    Dim brtf As Document
    ' "'" means comment in vba
    ' i want to combine rtf1,rtf2 into blankrtf
    ' get these file object
    Set rtf1 = Application.Documents.Open("C:\Users\User\Desktop\VBA Folder\RTF1.rtf")
    Set rtf2 = Application.Documents.Open("C:\Users\User\Desktop\VBA Folder\RTF2.rtf")
    Set brtf = Application.Documents.Open("C:\Users\User\Desktop\VBA Folder\BlankRTF.rtf")
    
    'Turn screen updating off to speed up code
    Application.ScreenUpdating = False
    
    'change to rtf1 file
    rtf1.Activate
    'copy whole context in rtf1
    Selection.WholeStory
    Selection.Copy
    'change to blankrtf file
    brtf.Activate
    'selection move to last line
    Selection.EndKey Unit:=wdLine
    'paste context
    Selection.TypeParagraph
    Selection.Paste
    'close rtf1 file without saving changes
    rtf1.Close False
    
    rtf2.Activate
    Selection.WholeStory
    Selection.Copy
    brtf.Activate
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.Paste
    rtf2.Close False
    
    'close blankrtf with saving changes
    brtf.Close True
    'Turn screen updating off
    Application.ScreenUpdating = True
    End Sub


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 10, 2017 5:51 AM
    Moderator
  • I am not familiar with the above approach, that is running VB code in Unix Platform. Thanks for your suggestion.
    Wednesday, May 10, 2017 6:55 AM
  • Hi Loganathan,

    Thanks for your post.

    This forum is used to discuss about Office developing issue, your issue seems to be related with dealing with REF files. I am afraid there is no Office library could be used directly in Java.

    As a search result by Google, I suggest you check whether below links meet your requirement.

    # Merging two RTF files in Java

    https://stackoverflow.com/questions/4367336/merging-two-rtf-files-in-java

    # Merging RTF files?

    https://stackoverflow.com/questions/41225713/merging-rtf-files

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 2, 2017 7:40 AM