Replace carriage returns with blank spaces

Previous topic - Next topic

ClaraMontseny

Hello everyone,

I copied a pdf text into my scribus file so it has a lot of carriage returns. I want to replace those carriage returns with blank spaces. Normally, when I use InDesign I make use of GREP. I have explored the 'Search/Replace' settings but I see no options for what I need. Can anyone help me? Thank you very much!

JavierSam

Hello everyone.
I am in a similar situation to Clara.
Does anyone know of a way to solve it?

JavierSam

ok, I just found a possible solution using a script.
It is based on this one:
https://wiki.scribus.net/canvas/Clean-up_the_imported_text_based_on_the_Slovak_typographic_rules
with a small modification.
Copy the following code and save it as a .PY file.
Then run the script from Scribus with the selected text frame.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

adapted from
https://wiki.scribus.net/canvas/Clean-up_the_imported_text_based_on_the_Slovak_typographic_rules

"""

import sys
import re

try:
    import scribus
except ImportError,err:
    print 'This Python script is written for the Scribus scripting interface. It can only be run from within Scribus.'
    sys.exit(1)

if not scribus.haveDoc():
    scribus.messageBox('Warning', 'You should open a document.', scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(1)
if scribus.selectionCount() == 0:
    scribus.messageBox('Warning', 'You should select a text frame.', scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(1)
if scribus.selectionCount() > 1:
    scribus.messageBox('Warning', 'You should select one text frame.', scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(1)

replacements = (
    # double carriage return to carriage return
    (u'\u000d'+u'\u000d'+r'+',u'\u000d'),
)

d = scribus.getSelectedObject()

if scribus.getObjectType(d) != 'TextFrame':
    scribus.messageBox('Warning', 'You should select a text frame.', scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(1)
else:
    for item in replacements:
        content = unicode(scribus.getAllText(d))
        p = re.compile(item[0])
        r = re.finditer(p, content)
        for i in reversed(tuple(r)):
            count = i.end()-i.start()
            scribus.selectText(i.start(), count, d)
            scribus.deleteText(d)
            scribus.insertText(item[1], i.start(), d)
    scribus.setRedraw(True)
    scribus.docChanged(True)
    scribus.messageBox('Info', 'Script finished successfully.', scribus.ICON_INFORMATION, scribus.BUTTON_OK)

Engineering_text

Not what the original poster was asking for, but there is another work around for those not wanting to run a script might be helpful here. I cut and pasted the pdf text into a word processor, then saved the file in an old word doc format -which Scribus can import- and the extra carriage returns were removed. I happen to use home version of Word Perfect, but for the Linux world there are a variety of free word processors.

You probably know this already, but many word processors also allow for making all the tab and carriage returns visible characters so that you can run "find and replace" to get rid of extra spaces, tabs, and carriage returns. To the extent I can, I like to do all the writing and story editing (grammar, spelling, revisions, etc.)  in a word processor, then pull that into Scribus.

utnik

hi all

'search and replace' works in scribus, but you can't insert the carriage return direct in the search field. you need to copy it from your text and paste it into the search field. (you won't see see it either - but it works...)

utnik

steven8

#5
There is only one catch to removing all the carriage returns.  You're left with one big blob of text and you have to go back and locate where all those paragraphs end and recreate them.  It can be a real pain in the arse.  You can do it if you want to.  Alternate search and replace in Open/Libre Office makes it easy.  Couple clicks and the only carriage return you have left is the one at the end of everything.

That script didn't remove anything for me.
Scribus 1.6.0 Stable
Windows 11

Nermander

If you are importing a text that has a CR at the end of each line (instead of just the end of the paragraph) this is usually what you want.

In Word I used to have a macro for imported text files doing the following:
1. Replace all paragraph breaks with line breaks
2. Replace all double line breaks with a single paragraph break
3. Replace all remaining line breaks with a space
(4. Replace all double spaces with a single space)


I think I named it "cleanup".