sd/qa/unit/data/pdf/SampleSlideDeck.pdf |binary
 sd/qa/unit/export-tests.cxx             |   22 ++++++++++++++++++++++
 sd/source/filter/pdf/sdpdffilter.cxx    |   17 +++++++++++++++++
 3 files changed, 39 insertions(+)

New commits:
commit c49baf8274bfa5ac94bdbc4afae3b4cb416b37ae
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Oct 27 19:45:06 2025 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Tue Oct 28 11:56:55 2025 +0100

    align master page size with imported pdf individual pages
    
    for the simple case that all pages are the same at least, so
    export to [f]odg and reload will result in the same size pages
    
    Change-Id: I3d7207dda0dc16afd0fd2eef07cd228a44d90466
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193080
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/sd/qa/unit/data/pdf/SampleSlideDeck.pdf 
b/sd/qa/unit/data/pdf/SampleSlideDeck.pdf
new file mode 100644
index 000000000000..755186f64a8d
Binary files /dev/null and b/sd/qa/unit/data/pdf/SampleSlideDeck.pdf differ
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index b90b911529db..1fc61f3b9f29 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -1277,6 +1277,28 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, 
testExplodedPdfPatternFill)
                          "@draw:fill-image-name='Bitmap_20_1']");
 }
 
+CPPUNIT_TEST_FIXTURE(SdExportTest, testPdfPageMasterOrientation)
+{
+    auto pPdfium = vcl::pdf::PDFiumLibrary::get();
+    if (!pPdfium)
+        return;
+    UsePdfium aGuard;
+
+    loadFromFile(u"pdf/SampleSlideDeck.pdf");
+
+    
setFilterOptions("{\"DecomposePDF\":{\"type\":\"boolean\",\"value\":\"true\"}}");
+    save(u"OpenDocument Drawing Flat XML"_ustr);
+
+    xmlDocUniquePtr pXmlDoc = parseExportedFile();
+
+    // Ensure the page size is landscape. Before fix the master pagesize was
+    // portrait Letter so on reimport of the [f]odg the master page size is
+    // what is applied to the reloaded pages and was obviously wrong on reload.
+    assertXPath(pXmlDoc,
+                
"/office:document/office:automatic-styles/style:page-layout[@style:name='PM0']/"
+                
"style:page-layout-properties[@style:print-orientation='landscape']");
+}
+
 CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfTextShear)
 {
     auto pPdfium = vcl::pdf::PDFiumLibrary::get();
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx 
b/sd/source/filter/pdf/sdpdffilter.cxx
index 5befb7c3f2e3..e8540104e021 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -83,6 +83,9 @@ static bool ImportPDF(SvStream& rStream, SdDrawDocument& 
rDocument)
         nPageToDuplicate = rDocument.DuplicatePage(nPageToDuplicate);
     }
 
+    bool bAllPagesSameSize(false);
+    Size aMasterSizeHMM;
+
     for (vcl::PDFGraphicResult const& rPDFGraphicResult : aGraphics)
     {
         const Graphic& rGraphic = rPDFGraphicResult.GetGraphic();
@@ -98,6 +101,13 @@ static bool ImportPDF(SvStream& rStream, SdDrawDocument& 
rDocument)
 
         // Make the page size match the rendered image.
         pPage->SetSize(aSizeHMM);
+        if (nPageNumber == 0)
+        {
+            aMasterSizeHMM = aSizeHMM;
+            bAllPagesSameSize = true;
+        }
+        else
+            bAllPagesSameSize &= aMasterSizeHMM == aSizeHMM;
 
         rtl::Reference<SdrGrafObj> pSdrGrafObj
             = new SdrGrafObj(rModel, rGraphic, tools::Rectangle(Point(), 
aSizeHMM));
@@ -240,6 +250,13 @@ static bool ImportPDF(SvStream& rStream, SdDrawDocument& 
rDocument)
         }
         pPage->setLinkAnnotations(rPDFGraphicResult.GetLinksInfo());
     }
+
+    if (SdPage* pPage = bAllPagesSameSize ? rDocument.GetSdPage(0, 
PageKind::Standard) : nullptr)
+    {
+        SdPage& rMasterPage = static_cast<SdPage&>(pPage->TRG_GetMasterPage());
+        rMasterPage.SetSize(aMasterSizeHMM);
+    }
+
     rDocument.setLock(bWasLocked);
     rDocument.EnableUndo(bSavedUndoEnabled);
     return true;

Reply via email to