[Solved] Can I embed font in ODF document?

Discuss the word processor
Locked
dninich
Posts: 8
Joined: Wed Feb 08, 2017 8:51 pm

[Solved] Can I embed font in ODF document?

Post by dninich »

Can I embed font in ODF document?
If Yes: How?
Else: Why not?
Last edited by MrProgrammer on Sat Nov 07, 2020 6:38 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
OpenOffice 4.1.4 on Windows 10
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Can I embed font in ODF document?

Post by acknak »

Greetings and welcome to the community forum!

Yes, it is possible, but the feature is not yet part of the ODF standard and is only implemented by LibreOffice. Apache OO will not be able to use the embedded fonts (I'm not sure if the document will open or not in AOO).

Personally, I'm not sure the advantages are worth the risk: if someone needs to edit the document, it isn't necessary to have all the fonts—OO will substitute something from the available fonts. If the document doesn't need to be edited, then you can send a pdf that will embed the fonts by default.
AOO4/LO5 • Linux • Fedora 23
User avatar
Zizi64
Volunteer
Posts: 11489
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can I embed font in ODF document?

Post by Zizi64 »

I think it is depends on the licence of the font what you want to embed.
Maybe you are not permitted to send a copy of a commercial font (like the fonts of the Windows, of the MS Office) to an another person.

https://www.microsoft.com/typography/faq/faq11.htm
https://en.wikipedia.org/wiki/SIL_Open_Font_License

Use the really cost free and open source fonts like the DejaVu font family, the Liberation font family, the Linux Libertine font family, and others.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
dninich
Posts: 8
Joined: Wed Feb 08, 2017 8:51 pm

Re: Can I embed font in ODF document?

Post by dninich »

First of all, thanks for swift response; it seems this is a great community and I must say that I read many posts from both acknak and Zizi64. You guys are legends and You helped me many, many times before.

@acknak
That's valuable info. For some reason Libre is not my cup of tea, maybe I'm old fashioned.
As for advantages, I want user to get document perfectly formatted and You know how font change can break it.
On the other hand, some typo always gets by and needs to be corrected. Doc could pack fonts.
Maybe I can "fix" formatting with manual breaks? Any tutorial?

@Zizi64
Here's what RedHat says for Liberation:
You are free to use these fonts on any system you would like. You are free to redistribute them under the GPL+exception license found in the download. Using these fonts does not subject your documents to the GPL, it liberates them from any proprietary claim. Once you have installed these fonts, I encourage you to make them your default in Thunderbird, FireFox, and Open Office. Heck, for that matter make them your default in Microsoft Office, in Microsoft Windows, in Apple OSX, in anything your would like. :D In many applications you can set Times New Roman, Arial and Courier New to convert to these fonts.
Guess that means I can pack them...just to find a way to do it.
OpenOffice 4.1.4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11489
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can I embed font in ODF document?

Post by Zizi64 »

Just a tip:

The LibreOffice can save your documents into Hybrid PDF file format too. It means: the created pdf file behave as a normal .pdf file in a 'Pdf reader' software, and you can edit it with LO as the ODF files you can.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Can I embed font in ODF document?

Post by acknak »

dninich wrote:...
As for advantages, I want user to get document perfectly formatted and You know how font change can break it.
On the other hand, some typo always gets by and needs to be corrected....
Ah. I see. That makes sense.

I don't know any way to address that, other than fixing the typos and sending the document back to you for final formatting, or installing the same fonts on both machines. I agree, neither of those are great solutions.

I believe there was some macro code on the forum (maybe it was the old forum) that listed all the fonts used by a document. That would at least give some assistance in getting the proper fonts installed. You'd have to try a search for it.
AOO4/LO5 • Linux • Fedora 23
User avatar
RoryOF
Moderator
Posts: 35087
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Can I embed font in ODF document?

Post by RoryOF »

Here it is, acknak, as an extension
TestFonts
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

dninich wrote:As for advantages, I want user to get document perfectly formatted and You know how font change can break it.
Indeed. For others searching the following may be useful.

Remember that the font displayed in the document's Font selection box is the font the document is calling for at the cursor position. This may not be the font being used to display or print the document because, if you do not have the font being called for installed on your PC, Windows (or other operating system) will silently substitute an alternative, available font without telling you. This will almost certainly cause different line spills and page spills.

The Testfonts add-on is invaluable to check which fonts are being called for in a document, and which are missing and have therefore been substituted. Note that some fonts do not have a font file for, say, Italic or Bold; and in that case, when Italic is called for, Windows itself applies a slant to the font to simulate Italic; and when Bold is called for, Windows thickens the characters to simulate Bold.

Also, always use .odt files and not .doc files so as to preserve formatting - see [Tutorial] Differences between Writer and MS Word files for the reasons.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
dninich
Posts: 8
Joined: Wed Feb 08, 2017 8:51 pm

Re: Can I embed font in ODF document?

Post by dninich »

Zizi64 wrote:Just a tip:
The LibreOffice can save your documents into Hybrid PDF file format too. It means: the created pdf file behave as a normal .pdf file in a 'Pdf reader' software, and you can edit it with LO as the ODF files you can.
Zizi64, this solution is revolutionary, why doesn't all internet buzz about it?
After some googling I found that OO actually embeds entire ODF document in PDF and only drawback is document size.
---
It seems AOO needs extension from arielch.org (aoo-pdf-import-0.1.0-windows-x86) for HybridPDF to work.
That extension always freeze extension manager and after restart EM throws error: "The status of this extension is unknown".
I'm so disappointed with Apache OO right now, but this is a separate topic.
I'm going to pursue this solution further and although this isn't direct answer to my question I consider this topic solved.
Thanks Zizi64!
OpenOffice 4.1.4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11489
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can I embed font in ODF document?

Post by Zizi64 »

Zizi64, this solution is revolutionary, why doesn't all internet buzz about it?
It is not a new feature in the LO.

It seems AOO needs extension from arielch.org (aoo-pdf-import-0.1.0-windows-x86) for HybridPDF to work.
I suppose the Hybrid PDF files will not work in the AOO. The PDF import extension can not open a pdf in the Writer app., it can open the normal pdf files in the Draw application, and you can make some cosmetics only on a pdf file.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

Zizi64
 Edit: Edited to correct it so as not to confuse searchers. 
Could you upload a tiny example hybrid .odt file with its PDF embedded as created by LO Could you upload a tiny example hybrid .PDF file with its .odt file embedded as created by LO- I would like to see what AOO thinks of it.

Presumably all the extension does it put the appropriately named PDF in the zipped .odt container.
Last edited by John_Ha on Thu Feb 16, 2017 1:37 am, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Zizi64
Volunteer
Posts: 11489
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can I embed font in ODF document?

Post by Zizi64 »

Could you upload a tiny example hybrid .odt file with its PDF embedded as created by LO - I would like to see what AOO thinks of it.
Of course:
PDF export.png
Hybrid PDF.pdf
(107.98 KiB) Downloaded 271 times
Hybrid PDF.odt
(41.59 KiB) Downloaded 281 times
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
dninich
Posts: 8
Joined: Wed Feb 08, 2017 8:51 pm

Re: Can I embed font in ODF document?

Post by dninich »

Zizi64 wrote: I suppose the Hybrid PDF files will not work in the AOO. The PDF import extension can not open a pdf in the Writer app., it can open the normal pdf files in the Draw application, and you can make some cosmetics only on a pdf file.
Zizi64, here is what author of PDF Import for Apache OpenOffice extension on http://extensions.openoffice.org/en/pro ... openoffice states:
The PDF Import Extension allows you to import and modify PDF documents. Best results with 100% layout accuracy can be achieved with the "PDF/ODF hybrid file" format, which this extension also enables. A hybrid PDF/ODF file is a PDF file that contains an embedded ODF source file. Hybrid PDF/ODF files will be opened in OpenOffice.org as an ODF file without any layout changes.
Heaven knows how this extension works, coz I can't install it. I guess it's the requirement for HPDF in AOO.
acknack would know better about AOO and Hybrid, but it seems AOO users are in loss here.
Guess it's back to .doc...
OpenOffice 4.1.4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11489
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Can I embed font in ODF document?

Post by Zizi64 »

Heaven knows how this extension works, coz I can't install it.
The LO contains this feature by default. Not needed to install it separatelly... And it works fine for me in my LO4.4.7.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
RoryOF
Moderator
Posts: 35087
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Can I embed font in ODF document?

Post by RoryOF »

There are two versions of the extension, as far as I remember, one for OO 3 the other for OO 4. The wrong one won't work.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Can I embed font in ODF document?

Post by musikai »

Can somebody be more specific about LO's feature to embed a font?
The Hybrid PDF version clearly embeds fonts and the.odt into the PDF, but is there really a way to embed (and read) the fonts into an .odt? And how?
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

Zizi64 wrote:
Could you upload a tiny example hybrid .odt file with its PDF embedded as created by LO - I would like to see what AOO thinks of it.
Of course:
Zizi64
 Edit: Edited so as not to confuse searchers. I am confused - see next post correcting things. 
I am confused. You will probably respond that is the normal state of affairs for me ;) but I don't think that Hybrid PDF.odt file has the PDF embedded in it. I cannot see the PDF by unzipping the .odt. Hybrid PDF.PDF is 104 kB but Hybrid PDF.odt is only 42 kB. When I open Hybrid PDF.odt with AOO and save it, I would expect the file size to decrease because the PDF would not be included ... but the file size actually increases slightly, presumably because of some differences between AOO and LO.

