diff options
Diffstat (limited to 'vcl/source/gdi/pdfwriter_impl.cxx')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 698fdab61d6b..490f5d3b4768 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -676,6 +676,32 @@ static void appendDestinationName( const OUString& rString, OStringBuffer& rBuff } } +/// Decide if rGraphic has PDF data that is possible to embed in our output. +static bool hasPdfData(const Graphic& rGraphic, bool bUseReferenceXObject) +{ + const css::uno::Sequence<sal_Int8>& rData = rGraphic.getPdfData(); + + if (rData.getLength() < 8) + return false; + + if (rData[0] != '%' || rData[1] != 'P' || rData[2] != 'D' || rData[3] != 'F' || rData[4] != '-') + // Unexpected header. + return false; + + if (bUseReferenceXObject) + // This is possible for all versions. + return true; + + sal_Int32 nMajor = OString(rData[5]).toInt32(); + sal_Int32 nMinor = OString(rData[7]).toInt32(); + + if (nMajor > 1 || (nMajor == 1 && nMinor > 4)) + // This is PDF-1.5 or newer, can't embed into PDF-1.4. + return false; + + return true; +} + void PDFWriter::AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer) { rBuffer.append( "FEFF" ); @@ -11574,7 +11600,7 @@ void PDFWriterImpl::createEmbeddedFile(const Graphic& rGraphic, ReferenceXObject // no pdf data. rEmit.m_nBitmapObject = nBitmapObject; - if (!rGraphic.getPdfData().hasElements()) + if (!hasPdfData(rGraphic, m_aContext.UseReferenceXObject)) return; if (m_aContext.UseReferenceXObject) @@ -11754,7 +11780,7 @@ const PDFWriterImpl::BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx m_aBitmaps.push_front( BitmapEmit() ); m_aBitmaps.front().m_aID = aID; m_aBitmaps.front().m_aBitmap = aBitmap; - if (!rGraphic.getPdfData().hasElements() || m_aContext.UseReferenceXObject) + if (!hasPdfData(rGraphic, m_aContext.UseReferenceXObject) || m_aContext.UseReferenceXObject) m_aBitmaps.front().m_nObject = createObject(); createEmbeddedFile(rGraphic, m_aBitmaps.front().m_aReferenceXObject, m_aBitmaps.front().m_nObject); it = m_aBitmaps.begin(); |