Page 1 of 1
[Solved] Can I embed font in ODF document?
Posted: Fri Feb 10, 2017 1:00 am
by dninich
Can I embed font in ODF document?
If Yes: How?
Else: Why not?
Re: Can I embed font in ODF document?
Posted: Fri Feb 10, 2017 4:02 am
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.
Re: Can I embed font in ODF document?
Posted: Fri Feb 10, 2017 8:17 am
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 2:28 am
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. 
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 8:57 am
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 3:30 pm
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 3:33 pm
by RoryOF
Here it is, acknak, as an extension
TestFonts
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 3:36 pm
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 6:51 pm
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!
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 6:59 pm
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 7:38 pm
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 8:20 pm
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:
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 9:44 pm
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...
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 9:57 pm
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.
Re: Can I embed font in ODF document?
Posted: Wed Feb 15, 2017 10:00 pm
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 12:06 am
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?
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 12:52 am
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 12:59 am
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

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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 1:16 am
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 1:24 am
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 1:31 am
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 1:44 am
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.
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 4:06 am
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
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 11:52 am
by John_Ha
MrProgrammer wrote:I used this Perl program
I see why your forum name is MrProgrammer!
Re: Can I embed font in ODF document?
Posted: Thu Feb 16, 2017 1:40 pm
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.