Can you please check if Hybrid PDF.odt does actually contain an embedded PDF file.
Last edited by John_Ha on Thu Feb 16, 2017 1:39 am, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

John_Ha wrote:I am confused. You will probably respond that is the normal state of affairs for me ;) but I don't think that Hybrid PDF.odt file has the PDF embedded in it ...
Ah! you would have been correct :oops: I see the .odt is embedded in the PDF file and not the PDF is embedded in the .odt.

File > Properties ..., in the PDF makes no mention of the embedded .odt file. Two questions.

1 Can I get a copy of the .odt file out of the PDF so I can edit it?

2 Can I open the PDF with LO, and LO actually ignores the PDF file and opens the .odt file?

LO manual says
General section

Hybid PDF (embed ODF file): Use this setting to export the document as a PDF file containing two file formats: PDF and ODF. In PDF viewers it behaves like a normal PDF file, and it remains fully editable in LibreOffice.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

musikai wrote:Can somebody be more specific about LO's feature to embed a font?
There is no mention of embedding fonts in the LO manual. As it has been reported that it is possible, it could be that the .odt standard supports doing it, but no application (yet?) implements it.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Can I embed font in ODF document?

Post by musikai »

About the Hybrid PDF:
When you open a Hybrid PDF file in LO it will open the embedded .odt in Writer.
A PDFviewer only seess the PDF and can't open or extract the odt.

