vcl/source/gdi/pdfwriter_impl.cxx |   92 +++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 40 deletions(-)

New commits:
commit 2ace1a19ff358e4517eb248bdce9b206e70692e7
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Nov 1 00:24:14 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Nov 8 16:43:25 2024 +0100

    pdf: Don't emit metadata for /Info, allow XMP for PDF >= 1.4
    
    Metadata written to /Info dictionary is deprecated in PDF 2.0 with
    the exception of /CreateDate and /ModDate, so don't write it if
    we are writing to PDF 2.0.
    Instead of this allow to write the XMP metadata all the way back
    to PDF 1.4 (when it was added to the specs).
    
    Change-Id: I33e29d7d52e96d34e973032d7d8b42d876282dcb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175925
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index e23e20c87fea..73e031edfe9b 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -5800,51 +5800,63 @@ sal_Int32 PDFWriterImpl::emitInfoDict( )
 
     if( updateObject( nObject ) )
     {
-        OStringBuffer aLine( 1024 );
-        aLine.append( nObject );
-        aLine.append( " 0 obj
"
-                      "<<" );
-        if( !m_aContext.DocumentInfo.Title.isEmpty() )
-        {
-            aLine.append( "/Title" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Title, 
nObject, aLine );
-            aLine.append( "
" );
-        }
-        if( !m_aContext.DocumentInfo.Author.isEmpty() )
-        {
-            aLine.append( "/Author" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Author, 
nObject, aLine );
-            aLine.append( "
" );
-        }
-        if( !m_aContext.DocumentInfo.Subject.isEmpty() )
-        {
-            aLine.append( "/Subject" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Subject, 
nObject, aLine );
-            aLine.append( "
" );
-        }
-        if( !m_aContext.DocumentInfo.Keywords.isEmpty() )
-        {
-            aLine.append( "/Keywords" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Keywords, 
nObject, aLine );
-            aLine.append( "
" );
-        }
-        if( !m_aContext.DocumentInfo.Creator.isEmpty() )
+        OStringBuffer aLine(1024);
+        appendObjectID(nObject, aLine);
+        aLine.append("<<");
+
+        // These entries are deprecated in PDF 2.0 (in favor of XMP metadata) 
and shouldn't be written.
+        // Exception: CreationDate and ModDate (which we don't write)
+        if (m_aContext.Version < PDFWriter::PDFVersion::PDF_2_0)
         {
-            aLine.append( "/Creator" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Creator, 
nObject, aLine );
-            aLine.append( "
" );
+            if (!m_aContext.DocumentInfo.Title.isEmpty())
+            {
+                aLine.append("/Title" );
+                appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Title, 
nObject, aLine );
+                aLine.append("
" );
+            }
+            if( !m_aContext.DocumentInfo.Author.isEmpty() )
+            {
+                aLine.append( "/Author" );
+                appendUnicodeTextStringEncrypt( 
m_aContext.DocumentInfo.Author, nObject, aLine );
+                aLine.append( "
" );
+            }
+            if( !m_aContext.DocumentInfo.Subject.isEmpty() )
+            {
+                aLine.append( "/Subject" );
+                appendUnicodeTextStringEncrypt( 
m_aContext.DocumentInfo.Subject, nObject, aLine );
+                aLine.append( "
" );
+            }
+            if( !m_aContext.DocumentInfo.Keywords.isEmpty() )
+            {
+                aLine.append( "/Keywords" );
+                appendUnicodeTextStringEncrypt( 
m_aContext.DocumentInfo.Keywords, nObject, aLine );
+                aLine.append( "
" );
+            }
+            if( !m_aContext.DocumentInfo.Creator.isEmpty() )
+            {
+                aLine.append( "/Creator" );
+                appendUnicodeTextStringEncrypt( 
m_aContext.DocumentInfo.Creator, nObject, aLine );
+                aLine.append( "
" );
+            }
+            if( !m_aContext.DocumentInfo.Producer.isEmpty() )
+            {
+                aLine.append( "/Producer" );
+                appendUnicodeTextStringEncrypt( 
m_aContext.DocumentInfo.Producer, nObject, aLine );
+                aLine.append( "
" );
+            }
         }
-        if( !m_aContext.DocumentInfo.Producer.isEmpty() )
+
+        // Allowed in PDF 2.0
         {
-            aLine.append( "/Producer" );
-            appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Producer, 
nObject, aLine );
+            aLine.append("/CreationDate");
+            appendLiteralStringEncrypt( m_aCreationDateString, nObject, aLine 
);
             aLine.append( "
" );
         }
 
-        aLine.append( "/CreationDate" );
-        appendLiteralStringEncrypt( m_aCreationDateString, nObject, aLine );
-        aLine.append( ">>
endobj

" );
-        if( ! writeBuffer( aLine ) )
+        aLine.append(">>
");
+        aLine.append("endobj

" );
+
+        if (!writeBuffer(aLine))
             nObject = 0;
     }
     else
@@ -6035,7 +6047,7 @@ static void lcl_assignMeta(const 
css::uno::Sequence<OUString>& rValues, std::vec
 // Since in PDF 1.4
 sal_Int32 PDFWriterImpl::emitDocumentMetadata()
 {
-    if( !m_bIsPDF_A1 && !m_bIsPDF_A2 && !m_bIsPDF_A3 && !m_bIsPDF_A4 && 
!m_bIsPDF_UA)
+    if (m_aContext.Version < PDFWriter::PDFVersion::PDF_1_4)
         return 0;
 
     //get the object number for all the destinations

Reply via email to