Bug 144488 - Master documents: Hyperlink from one subdocument to another should be simplified to be internal when exported to ODT or PDF
Summary: Master documents: Hyperlink from one subdocument to another should be simplif...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Printing and PDF export (show other bugs)
Version:
(earliest affected)
7.1.6.2 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL: https://ask.libreoffice.org/t/cross-r...
Whiteboard:
Keywords:
Depends on:
Blocks: Hyperlink Writer-Master-Doc
  Show dependency treegraph
 
Reported: 2021-09-14 11:22 UTC by harald.braun.p
Modified: 2024-03-21 03:36 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
test kit: two ODT subdocs, one ODM master (37.27 KB, application/zip)
2024-03-21 03:31 UTC, Stéphane Guillou (stragu)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description harald.braun.p 2021-09-14 11:22:26 UTC
Writer: Master document with partial documents - export functions do not adapt hyperlinks to fragments in partial documents

The following export functions are affected:
- Master document for .odt file
- Master document to .pdf file

LibreOffice Community version: 7.1.6.2
Operating system: Ubuntu 20.04.1

I have created a master document with several sub-documents.
In the part-documents there are hyperlinks to fragments of another part-documents.
These hyperlinks are not adapted when exporting to an .odt file or a .pdf file.

A hyperlink xlink: href = "../ Teildokument2.odt#Heading" remains that way, but should be in
xlink: href = "#Heading" can be changed (xlink: type = "simple").

Hyperlinks that point to destinations outside of the global and partial documents of the global document must be retained.

Translated with Google Translate from German
Comment 1 Dieter 2021-09-29 14:24:24 UTC
Harald, thank you for reporting the bug. Please attach a sample document (masterdocument with some subdocuments), as this makes it easier for us to verify the bug. 
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it)

I'm not sure, if I understand everything in your report (for example what do you mean with "Fragment"). Sometimes deepl.com is a better choice for translation. It's also no problem - as far as I know - to write a report in German and add the translated version in English.
Comment 2 harald.braun.p 2021-09-30 10:12:40 UTC
Hello Dieter,

first to your question about the "fragment".

Here I refer you to the RFC 3986 for the structure of a URI, heading "3. Syntax Components".

Since I was not able to upload the documents as attachment I sent them to your mail address.
There you will find a zip file containing a simple global document with its sub-documents, where in the sub-document "About this Guide" with the chapter "About this Guide" simply hyperlinks to the sub-documents "Introduction" and "Login to the Switch".

The content.xml of the global document contains the following references:

xlink:type="simple" xlink:href="../About_this_Guide.odt#1.About%20This%20Guide%7Coutline"

xlink:type="simple" xlink:href="../Introduction.odt#1.Introduction%7Coutline"

xlink:type="simple" xlink:href="../Login_to_the_Switch.odt#1.Login%20to%20the%20Switch%7Coutline"

When I export this from the global document to a PDF file the following links are in the PDF file:

file:///home/haraldbraun/Dokumente/fehlersuche/-About_this_Guide.odt#1.About%20This%20Guide%7Coutline

file:///home/haraldbraun/Dokumente/fehlersuche/-Introduction.odt#1.Introduction%7Coutline

file:///home/haraldbraun/Dokumente/fehlersuche/-Login_to_the_Switch.odt#1.Login%20to%20the%20Switch%7Coutline


For me file:///home/haraldbraun/Dokumente/fehlersuche/ is the directory in which 

a) the global document
b) the partial documents and
c) the exported PDF file.

Clicking on the hyperlink in the PDF file does not lead to the target.

If I now create an .odt file from the global document using the export function, then unpack the .odt file and change the "content.xml" of this .odt file so that the references look like this:

xlink:type="simple" xlink:href="#About%20This%20Guide%7Coutline"

xlink:type="simple" xlink:href="#Introduction%7Coutline"

xlink:type="simple" xlink:href="#Login%20to%20the%20Switch%7Coutline"

save the "content.xml" and then create an .odt file again from the archive files (zipping) I have created the prerequisites for a working PDF file.

