12#include <rtl/strbuf.hxx>
25 : m_rContainer(rContainer)
31 std::map<sal_Int32, sal_Int32>& rCopiedResources)
49 for (
auto const& pElement : pInputArray->GetElements())
59 for (
auto const& pPair : pInputDictionary->GetItems())
62 rLine.append(pPair.first);
77 std::map<sal_Int32, sal_Int32>& rCopiedResources)
80 if (it != rCopiedResources.end())
90 <<
" -> " << nObject);
92 OStringBuffer aLine = OString::number(nObject) +
" 0 obj\n";
105 aLine.append(
"/" + rPair.first +
" ");
109 aLine.append(
" >>\n");
115 aLine.append(
"stream\n");
122 const std::vector<filter::PDFElement*>& rElements = pArray->GetElements();
125 for (
auto const& pElement : rElements)
139 pNumber->writeString(aLine);
154 aLine.append(
static_cast<const char*
>(rStream.
GetData()), rStream.
GetSize());
160 aLine.append(
"\nendstream\n");
166 aLine.append(
"endobj\n\n");
174 const OString& rKind,
175 std::map<sal_Int32, sal_Int32>& rCopiedResources)
179 std::map<OString, sal_Int32> aRet;
182 std::map<OString, filter::PDFElement*> aItems;
191 aItems = pDictionary->GetItems();
202 pKindObject = pReferenced;
213 aItems = pDictionary->GetItems();
218 aItems =
pObject->GetDictionaryItems();
226 bool bHasDictValue =
false;
228 for (
const auto& rItem : aItems)
236 bHasDictValue =
true;
249 aRet[rItem.first] = nObject;
252 if (bHasDictValue && pKindObject)
255 return "/" + rKind +
" " + OString::number(nObject) +
" 0 R";
259 OStringBuffer sRet(
"/" + rKind +
"<<");
260 for (
const auto& rPair : aRet)
262 sRet.append(
"/" + rPair.first +
" " + OString::number(rPair.second) +
" 0 R");
266 return sRet.makeStringAndClear();
272 std::map<sal_Int32, sal_Int32> aCopiedResources;
277 std::map<sal_Int32, sal_Int32>& rCopiedResources)
279 rLine.append(
" /Resources <<");
280 static const std::initializer_list<OString> aKeys
281 = {
"ColorSpace",
"ExtGState",
"Font",
"XObject",
"Shading",
"Pattern" };
282 for (
const auto& rKey : aKeys)
292 for (
auto pContent : rContentStreams)
297 SAL_WARN(
"vcl.pdfwriter",
"PDFObjectCopier::copyPageStreams: contents has no stream");
305 if (!pFilter && pFilterArray)
308 if (!aElements.empty())
314 if (pFilter->GetValue() !=
"FlateDecode")
323 aZCodec.
Decompress(rPageStream, aMemoryStream);
326 SAL_WARN(
"vcl.pdfwriter",
"PDFObjectCopier::copyPageStreams: decompression failed");
340 return rStream.
Tell();
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
tools::Long Decompress(SvStream &rIStm, SvStream &rOStm)
tools::Long EndCompression()
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
Allows creating, updating and writing PDF objects in a container.
virtual void checkAndEnableStreamEncryption(sal_Int32 nObject)=0
virtual bool updateObject(sal_Int32 n)=0
bool writeBuffer(std::string_view aBuffer)
virtual sal_Int32 createObject()=0
virtual void disableStreamEncryption()=0
OString copyExternalResources(filter::PDFObjectElement &rPage, const OString &rKind, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
Copies resources of a given kind from an external page to the output, returning what has to be includ...
PDFObjectCopier(PDFObjectContainer &rContainer)
void copyRecursively(OStringBuffer &rLine, filter::PDFElement &rInputElement, SvMemoryStream &rDocBuffer, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
static sal_Int32 copyPageStreams(std::vector< filter::PDFObjectElement * > &rContentStreams, SvMemoryStream &rStream, bool &rCompressed)
Copies page one or more page streams from rContentStreams into rStream.
void copyPageResources(filter::PDFObjectElement *pPage, OStringBuffer &rLine)
Copies resources of pPage into rLine.
PDFObjectContainer & m_rContainer
sal_Int32 copyExternalResource(SvMemoryStream &rDocBuffer, filter::PDFObjectElement &rObject, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
Copies a single resource from an external document, returns the new object ID in our document.
static bool compressStream(SvMemoryStream *)
const std::vector< PDFElement * > & GetElements() const
Dictionary object: a set key-value pairs.
SvMemoryStream & GetEditBuffer()
Access to the input document, even after the input stream is gone.
A byte range in a PDF file.
virtual void writeString(OStringBuffer &rBuffer)=0
Name object: a key string.
Numbering object: an integer or a real.
Indirect object: something with a unique ID.
const std::map< OString, PDFElement * > & GetDictionaryItems()
Get access to the parsed key-value items from the object dictionary.
double GetObjectValue() const
PDFElement * Lookup(const OString &rDictionaryKey)
PDFStreamElement * GetStream() const
Access to the stream of the object, if it has any.
PDFArrayElement * GetArray()
PDFNumberElement * GetNumberElement() const
PDFObjectElement * LookupObject(const OString &rDictionaryKey)
PDFDocument & GetDocument()
PDFDictionaryElement * GetDictionary()
Reference object: something with a unique ID.
Stream object: a byte array with a known length.
SvMemoryStream & GetMemory()
EmbeddedObjectRef * pObject
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)