Scribusoid

Author Topic: Replace carriage returns with blank spaces  (Read 2178 times)

ClaraMontseny

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
  • Scribus User
Replace carriage returns with blank spaces
« on: September 01, 2015, 02:56:13 pm »
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

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
  • Scribus User
    • JavierSam
Re: Replace carriage returns with blank spaces
« Reply #1 on: March 14, 2022, 12:03:16 am »
Hello everyone.
I am in a similar situation to Clara.
Does anyone know of a way to solve it?

JavierSam

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
  • Scribus User
    • JavierSam
Re: Replace carriage returns with blank spaces
« Reply #2 on: March 14, 2022, 02:01:12 am »
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.
Code: [Select]
#!/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

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
  • Scribus User
Re: Replace carriage returns with blank spaces
« Reply #3 on: March 30, 2022, 09:34:44 pm »
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

  • Hero Member
  • *****
  • Posts: 1676
  • Karma: 18
Re: Replace carriage returns with blank spaces
« Reply #4 on: March 31, 2022, 06:48:56 am »
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

  • Newbie
  • *
  • Posts: 36
  • Karma: 1
  • Scribus User
Re: Replace carriage returns with blank spaces
« Reply #5 on: March 31, 2022, 04:38:22 pm »
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.
« Last Edit: March 31, 2022, 05:02:32 pm by steven8 »
Scribus 1.4.8 Stable
Windows 11

Nermander

  • Hero Member
  • *****
  • Posts: 1534
  • Karma: 19
Re: Replace carriage returns with blank spaces
« Reply #6 on: April 02, 2022, 11:54:33 am »
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".