From this .odt file I then export the PDF file again. And lo and behold, the hyperlinks work just fine.

Many greetings
Harald

Translated with www.DeepL.com/Translator (free version)
Comment 3 harald.braun.p 2021-09-30 10:21:15 UTC
Hello Dieter,

sorry the new references looks like this:

xlink:type="simple" xlink:href="#1.About%20This%20Guide%7Coutline"

xlink:type="simple" xlink:href="#1.Introduction%7Coutline"

xlink:type="simple" xlink:href="#1.Login%20to%20the%20Switch%7Coutline"
Comment 4 Dieter 2021-11-13 08:20:35 UTC Comment hidden (off-topic)
Comment 5 harald.braun.p 2021-11-13 15:07:27 UTC
Hello Dieter,

thank you very much for your comment 4.

Try 1:
==========

I have completed and tested your steps for reproduction a little bit:

1. Open a new document and write some words (including the word "document2").
2. Saving this 1st document under any name.
3. Open another new document and create the heading "Document2". Formatted with heading1.
4. Save this 2nd document under any name.
5. Open the 1st document; mark the word "Document2"; Insert -> Hyperlink -> Select document (2nd document) -> Select target (heading "Document2") -> O.K.
6. Export as PDF (in doing so, under the "PDF Options" on the "Links" tab, the option "Convert document links to PDF targets" was NOT checked.
7. save the PDF file.
8. open PDF file and click on link.

Result: 
The link does not work! NO error message

If you move the mouse cursor over the hyperlink in the generated PDF file you can see the following: "file://<path>/Document1.odf#Document2%7Coutline" (<path> is the placeholder for my local directory path).


Try 2:
==========

Now I repeated step 5. and in step 6. under "PDF Options" on the "Links" tab I checked the option "Convert document links to PDF targets".
Repeated steps 7. and 8.

Result:
The link does not work! 
The error message appears: "External link could not be opened/ Error fetching information for file >><path>/Document2.pdf<<: file or directory not found" (<path> is the placeholder for my local directory path). The link does not work, that the 2nd document was not converted to a pdf file.

In the "content.xml" of the 1st document the following is stored to the hyperlink: <text:a xlink:type="simple" xlink:href="../Document2.odt#1.Document2%7Coutline" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">Document2</text:a>


Notes on the global document with its sub-documents:
=========================================================

Basically, MANY documents with their links are united into ONE document here when exporting to a PDF file or to an .odt file.

Hyperlinks can be here:

Case 1:

(a) from the global document to one or more sub-documents,
(b) from a sub-document to one or more sub-documents

refer.

Case 2:

In addition, there may be hyperlinks here that point to external files that are not part of the global document and its sub-documents.

In case 1, the hyperlinks must work within the target document when exported and thus be converted to hyperlinks to internal targets of a file.

In case 2, the hyperlinks must be designed to open the original files separately from the PDF or .odt file (if the link is available).

I hope I could help you with this.

Translated with www.DeepL.com/Translator (free version)
Comment 6 Dieter 2021-11-14 05:55:02 UTC
Harald thanks for that retest. So I change status to NEW.
Comment 7 Timur 2022-01-11 09:50:09 UTC
It's much easier to test if there are minimal sample documents created and attached here.
Comment 8 Timur 2022-01-11 09:54:03 UTC
Is this the same as bug 142707?
Comment 9 harald.braun.p 2022-01-15 15:53:16 UTC
(In reply to Timur from comment #8)
> Is this the same as bug 142707?

Hello Timur,

I think bug 142707 this is a additional problem.

Here is my current workaround to solve my problem:

It is possible to export a PDF file from a global document (.odm file). However, the hyperlinks that link certain topics with partial documents of the global document are not adapted. In the PDF file then
a) the targets are not found, or
b) if the document parts are accessible, they are accessed.
If such a PDF file is sent or transferred to another computer, case a) is always active.

This is not desirable.

For this reason, the basic procedure is as follows. 1:

