Issue #27: Signature plugin - inserting bitmap images does not work

This commit is contained in:
Jakub Melka 2022-10-22 17:04:47 +02:00
parent 87a152401b
commit cb1c31ba3d
2 changed files with 37 additions and 2 deletions

View File

@ -821,9 +821,10 @@ void PDFPageContentStreamBuilder::end(QPainter* painter)
}
}
PDFObject oldResourcesObject = pageDictionary->get("Resources");
PDFObject oldResourcesObject = m_documentBuilder->getObject(pageDictionary->get("Resources"));
oldResourcesObject = removeDictionaryReferencesFromResources(oldResourcesObject);
replaceResources(contentsReference, resourcesReference, oldResourcesObject);
m_documentBuilder->mergeTo(resourcesReference, m_documentBuilder->getObject(oldResourcesObject));
m_documentBuilder->mergeTo(resourcesReference, oldResourcesObject);
}
switch (m_mode)
@ -859,6 +860,38 @@ void PDFPageContentStreamBuilder::end(QPainter* painter)
}
}
PDFObject PDFPageContentStreamBuilder::removeDictionaryReferencesFromResources(PDFObject resources)
{
PDFObjectFactory resourcesBuilder;
resources = m_documentBuilder->getObject(resources);
if (resources.isDictionary())
{
resourcesBuilder.beginDictionary();
const PDFDictionary* resourcesDictionary = resources.getDictionary();
const size_t count = resourcesDictionary->getCount();
for (size_t i = 0; i < count; ++i)
{
PDFObject object = m_documentBuilder->getObject(resourcesDictionary->getValue(i));
if (object.isNull())
{
continue;
}
resourcesBuilder.beginDictionaryItem(resourcesDictionary->getKey(i).getString());
resourcesBuilder << object;
resourcesBuilder.endDictionaryItem();
}
resourcesBuilder.endDictionary();
resources = resourcesBuilder.takeObject();
}
return resources;
}
void PDFPageContentStreamBuilder::replaceResources(PDFObjectReference contentStreamReference,
PDFObjectReference resourcesReference,
PDFObject oldResources)

View File

@ -301,6 +301,8 @@ public:
void end(QPainter* painter);
private:
PDFObject removeDictionaryReferencesFromResources(PDFObject resources);
void replaceResources(PDFObjectReference contentStreamReference,
PDFObjectReference resourcesReference,
PDFObject oldResources);