There is no such thing as a Hybrid odt with an embedded PDF.
Last edited by musikai on Thu Feb 16, 2017 1:34 am, edited 1 time in total.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

I have been poking around the PDF file.

PDF files have many numbered sections and the 13th section inside this PDF file has the usual " PK " markers suggesting it is the unnamed .odt file. I deleted everything preceding those lines struck out in red below, which I also deleted. I then deleted everything after this section and saved what was left as as fred.odt. It opened normally in AOO as a .odt file.
Attachments
Clipboard02.png
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Can I embed font in ODF document?

Post by musikai »

Oh, cool! You have to have good knowledge about the interious of PDFs! So for a pro it is possible to extract an .odt for use in OO.
John_Ha wrote:
musikai wrote:Can somebody be more specific about LO's feature to embed a font?
There is no mention of embedding fonts in the LO manual. As it has been reported that it is possible, it could be that the .odt standard supports doing it, but no application (yet?) implements it.
I just saw that there is indeed an option to include fonts into an .odt in LO.
viewtopic.php?f=6&t=83321

And it works! When looking into an unzipped odt there is folder called "fonts" with lots of .ttf. Unclear if LO can use them directly when opening the odt. Perhaps they are just packed and must be manually installed on the system if the user needs them.
Edit: Indeed, this option is for portability and LO will use them directly on the target computer:
https://help.libreoffice.org/Common/Embedding_Fonts
They are named font1.ttf, font2.ttf and so on. Will look what their internal names are. Edit: Yes, they seem to be complete correct fonts with correct internal names like "OpusStd", "Arial", etc.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
User avatar
MrProgrammer
Moderator
Posts: 5309
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Can I embed font in ODF document?

Post by MrProgrammer »

John_Ha wrote:I deleted everything preceding those lines struck out in red below, which I also deleted. I then deleted everything after this section and saved what was left as as fred.odt. It opened normally in AOO as a .odt file.
I used this Perl program to extract the embedded ODT file from the PDF. The program does not attempt to understand the format of a PDF beyond what is needed to perform the extract, so it may not work in all cases. But I ran the program with Hybrid PDF.pdf as the input file and the resulting Hybrid.odt opened with Open Office and appeared to match the corresponding ODT file from that post.

#!/usr/bin/env perl
# Extract ODT file from hybrid PDF
# Usage: perl {ThisProgram} <Hybrid.pdf >Hybrid.odt                # Must use < and >
use strict; use warnings;

my $found = 0; my @stream = ();                                    # Initialize variables
my $mimetype = 'mimetypeapplication/vnd.oasis.opendocument';       # Open Document identifier
while (<>) {                                                       # Read lines from STDIN
   my $endstream = 'endstream' eq substr $_,0,9;                   # End-of-stream line?
   push @stream,$_ if ('stream' eq substr $_,0,6) .. $endstream;   # Push from stream to endstream
   $found = 1 if -1 != index $_,$mimetype;                         # Look for Open Document stream
   if ($endstream) {                                               # At end of stream
      if ($found) {                                                # Did stream contain identifier?
         pop @stream; shift @stream;                               # Remove stream boundaries
         foreach (@stream) { print; }                              # Yes, write to STDOUT
         last;                                                     # Exit WHILE loop (and program)
      }                                                            # End of $found block
      $found = 0; @stream = ();                                    # Clear array for next stream
   }                                                               # End of $endstream block
}                                                                  # End of WHILE loop
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
John_Ha
Volunteer
Posts: 9600
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Can I embed font in ODF document?

Post by John_Ha »

MrProgrammer wrote:I used this Perl program
I see why your forum name is MrProgrammer!
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Can I embed font in ODF document?

Post by musikai »

MrProgrammer wrote:I used this Perl program to extract the embedded ODT file from the PDF.
Do you know if this is also possible in Basic? I once tried to read and write streams from a PDF and it didn't work.
I suppose it was because I was using TextInputStream (I wanted to replace certain text) and the non-text-streams got truncated.
The way with something like

Code: Select all

oExp = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
ofw = oExp.openFileWrite(oURL)
n = oFlux.readBytes(mData(), 50000)
ofw.writeBytes(mData())
could perhaps work but I don't know how to replace text.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Locked