summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-01-28 19:28:06 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-02-01 02:11:05 +0000
commit9740331d8bc56a9b6fbe3e4c1b26fb97f6639cc6 (patch)
treedb4b751fbbc55b2cece8e45cfbbd57dee14e9e95 /vcl
parentd8e6b488ceaff7c88856ebcfcfec14d2d8cd7652 (diff)
tdf#66580 write more metadata to embedded and attached files
Change-Id: I6f40fd98b48893d01d29a806877821c561688897 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146288 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/pdf/pdfwriter_impl.hxx3
-rw-r--r--vcl/source/gdi/pdfwriter.cxx4
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx36
3 files changed, 35 insertions, 8 deletions
diff --git a/vcl/inc/pdf/pdfwriter_impl.hxx b/vcl/inc/pdf/pdfwriter_impl.hxx
index 32917315f66c..4e10204433cb 100644
--- a/vcl/inc/pdf/pdfwriter_impl.hxx
+++ b/vcl/inc/pdf/pdfwriter_impl.hxx
@@ -669,6 +669,7 @@ struct PDFDocumentAttachedFile
{
OUString maFilename;
OUString maMimeType;
+ OUString maDescription;
sal_Int32 mnEmbeddedFileObjectId;
sal_Int32 mnObjectId;
};
@@ -1330,7 +1331,7 @@ public:
sal_Int32 createControl( const PDFWriter::AnyWidget& rControl, sal_Int32 nPageNr = -1 );
// attached file
- void addDocumentAttachedFile(OUString const& rFileName, OUString const& rMimeType, std::unique_ptr<PDFOutputStream> rStream);
+ void addDocumentAttachedFile(OUString const& rFileName, OUString const& rMimeType, OUString const& rDescription, std::unique_ptr<PDFOutputStream> rStream);
sal_Int32 addEmbeddedFile(BinaryDataContainer const & rDataContainer);
sal_Int32 addEmbeddedFile(std::unique_ptr<PDFOutputStream> rStream, OUString const& rMimeType);
diff --git a/vcl/source/gdi/pdfwriter.cxx b/vcl/source/gdi/pdfwriter.cxx
index 7d53f45c4699..2582b392b1ae 100644
--- a/vcl/source/gdi/pdfwriter.cxx
+++ b/vcl/source/gdi/pdfwriter.cxx
@@ -443,9 +443,9 @@ PDFOutputStream::~PDFOutputStream()
{
}
-void PDFWriter::AddAttachedFile(OUString const& rFileName, OUString const& rMimeType, std::unique_ptr<PDFOutputStream> pStream)
+void PDFWriter::AddAttachedFile(OUString const& rFileName, OUString const& rMimeType, OUString const& rDescription, std::unique_ptr<PDFOutputStream> pStream)
{
- xImplementation->addDocumentAttachedFile(rFileName, rMimeType, std::move(pStream));
+ xImplementation->addDocumentAttachedFile(rFileName, rMimeType, rDescription, std::move(pStream));
}
std::set< PDFWriter::ErrorCode > const & PDFWriter::GetErrors() const
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 2a87f8cb4e23..8be74da9e1c5 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -3423,12 +3423,13 @@ bool PDFWriterImpl::appendDest( sal_Int32 nDestID, OStringBuffer& rBuffer )
return true;
}
-void PDFWriterImpl::addDocumentAttachedFile(OUString const& rFileName, OUString const& rMimeType, std::unique_ptr<PDFOutputStream> rStream)
+void PDFWriterImpl::addDocumentAttachedFile(OUString const& rFileName, OUString const& rMimeType, OUString const& rDescription, std::unique_ptr<PDFOutputStream> rStream)
{
sal_Int32 nObjectID = addEmbeddedFile(std::move(rStream), rMimeType);
auto& rAttachedFile = m_aDocumentAttachedFiles.emplace_back();
rAttachedFile.maFilename = rFileName;
rAttachedFile.maMimeType = rMimeType;
+ rAttachedFile.maDescription = rDescription;
rAttachedFile.mnEmbeddedFileObjectId = nObjectID;
rAttachedFile.mnObjectId = createObject();
}
@@ -4930,6 +4931,7 @@ bool PDFWriterImpl::emitEmbeddedFiles()
continue;
sal_Int32 nSizeObject = createObject();
+ sal_Int32 nParamsObject = createObject();
OStringBuffer aLine;
aLine.append(rEmbeddedFile.m_nObject);
@@ -4942,6 +4944,8 @@ bool PDFWriterImpl::emitEmbeddedFiles()
}
aLine.append(" /Length ");
appendObjectReference(nSizeObject, aLine);
+ aLine.append(" /Params ");
+ appendObjectReference(nParamsObject, aLine);
aLine.append(">>\nstream\n");
checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject);
CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
@@ -4975,6 +4979,19 @@ bool PDFWriterImpl::emitEmbeddedFiles()
aLine.append("\nendobj\n\n");
if (!writeBuffer(aLine.getStr(), aLine.getLength()))
return false;
+ aLine.setLength(0);
+
+ if (!updateObject(nParamsObject))
+ return false;
+ aLine.append(nParamsObject);
+ aLine.append(" 0 obj\n");
+ aLine.append("<<");
+ aLine.append("/Size ");
+ aLine.append(nSize);
+ aLine.append(">>");
+ aLine.append("\nendobj\n\n");
+ if (!writeBuffer(aLine.getStr(), aLine.getLength()))
+ return false;
}
return true;
}
@@ -5093,11 +5110,20 @@ bool PDFWriterImpl::emitCatalog()
aLine.setLength( 0 );
appendObjectID(rAttachedFile.mnObjectId, aLine);
- aLine.append("<</Type/Filespec /F");
- aLine.append('<');
+ aLine.append("<</Type /Filespec");
+ aLine.append("/F<");
PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
- aLine.append('>');
- aLine.append(" /EF <</F ");
+ aLine.append("> ");
+ aLine.append("/UF<");
+ PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
+ aLine.append("> ");
+ if (!rAttachedFile.maDescription.isEmpty())
+ {
+ aLine.append("/Desc <");
+ PDFWriter::AppendUnicodeTextString(rAttachedFile.maDescription, aLine);
+ aLine.append("> ");
+ }
+ aLine.append("/EF <</F ");
appendObjectReference(rAttachedFile.mnEmbeddedFileObjectId, aLine);
aLine.append(">>");
aLine.append(">>\nendobj\n\n");