tdf#167659 Allow hiding tracked changes in PDF export from command line
PDFs exported from Writer show/don't show tracked changes
based on what's set on the UI.
During command line conversion, there was no way to change
this setting.
Introduce a new option 'ExportTrackedChanges' to be only used
during command line conversion as a --convert-to parameter, eg.:
'pdf:writer_pdf_Export:{"ExportTrackedChanges":
{"type":"boolean","value":"false"}}'
Change-Id: I763393ee4305415b714662decf23e0e8f8e75662
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188194
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
@@ -68,6 +68,7 @@
|
||||
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <rtl/bootstrap.hxx>
|
||||
#include <config_features.h>
|
||||
@@ -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<bool> 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<beans::XPropertySet> 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<XPropertySet>(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&)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Binary file not shown.
@@ -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<beans::PropertyValue> 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<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
|
||||
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0);
|
||||
CPPUNIT_ASSERT(pPdfPage);
|
||||
std::unique_ptr<vcl::pdf::PDFiumTextPage> pPdfTextPage = pPdfPage->getTextPage();
|
||||
CPPUNIT_ASSERT(pPdfTextPage);
|
||||
|
||||
const int nChars = pPdfTextPage->countChars();
|
||||
std::vector<sal_uInt32> 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();
|
||||
|
||||
Reference in New Issue
Block a user