Bug 165917 - PDF exports to most recent directory, not to current directory
Summary: PDF exports to most recent directory, not to current directory
Status: REOPENED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
24.8.6.2 release
Hardware: All All
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: bibisected, bisected, regression
: 165967 (view as bug list)
Depends on:
Blocks: PDF-Export
  Show dependency treegraph
 
Reported: 2025-03-26 13:46 UTC by Frank Reibold
Modified: 2025-04-01 19:20 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
video testing the bug (22.99 MB, video/webm)
2025-03-30 19:02 UTC, BogdanB
Details
the only change on many machines (141.91 KB, image/png)
2025-03-31 13:00 UTC, Torsten Levenhagen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Reibold 2025-03-26 13:46:17 UTC
Description:
PDFs are exported to the most recently directory and not to the document's directory.

Correct in 25.2.1.2
Wrong in 25.2.2.1

Steps to Reproduce:
1.Click the "export to PDF" toolbar icon



Actual Results:
The most recently used directory opens

Expected Results:
The document's directory opens


Reproducible: Always


User Profile Reset: No

Additional Info:
I reverted to LO 25.2.1.2 from 25.2.2.1 and the behaviour is correct again.
Comment 1 m_a_riosv 2025-03-26 21:34:25 UTC
I can't reproduce.

Please detail step by step how the issue is reached.

Please test in safe mode, Menu/Help/Restart in Safe Mode
Comment 2 BogdanB 2025-03-27 03:24:47 UTC
I am also affected at work on Windows. Pressing PDF icon would generate a copy of the document in PDF in the current folder. Now it's anywhere but not the document folder.
Comment 3 BogdanB 2025-03-27 04:58:43 UTC
On my linux is still ok
Version: 25.2.1.1 (X86_64) / LibreOffice Community
Build ID: e538fb6403facdfd3db0250c3b3278236c675c2a
CPU threads: 16; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

But I noticed the problem at work, on Windows. I often generate some reports in a certain folder. I open documents, edit, export the PDF (usually the PDF being generated in the same folder), then I send all the PDF from the active folder to clients. Now I have to choose each time the correct folder for the exported PDF.
Comment 4 BogdanB 2025-03-27 04:59:24 UTC
I would bibisect this, but it is Windows only. I can't.
Comment 5 BogdanB 2025-03-27 06:47:49 UTC
I came back to 24.8 on Windows but I have the same problem. Could be a Windows update that broke that option?

Version: 24.8.6.1 (X86_64) / LibreOffice Community
Build ID: 051bf11303684a0a982c9966e8be766d0a9efbc7
CPU threads: 4; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win
Locale: ro-RO (en_US); UI: en-US
Calc: threaded
Comment 6 Frank Reibold 2025-03-28 09:52:02 UTC
LibreOffice 25.2.2.2 Writer on Windows 10 hast the same problems.
Comment 7 BogdanB 2025-03-28 09:55:02 UTC
Confirm with
Version: 24.8.6.2 (X86_64) / LibreOffice Community
Build ID: 6d98ba145e9a8a39fc57bcc76981d1fb1316c60c
CPU threads: 4; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win
Locale: ro-RO (en_US); UI: en-US
Calc: threaded

But could be a Windows bug, not a LibreOffice one. 
Should be investigated.
Comment 8 Frank Reibold 2025-03-28 10:03:29 UTC
OpenOffice 4.1.15 on Windows 10 works as expected.
Comment 9 Frank Reibold 2025-03-28 10:20:43 UTC
LibreOffice 24.2.7.2 on Windows 10 works as expected :-)

Maybe someone changed the Windows version of the code which constructs the path of the current document? That wouldn't cause problems on Linux.


