With the following code I am trying to update Ink Annotations by first
removing them, then writing them with new InkList data.

However, when I read the file back, the InkList key is missing in the
dictionary - what am I missing?


PdfDocumentData::PdfSaveResult PdfDocumentData::saveAs(QString fileName)
{
    QByteArray fn = fileName.toLocal8Bit();
    try {
        qDebug()<<"saving"<<fileName;
        for(int pn = 0; pn < m_doc2->GetPageCount(); pn++) {
            qDebug()<<"updating page"<<pn;
            auto page = m_doc2->GetPage(pn);
            for(int an = page->GetNumAnnots() - 1; an >= 0; an--) {
                auto anno = page->GetAnnotation(an);
                if(anno->GetType() == PoDoFo::ePdfAnnotation_Ink) {
                    page->DeleteAnnotation(an);
                }
            }
            if(m_annotations.contains(pn)) {
                QList<QList<QPointF> >& annots = m_annotations[pn];
                for(int an = 0; an < annots.size(); an++) {
                    qDebug()<<"writing annotation"<<an;
                    QList<QPointF>& str = annots[an];
                    PoDoFo::PdfRect rect(0,100,100,0); //FIXME
                    auto anno = 
page->CreateAnnotation(PoDoFo::ePdfAnnotation_Ink, rect);
                    auto dict = anno->GetObject()->GetDictionary();
                    PoDoFo::PdfArray points;
                    for (int p=0; p<str.size(); p++) {
                        points.push_back(str[p].x());
                        points.push_back(str[p].y());
                    }
                    PoDoFo::PdfArray array;
                    array.push_back(points); // InkList is Array of Array of 
Points

                    dict.AddKey("InkList", array);

                }
            }
        }
        m_doc2->Write(fn.data());
    } catch(...) {
        qDebug()<<"exception saving"<<fileName;
        return SaveError;
    }
    return SaveSuccess;
}


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to