12 #include <rtl/strbuf.hxx>
25 : m_rContainer(rContainer)
31 std::map<sal_Int32, sal_Int32>& rCopiedResources)
33 if (
auto pReference = dynamic_cast<filter::PDFReferenceElement*>(&rInputElement))
46 else if (
auto pInputArray = dynamic_cast<filter::PDFArrayElement*>(&rInputElement))
49 for (
auto const& pElement : pInputArray->GetElements())
56 else if (
auto pInputDictionary = dynamic_cast<filter::PDFDictionaryElement*>(&rInputElement))
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);
93 aLine.append(nObject);
94 aLine.append(
" 0 obj\n");
108 aLine.append(rPair.first);
113 aLine.append(
" >>\n");
118 aLine.append(
"stream\n");
120 aLine.append(static_cast<const char*>(rStream.
GetData()), rStream.
GetSize());
121 aLine.append(
"\nendstream\n");
128 const std::vector<filter::PDFElement*>& rElements = pArray->GetElements();
131 for (
auto const& pElement : rElements)
145 pNumber->writeString(aLine);
149 aLine.append(
"endobj\n\n");
161 const OString& rKind,
162 std::map<sal_Int32, sal_Int32>& rCopiedResources)
166 std::map<OString, sal_Int32> aRet;
169 std::map<OString, filter::PDFElement*> aItems;
170 if (
auto pResources = dynamic_cast<filter::PDFDictionaryElement*>(rPage.
Lookup(
"Resources")))
174 if (
auto pDictionary = dynamic_cast<filter::PDFDictionaryElement*>(pLookup))
177 aItems = pDictionary->GetItems();
179 else if (
auto pReference = dynamic_cast<filter::PDFReferenceElement*>(pLookup))
195 if (
auto pDictionary = dynamic_cast<filter::PDFDictionaryElement*>(pValue))
197 aItems = pDictionary->GetItems();
200 aItems =
pObject->GetDictionaryItems();
207 for (
const auto& rItem : aItems)
220 aRet[rItem.first] = nObject;
224 OStringBuffer sRet(
"/" + rKind +
"<<");
225 for (
const auto& rPair : aRet)
227 sRet.append(
"/" + rPair.first +
" " + OString::number(rPair.second) +
" 0 R");
231 return sRet.makeStringAndClear();
237 std::map<sal_Int32, sal_Int32> aCopiedResources;
242 std::map<sal_Int32, sal_Int32>& rCopiedResources)
244 rLine.append(
" /Resources <<");
245 static const std::initializer_list<OString> aKeys
246 = {
"ColorSpace",
"ExtGState",
"Font",
"XObject",
"Shading" };
247 for (
const auto& rKey : aKeys)
257 for (
auto pContent : rContentStreams)
262 SAL_WARN(
"vcl.pdfwriter",
"PDFObjectCopier::copyPageStreams: contents has no stream");
271 if (pFilter->GetValue() !=
"FlateDecode")
280 aZCodec.
Decompress(rPageStream, aMemoryStream);
283 SAL_WARN(
"vcl.pdfwriter",
"PDFObjectCopier::copyPageStreams: decompression failed");
297 return rStream.
Tell();
Numbering object: an integer or a real.
virtual bool updateObject(sal_Int32 n)=0
virtual bool writeBuffer(const void *pBuffer, sal_uInt64 nBytes)=0
sal_uInt64 Seek(sal_uInt64 nPos)
tools::Long Decompress(SvStream &rIStm, SvStream &rOStm)
EmbeddedObjectRef * pObject
A byte range in a PDF file.
void copyPageResources(filter::PDFObjectElement *pPage, OStringBuffer &rLine)
Copies resources of pPage into rLine.
PDFObjectContainer & m_rContainer
PDFDocument & GetDocument()
Indirect object: something with a unique ID.
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
tools::Long EndCompression()
double GetObjectValue() const
PDFStreamElement * GetStream() const
Access to the stream of the object, if it has any.
PDFObjectElement * LookupObject(const OString &rDictionaryKey)
SvMemoryStream & GetEditBuffer()
Access to the input document, even after the input stream is gone.
PDFDictionaryElement * GetDictionary()
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...
SvMemoryStream & GetMemory()
#define SAL_INFO(area, stream)
PDFNumberElement * GetNumberElement() const
static sal_Int32 copyPageStreams(std::vector< filter::PDFObjectElement * > &rContentStreams, SvMemoryStream &rStream, bool &rCompressed)
Copies page one or more page streams from rContentStreams into rStream.
PDFArrayElement * GetArray()
Reference object: something with a unique ID.
virtual sal_Int32 createObject()=0
static bool compressStream(SvMemoryStream *)
virtual void writeString(OStringBuffer &rBuffer)=0
#define SAL_WARN(area, stream)
Name object: a key string.
const std::map< OString, PDFElement * > & GetDictionaryItems()
Get access to the parsed key-value items from the object dictionary.
PDFElement * Lookup(const OString &rDictionaryKey)
void copyRecursively(OStringBuffer &rLine, filter::PDFElement &rInputElement, SvMemoryStream &rDocBuffer, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
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...
Stream object: a byte array with a known length.
PDFObjectCopier(PDFObjectContainer &rContainer)
Allows creating, updating and writing PDF objects in a container.