Version: 24.2.7.2 (X86_64) / LibreOffice Community
Build ID: ee3885777aa7032db5a9b65deec9457448a91162
CPU threads: 4; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: threaded
Comment 10 BogdanB 2025-03-28 10:31:16 UTC
I was using 25.2 last month and was ok. This is the reason I suspect Windows to be the cause. Now I moved back to 24.8, but useles, it is the same. I prefer now the stable (still) version of LibreOffice.
Comment 11 henrik.ericson 2025-03-28 17:12:02 UTC
At work: Windows 11, LibreOffice 25.2.2.2, PDF exports to recent folder (unwanted behavior)
At home: Windows 11, LibreOffice 25.2.1.2, PDF exports to document folder (wanted behavior)
Comment 12 BogdanB 2025-03-28 17:28:54 UTC
(In reply to henrik.ericson from comment #11)
> At work: Windows 11, LibreOffice 25.2.2.2, PDF exports to recent folder
> (unwanted behavior)
> At home: Windows 11, LibreOffice 25.2.1.2, PDF exports to document folder
> (wanted behavior)

In 25.2.2.2 version from work, please go to Help - About and copy info from there. Should be a link with all the changes for 25.2.2.2.
Comment 13 m_a_riosv 2025-03-29 23:33:03 UTC
*** Bug 165967 has been marked as a duplicate of this bug. ***
Comment 14 Saburo 2025-03-30 02:27:50 UTC
bisected with linux-64-25.2

commit 67cffdf1b2872b4bcac657f7bcf63f19c261a5c6
author	Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>	Thu Feb 13 09:55:04 2025 +0100

tdf#165228 Don't reuse previous path in save dialog
Comment 15 BogdanB 2025-03-30 05:17:04 UTC
Samuel, please take a look at this bug.

My current workflow is this: I open a folder with some documents, I edit, save and export as PDF, then try to export the PDF to clients. I expect as before that a document will be created in the folder I am in at the moment. In fact, the PDF will go to the most recent folder where I have something else, not related with what I am doing. So I have to change the folder in order to export the PDF. 

Then, I change the current working folder, and edit another file, and repeat all the steps, and again I have to change the folder where the exported PDF will go.
Comment 16 BogdanB 2025-03-30 05:38:00 UTC
More, many apps (WhatsApp, email) allows you to drag and drop documents from current folder. But I do not have what I need in the current folder, if I am in a hurry and did not read where the PDF was exported, I will send an old version of the PDF, if there was one.
Comment 17 BogdanB 2025-03-30 19:02:51 UTC
Created attachment 200094 [details]
video testing the bug

I have created a video with both behaviors. In the first minute is the old behavior, is very easy, you get the folder where you work.

In the last minute, you can see I have to change each time the folder I need to export.
Comment 18 Samuel Mehrbrodt (allotropia) 2025-03-31 05:32:47 UTC
So this works as designed.
If there a are other workflows where the current implementation is not ideal, there are two possibilities:

1. Create a macro which does exactly what you want it to do, and replace the current Save/Export/... action with your macro
2. File an enhancement request with a specific proposal what should be changed

In any case, this is not a bug and not a regression.
Comment 19 BogdanB 2025-03-31 10:47:26 UTC
This is the macro exporting a PDF in the current folder:
Sub ExportToPDF()
    Dim oDoc As Object
    Dim sURL As String
    Dim sFilePath As String
    Dim sPDFPath As String
    
    oDoc = ThisComponent
    If oDoc.hasLocation Then
        ' Get the document's directory
        sURL = oDoc.getURL()
        sFilePath = ConvertFromURL(sURL)
        If sFilePath = "" Then
            MsgBox "Error: Could not determine file path.", 48, "Error"
            Exit Sub
        End If
        
        sFilePath = Left(sFilePath, Len(sFilePath) - Len(GetFileName(sFilePath)))
        
        ' Define PDF file path
        sPDFPath = sFilePath & GetFileNameWithoutExtension(sURL) & ".pdf"
        
        ' Export to PDF
        Dim aProps(1) As New com.sun.star.beans.PropertyValue
        aProps(0).Name = "FilterName"
        aProps(0).Value = "writer_pdf_Export"
        
        oDoc.storeToURL(ConvertToURL(sPDFPath), aProps())
        MsgBox "Document exported to: " & sPDFPath, 64, "Export Successful"
    Else
        MsgBox "Please save the document before exporting.", 48, "Error"
    End If
End Sub

Function GetFileName(sFilePath As String) As String
    If sFilePath = "" Then Exit Function
    Dim sName As String
    Dim i As Integer
    i = LastIndexOf(sFilePath, "\")
    If i = 0 Then i = LastIndexOf(sFilePath, "/") ' Handle UNIX-style paths
    If i > 0 Then
        sName = Mid(sFilePath, i + 1)
    Else
        sName = sFilePath
    End If
    GetFileName = sName
End Function

Function GetFileNameWithoutExtension(sFilePath As String) As String
    Dim sName As String
    sName = GetFileName(sFilePath)
    If sName = "" Then Exit Function
    Dim i As Integer
    i = LastIndexOf(sName, ".")
    If i > 0 Then
        sName = Left(sName, i - 1)
    End If
    GetFileNameWithoutExtension = sName
End Function

Function ConvertFromURL(sURL As String) As String
    If sURL = "" Then Exit Function
    ConvertFromURL = Replace(sURL, "file://", "")
    ConvertFromURL = Replace(ConvertFromURL, "/", "\") ' Ensure Windows-style path
End Function

Function ConvertToURL(sFilePath As String) As String
    If sFilePath = "" Then Exit Function
    ConvertToURL = "file://" & Replace(sFilePath, "\", "/") ' Ensure URL-style path
End Function

Function LastIndexOf(text As String, character As String) As Integer
    Dim i As Integer
    For i = Len(text) To 1 Step -1
        If Mid(text, i, 1) = character Then
            LastIndexOf = i
            Exit Function
        End If
    Next i
    LastIndexOf = 0
End Function
Comment 20 Torsten Levenhagen 2025-03-31 13:00:46 UTC
Created attachment 200101 [details]
the only change on many machines
Comment 21 Torsten Levenhagen 2025-03-31 13:34:41 UTC
(In reply to Samuel Mehrbrodt (allotropia) from comment #18)
> So this works as designed.
...
> In any case, this is not a bug and not a regression.

Sorry, that's wrong.

I've tested several different machines (see below) with CALC.

Until Friday, the behavior on all machines was:
Export PDF to the same directory as the CALC file.

Then, three Windows devices received an update from 25.2.1.2 to 25.2.2.2 via winget-autoupdate (see uploaded image). This was the only change - no Windows updates, no settings changed, no user change!

Since then, the behavior on these three machines (2x Win 11, 1x Win 10) has been:
Export PDF to the last directory used for export.

Please check again if there has been a code change where org.openoffice.Common:LastDirectory['ClacSaveAs'] and ['CalcExport'] may have been swapped.

Or explain to me why the standard behavior you claim did NOT work from version 7.4.7.2 to 25.2.1.2 and nobody has reported this alleged misbehavior so far - but several people are now reporting it because the previous behavior has changed.

=============

OLD BEHAVIOR:

Version: 7.4.7.2 / LibreOffice Community
Build ID: 40(Build:2)
CPU threads: 4; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Ubuntu package version: 1:7.4.7-0ubuntu0.22.10.1~bpo20.04.1
Calc: threaded

Version: 25.2.1.2 (X86_64) / LibreOffice Community
Build ID: d3abf4aee5fd705e4a92bba33a32f40bc4e56f49
CPU threads: 8; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Vulkan; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: CL threaded


NEW BEHAVIOR:

Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac
CPU threads: 12; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: threaded

Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac
CPU threads: 16; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Vulkan; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: CL threaded
Comment 22 Eduardo 2025-04-01 19:20:32 UTC
This is not a Windows only bug, I experience this in Linux as well (Manjaro, if that matters).
This is very annoying, especially since this worked (export to directory where original file resides) for *many many* years, I consider this as a feature not a bug.
I would suggest, if I can ofc, to revert that commit and create an enhancement request like "Always force save-as/export dialog to use default directories" or smth along those lines.

---------------------------------
Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 520(Build:2)
CPU threads: 8; OS: Linux 6.13; UI render: Skia/Raster; VCL: kf6 (cairo+xcb)
Locale: en-US (en_US.UTF-8); UI: en-US
25.2.2-1
Calc: threaded
---------------------------------