Ask Your Question

search and replace to find all tabs and replace them with a space? [closed]

asked 2018-01-31 04:18:48 +0200

Ropi27 gravatar image

updated 2020-10-28 01:32:30 +0200

Alex Kemp gravatar image

I have a pdf file that I have to reformat, so I I can edit it and remail it. I can't upload a file showing the issue because I don't have 3 points-not sure what that means::>

My edit would take me months, there's almost 2000 pages in the document.

It appears the pdf has tabs in it (between the words) when I select the text and paste it into an ods file. I need to find each tab and convert it to a space....either that, or make the tab value equal to one so it will appear to be a space.

I can't figure out how to use either possible solution.


C:\fakepath\test file.odt

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-02-22 00:39:36.324771


+1 .. should be enough to upload your PDF file.

librebel gravatar imagelibrebel ( 2018-01-31 04:31:07 +0200 )edit

TY librebel, But I can only tell you what the screen says, it said I need 3 points. I can attach a screen capture showing my screen, but it won't allow me to upload the screen capture till I get 3 points. Is there a quick and dirty way to get 3 points?

Ropi27 gravatar imageRopi27 ( 2018-01-31 05:07:52 +0200 )edit

You already have 11 points ( the +1 vote gave you 10 karma points).

librebel gravatar imagelibrebel ( 2018-01-31 05:35:24 +0200 )edit

I'm new to the forum, and don't know all the features yet. Now that I know the points refer to 'karma points', I'll look them up to understand them!!! I see 'karma' listed on the page after I log in, so I did get a the short version of what karma points mean! I need to read the FAQ. It's good to be aboard and thanks to all who run the forum and contribute. Many TY for the help.

Ropi27 gravatar imageRopi27 ( 2018-01-31 18:42:04 +0200 )edit

This is what I have when I paste a paragraph from the pdf into writer:

What I say to people that say they hate exercise is that, fine, you can hate exercise. Oftentimes, you're
not going to fall immediately in love with

This is what I would like to have as a result of some sort of search and replace (or similar) action:

What I say to people that say they hate exercise is that, fine, you can hate exercise. Often times, you're not going to fall immediately in love with

Ropi27 gravatar imageRopi27 ( 2018-01-31 19:28:19 +0200 )edit

The message format above was changed by the forum when I submitted it-disregard it. I did upload my test file, which is a native writer file, see the edit to my original post.

Ropi27 gravatar imageRopi27 ( 2018-01-31 19:36:48 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2018-01-31 05:43:53 +0200

librebel gravatar image

updated 2018-01-31 19:53:46 +0200

Hello @Ropi27,

To find all Tabs in the current Draw document, and replace them with a Space, you could use the function Draw_ReplaceAll() specified below.

Just call it as follows ( first open your PDF in LibreOffice Draw):

Draw_ReplaceAll( chr(9), chr(32) )

EDIT 2018-01-31 :

Or just call the helper method Draw_ReplaceAll_Tabs_with_a_Space() directly from the menu "Tools : Macros : Run Macro...".

Sub Draw_ReplaceAll_Tabs_with_a_Space()
    Dim lCount as Long : lCount = Draw_ReplaceAll( chr(9), chr(32) )
    msgbox "Replaced " & lCount & " Tabs with Spaces."
End Sub

Function Draw_ReplaceAll( strFind As String, strReplace As String ) As Long
REM Perform a Find/Replace inside the current Draw document.
REM <strFind>   : String to be found and replaced;  (Does not support Regular Expressions).
REM <strReplace>: String to replace the found substring with.
REM Returns the number of occurrences that were Found/Replaced.
    Dim oDoc As Object  :  oDoc = ThisComponent
    If oDoc.supportsService( "" ) Then
        Dim oDrawPages As Object  :  oDrawPages = oDoc.getDrawPages()
        Dim oDrawPage As Object
        Dim oReplace as Object
        Dim lCount As Long
        Dim i As Integer
        For i = 0 To oDrawPages.getCount() - 1      REM Traverse all DrawPages.
            oDrawPage = oDrawPages.getByIndex( i )
            oReplace  = oDrawPage.createReplaceDescriptor()
            oReplace.setSearchString( strFind )
            oReplace.setReplaceString( strReplace )
        '   oReplace.SearchCaseSensitive = True     REM TODO: Optional parameters.'
        '   oReplace.SearchBackwards = True '
        '   oReplace.SearchWords = True '
            lCount = lCount + oDrawPage.replaceAll( oReplace )
        Next i
        Draw_ReplaceAll = lCount
    End If
End Function

HTH, lib

edit flag offensive delete link more


WOW, ty! But, I don't understand any of this. I prefer to learn rather than to follow blindly-once learned, I do not have to continue looking for help/support. I am not sure why opening the pdf in Draw is needed, since I want the modified format to be readable in a writer document. What part of the libreoffice help file do I need to read in order to understand the suggested answer (I just need a 'hint'....or some would say 'a nudge in the right direction)'.

Ropi27 gravatar imageRopi27 ( 2018-01-31 19:18:30 +0200 )edit

Yw @Ropi27,

If you open a PDF document in LibreOffice, it is automatically opened in Draw, since that is the LibreOffice program that can handle PDF.

I'll update my answer with an easy way for you to call the macro directly from the menu Tools : Macros : Run Macro...

Nudge: Help for LibreOffice Basic and Macros

librebel gravatar imagelibrebel ( 2018-01-31 19:39:26 +0200 )edit

This worked for me, with a bit of a mission (Can't upvote yet though....)

Gert van den Berg gravatar imageGert van den Berg ( 2020-06-10 21:45:32 +0200 )edit

answered 2018-01-31 04:41:33 +0200

paul1149 gravatar image

Tabs have special meanings in Calc. Can you paste it into Writer? There, you would do a search for \t with "regular expressions" enabled, and replace it with a space.

edit flag offensive delete link more


I am pasting it into writer Paul, from pdf to writer. The test file I wanted to post is a writer document. Am I missing something? There is no calc involved.

I did find the /t with 'regular expressions' enabled in this forum with a search, but I do not know (and can't find) a character that equates to a 'space'. I tried tapping the space bar in the replace section of the dialog box for find and replace, but writer doesn't recognize the space character if entered from the KB.

Ropi27 gravatar imageRopi27 ( 2018-01-31 05:15:47 +0200 )edit

Question Tools

1 follower


Asked: 2018-01-31 04:18:48 +0200

Seen: 1,988 times

Last updated: Jan 31 '18