1. update all directories and links in the global document (.odm file). Attention: This currently takes between 2.5 and 4 hours. 2.
2. save the global document
3. create a normal Writer document from the global document (.odt file; File -> Export)
4. deactivate links and write protection in .odt file; remove links
5. save .odt file
6. change relevant hyperlinks in .odt file
Save .odt file. 7.
Export a PDF file from an .odt file.


Create .odt file from .odm file.
========================================

1. open .odm file
Answer Yes to the question whether all links should be updated. 3.
3. when the links are updated: save the .odm file
4. then File -> Export and create .odt file
5. close .odm file
6. open .odt file
7. answer with No to the question whether all links should be updated.
8. go to Format -> Areas... Go to Format -> Areas...
9. range: mark all ranges (mark 1st range; go down and mark last range with Shift+Click.
10. shortcut: deactivate shortcuts
11. write protection: deactivate protection
12. click the OK button
13. save .odt file
14. go to Format -> Areas... Go to Format -> Areas... 15.
15. range: Mark all ranges (mark 1st range; go down and mark last range with Shift+Click.
Click on the "Remove" button. 17.
Close the window with the OK button.
18. Save the .odt file.

Adapt hyperlinks in .odt file
=================================

Copy the .odt file into an empty temporary directory. 2.
2. change to the temporary directory
3. open .odt file with archive management (.odt file is a zip archive)
4. unpack the .odt file into the temporary directory. Finally, click on "Show file". 5.
Close the archive management. 6.
6. search for the file "content.xml" in the temporary directory and open it with Atom. 7.
7. call Find -> Find in Buffer
8. in Find: (href=")+.{5,90}(\.odt#).
Assumption: File whose hyperlinks are to be adapted has the file name "Gradle_User_Manual.odt". 9.
9. enter: href="# in Replace.
Mark the option "Regular Expression" (.*) and wait until the searched places are marked by Atom. 11.
Search for the first entry with the "Find" button and, if OK, change the marked entry with the "Replace" button. 12.
Click the "Replace" button until all relevant hyperlinks have been changed. 13.
13. Save content.xml in the archive.
14. Close content.xml and Atom. 15.
15. Mark the .odt file. Call up the "Rename..." function. Execute the key combination Ctrl+A. Execute the key combination Ctrl+C. Press the ESC key. 16.
Mark all files except the .odt file. 17.
Call up the "Compress..." function. In the "Archive name" field, execute the key combination Ctrl+V. Then click on "Create". (Files are compressed into a zip archive; file extension .zip). 18.
Delete the "old" .odt file in the temporary directory. 19.
Mark the Zip archive. Call up the "Rename..." function. Remove the .zip file extension. Complete "Rename...". 20.
Mark and delete all files in the temporary directory with the exception of the newly created .odt file.

Export PDF file
=====================

1. open .odt file with the changed hyperlinks
2. go to File -> Export as -> Export as PDF... go to
3. window PDF options
     Tab: General
       Area: Select option "All
       Area: Mark "Show PDF document after export".
       Images:  Mark option "JPEG compression quality" and enter value "90%".
       Images: Mark "Reduce image resolution" and enter value "300DPI".
       General: Mark "(PDF/A, ISO19005)-Archive".
       General: Select "PDF/A version: PDF/A-2b".
       Structure: Select "Export outline".
       Structure: Select "Export automatically inserted blank pages".
     Tab: Initial display
       Areas: Mark option "Outline and page
       Enlargement: Mark option "Standard
       Page layout: Mark option "Standard
     Tab: User interface
       Window options: Mark "Show document title".
       Transitions: Mark "Use transition effects".
       User interface options: Mark no option
       Collapse outline: Mark option "Show all".
     Tab: Shortcuts
       General: Mark "Export outline as named destinations".
       Links between documents: Mark option "Standard behaviour".
     Tab: Security
       Nothing can be marked??
     Tab: Digital signatures
       Nothing can be marked????
Click on the "Export" button. 5.
Specify a file name for the PDF file (e.g. 20210913_Gradle_User_Manual_7.2_002.00.pdf). 6.
Click on the "Save" button.


Translated with www.DeepL.com/Translator (free version)

Translated with www.DeepL.com/Translator (free version)
Comment 10 Stéphane Guillou (stragu) 2023-10-09 09:32:16 UTC Comment hidden (obsolete)
Comment 11 harald.braun.p 2023-10-14 13:39:58 UTC Comment hidden (obsolete)
Comment 12 Stéphane Guillou (stragu) 2023-10-14 22:48:38 UTC
(In reply to harald.braun.p from comment #11)
> Evince: link does not work.
> Foxit reader: link works.
[...]
> Foxit Reader: Link does not work.
> muPDF: Link works.
OK, so at least we can confirm that PDF links not working (as in comment 4) is not our issue but rather missing support in some PDF readers.

(In reply to harald.braun.p from comment #11)
> Note: But this is not my problem. See bug description.
Let's have a look at this ODM to ODT issue then. I know you shared them with Dieter, but can you please attach your sample documents here so others can test? https://bugs.documentfoundation.org/attachment.cgi?bugid=144488&action=enter
Comment 13 Stéphane Guillou (stragu) 2024-03-15 03:00:23 UTC
Changed summary to focus again on master export, but please provide minimal example files to illustrate.

Please also see existing reports on the topic, your issue might already be covered there: https://bugs.documentfoundation.org/buglist.cgi?query_format=advanced&resolution=---&short_desc=master link&short_desc_type=allwordssubstr
Comment 14 harald.braun.p 2024-03-15 08:59:05 UTC
Hello Stèphane,

Unfortunately, for health reasons, I won't have time to create any more sample files in the near future.

In addition, I have already sent the documents available to me several times by e-mail. So there should be enough material available.

I'm sorry that I can't help at the moment.

Best regards
/Harald
Comment 15 Stéphane Guillou (stragu) 2024-03-21 03:19:07 UTC
Thank you Harald, I understand.
Please feel free to unsubscribe to the report.

---

I tested with my own files created from scratch:
- sub-document ODT 1 with two headings
- sub-document ODT 2 with two headings + a hyperlink to one of the headings in sub-document 1

What I see:
* In subdoc 2, the target comes up as "1.Heading 1 of subdoc 1|outline" in the hyperlink dialog.
* Clicking the hyperlink in the Master document opens subdoc 1 in a new window.
* PDF export:
   * link is "subdoc1.odt#1.Heading%201%20of%20subdoc%201%7Coutline"
   * link does not work in Evince / Firefox / Chromium, but it _does_ in Okular, leading to opening subdoc 1 at the correct heading
   * using the option "convert to PDF targets" does not help as it converts the link to "subdoc1.pdf#1.Heading%201%20of%20subdoc%201%7Coutline" (subdoc1.pdf does not exist)
* ODT export:
   * link does work, opens subdoc 1 at the correct heading
* It is possible to insert into the master document a hyperlink to a heading of a subdocument, but that has to be done in a text section of the master, after having included the subdocuments.

My conclusion:
I agree with Harald that hyperlinks to parts of documents should be converted on export to PDF so they can be used to move inside the PDF (instead of opening the source subdocument). Or at least have an option of the kind "Simplify document target links for included files" that would follow the logic "if the link URI points to a file that is included as a subdocument, simplify it so it is internal to the exported file".

Version: 7.6.5.2 (X86_64) / LibreOffice Community
Build ID: 38d5f62f85355c192ef5f1dd47c5c0c0c6d6598b
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded

See also bug 145676.
Comment 16 Stéphane Guillou (stragu) 2024-03-21 03:31:42 UTC
Created attachment 193219 [details]
test kit: two ODT subdocs, one ODM master

Test files as described in previous comment. Created with:

Version: 7.6.5.2 (X86_64) / LibreOffice Community
Build ID: 38d5f62f85355c192ef5f1dd47c5c0c0c6d6598b
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

But exports with recent trunk build has same results:

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 53c5d570cab036b23f4969b858a648c8f0c24f93
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded

See also bug 52444, about having the option to export a "self-contained and self-sufficient" ODT, which this enhancement could be a part of.