diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx index 8b50dc1bbe45..4f7d9f740563 100644 --- a/filter/source/pdf/pdfexport.cxx +++ b/filter/source/pdf/pdfexport.cxx @@ -68,6 +68,7 @@ #include #include +#include #include #include @@ -406,6 +407,7 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& bool bUseTaggedPDF = false; sal_Int32 nPDFTypeSelection = 0; bool bPDFUACompliance = false; + std::optional bExportTrackedChanges; bool bExportNotes = true; bool bExportNotesInMargin = false; bool bExportNotesPages = false; @@ -561,6 +563,12 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& rProp.Value >>= nPDFTypeSelection; else if ( rProp.Name == "PDFUACompliance" ) rProp.Value >>= bPDFUACompliance; + else if (rProp.Name == "ExportTrackedChanges") + { + bool bExportTrackedChangesProp = false; + if (rProp.Value >>= bExportTrackedChangesProp) + bExportTrackedChanges = bExportTrackedChangesProp; + } else if ( rProp.Name == "ExportNotes" ) rProp.Value >>= bExportNotes; else if ( rProp.Name == "ExportNotesInMargin" ) @@ -1094,6 +1102,11 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& bool bReHideWhitespace = false; static constexpr OUString sHideWhitespace(u"HideWhitespace"_ustr); uno::Reference< beans::XPropertySet > xViewProperties; + uno::Reference xPropSet; + // property only exists and handled in SwXTextView for the purpose of + // exporting showing tracked changes to PDF from command line + static constexpr OUString sShowChangesPDF(u"PDFExport_ShowChanges"_ustr); + bool bToggleChangesPDF = false; if ( aCreator == "Writer" ) { @@ -1114,6 +1127,20 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& { xViewProperties->setPropertyValue(sHideWhitespace, uno::Any(false)); } + + if (bExportTrackedChanges.has_value()) + { + xPropSet = uno::Reference(xModel->getCurrentController(), + uno::UNO_QUERY_THROW); + bool bShowChangesPDF = false; + xPropSet->getPropertyValue(sShowChangesPDF) >>= bShowChangesPDF; + if (bShowChangesPDF != bExportTrackedChanges) + { + xPropSet->setPropertyValue(sShowChangesPDF, + Any(bExportTrackedChanges.value())); + bToggleChangesPDF = true; + } + } } catch( const uno::Exception& ) { @@ -1192,6 +1219,16 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& { } } + if (bToggleChangesPDF) + { + try + { + xPropSet->setPropertyValue(sShowChangesPDF, Any(!bExportTrackedChanges.value())); + } + catch (const uno::Exception&) + { + } + } } } } diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index 894da6ed74a9..ee6211e447ca 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -671,6 +671,20 @@ void SAL_CALL SwXTextView::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue ) { SolarMutexGuard aGuard; + + if (rPropertyName == "PDFExport_ShowChanges") + { + // hack used in PDF export code to turn off (or on) exporting showing tracked changes + // logic is simplified from FN_REDLINE_SHOW path in SwView + bool bShow = false; + rValue >>= bShow; + SwWrtShell& rSh = m_pView->GetWrtShell(); + rSh.StartAllAction(); + rSh.GetLayout()->SetHideRedlines(!bShow); + rSh.EndAllAction(); + return; + } + const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); if (!pEntry) throw UnknownPropertyException(rPropertyName); @@ -708,6 +722,13 @@ uno::Any SAL_CALL SwXTextView::getPropertyValue( Any aRet; + if (rPropertyName == "PDFExport_ShowChanges") + { + const bool bShow = !m_pView->GetWrtShell().GetLayout()->IsHideRedlines(); + aRet <<= bShow; + return aRet; + } + const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); if (!pEntry) throw UnknownPropertyException(rPropertyName); diff --git a/vcl/qa/cppunit/pdfexport/data/tdf167659.odt b/vcl/qa/cppunit/pdfexport/data/tdf167659.odt new file mode 100644 index 000000000000..1337275095fa Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf167659.odt differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 5024de86b201..b2723fc174c7 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -3627,6 +3627,30 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115967) CPPUNIT_ASSERT_EQUAL(u"m=750abc"_ustr, sText); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf167659) +{ + // Don't export showing tracked changes to PDF + uno::Sequence aFilterData( + comphelper::InitPropertySequence({ { "ExportTrackedChanges", uno::Any(false) } })); + aMediaDescriptor[u"FilterData"_ustr] <<= aFilterData; + saveAsPDF(u"tdf167659.odt"); + + // Parse the export result with pdfium. + std::unique_ptr pPdfDocument = parsePDFExport(); + std::unique_ptr pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + std::unique_ptr pPdfTextPage = pPdfPage->getTextPage(); + CPPUNIT_ASSERT(pPdfTextPage); + + const int nChars = pPdfTextPage->countChars(); + std::vector aChars(nChars); + for (int i = 0; i < nChars; i++) + aChars[i] = pPdfTextPage->getUnicode(i); + OUString aActualText(aChars.data(), aChars.size()); + // Without the change, this also includes tracked deleted text from the document + CPPUNIT_ASSERT_EQUAL(u"normal text"_ustr, aActualText); +} + } // end anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT();