filter/source/pdf/pdfexport.cxx | 2 +- include/vcl/pdfwriter.hxx | 2 +- vcl/inc/pdf/pdfwriter_impl.hxx | 3 ++- vcl/source/gdi/pdfwriter.cxx | 4 ++-- vcl/source/gdi/pdfwriter_impl.cxx | 36 +++++++++++++++++++++++++++++++----- 5 files changed, 37 insertions(+), 10 deletions(-)
New commits: commit 9740331d8bc56a9b6fbe3e4c1b26fb97f6639cc6 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jan 28 19:28:06 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Feb 1 02:11:05 2023 +0000 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 <qui...@gmail.com> diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx index 7e710dabd928..9d97f2134f41 100644 --- a/filter/source/pdf/pdfexport.cxx +++ b/filter/source/pdf/pdfexport.cxx @@ -935,7 +935,7 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& else if (aSrcMimetype == "application/vnd.oasis.opendocument.graphics") aExt = ".odg"; std::unique_ptr<vcl::PDFOutputStream> pStream(new PDFExportStreamDoc(mxSrcDoc, aPreparedPermissionPassword)); - aPDFWriter.AddAttachedFile("Original" + aExt, aSrcMimetype, std::move(pStream)); + aPDFWriter.AddAttachedFile("Original" + aExt, aSrcMimetype, u"Embedded original document of this PDF file", std::move(pStream)); } if ( pOut ) diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index 80b71237138e..366cd6714412 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -1210,7 +1210,7 @@ The following structure describes the permissions used in PDF security @param pStream the interface to the additional stream */ - void AddAttachedFile(OUString const& rFileName, const OUString& rMimeType, std::unique_ptr<PDFOutputStream> pStream); + void AddAttachedFile(OUString const& rFileName, OUString const& rMimeType, OUString const& rDescription, std::unique_ptr<PDFOutputStream> pStream); /// Write rString as a PDF hex string into rBuffer. static void AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer); 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");