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 fc2be80647bd187b4a71b5add30f48b2c1ab8e41
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Oct 27 19:45:06 2025 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Oct 31 08:35:28 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/+/193054
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

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 7817c962e9a0..a6b0aab22971 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -1295,6 +1295,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 14bd593d54d7..834aafa54b48 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