AndriuZ
AndriuZ

Reputation: 656

replace (fix) fonts in LibreOffice Draw after importing PDF

I adapted BASIC macro to Draw but don't understand why it converted fonts only in first page. The code is:

REM  *****  BASIC  ***** https://www.prahladyeri.com/blog/2016/02/ten-libreoffice-macro-recipes.html#searchandrepl

Sub replace_letters
  Dim badletters() As String
  Dim goodletters() As String
  Dim n As Long
  Dim document As Object
  Dim pages as Object
  Dim sheet as Object
  Dim replace As Object

  badletters() = Array("À", "È", "Ë", "Á", "Ð", "Ø", "Û", "Þ", "à", "è", "ë", "á", "ð", "ø", "û", "þ")
  goodletters() = Array("Ą", "Č", "Ė", "Į", "Š", "Ų", "Ū", "Ž", "ą", "č", "ė", "į", "š", "ų", "ū", "ž")
  document = ThisComponent
  rem ?? need every page - see sheet = doc.CurrentSelection.Spreadsheet
  pages = document.getDrawPages()
  page = pages.getByIndex(0)
  replace = page.createReplaceDescriptor rem document.createReplaceDescriptor in case of Writer
  rem replace.SearchRegularExpression = True
  For n = lbound(badletters()) To ubound(badletters())
    replace.SearchString = badletters(n)
    replace.ReplaceString = goodletters(n)
    page.replaceAll(replace)
  Next n
  MsgBox("Done")
End Sub

Where is glitch?

Upvotes: 3

Views: 2072

Answers (2)

Martin
Martin

Reputation: 1

I know this is an old one and already answered to the satisfaction of the op, but there is a possibility to set up replacement fonts right inside the LibreOffice/OpenOffice options under fonts... Set up, open document and all fonts are replaced automatically, no further action necessary. For those who don't want to dabble with Macros and Basic and all that.

Upvotes: 0

Jim K
Jim K

Reputation: 13790

This statement grabs only the first page:

page = pages.getByIndex(0)

Do this instead:

For pageNum = 0 To pages.getCount() - 1
    page = pages.getByIndex(pageNum)

This uses the XIndexAccess interface.

Upvotes: 2

Related Questions