Search code examples
iphoneiosobjective-cpodofo

how to add FileAttachment annotations of pdf


Hello i am using this library for implementation of annotation but facing one issue of attachment of image it provide PdfFileSpec objective c++ function i tried to convert this function to objective c but getting error in below image

class PODOFO_DOC_API PdfFileSpec : public PdfElement {
 public:
    PdfFileSpec( const char* pszFilename, bool bEmbedd, PdfDocument* pParent );

    PdfFileSpec( const char* pszFilename, bool bEmbedd, PdfVecObjects* pParent );

    /* Petr P. Petrov 17 September 2009*/
    /** Embeds the file in memory from "data" buffer under "pszFileName" fie name.
      */
    PdfFileSpec( const char* pszFilename, const unsigned char* data, ptrdiff_t size, PdfVecObjects* pParent);

    PdfFileSpec( PdfObject* pObject );

    /** \returns the filename of this file specification.
     *           if no general name is available 
     *           it will try the Unix, Mac and DOS keys too.
     */
    const PdfString & GetFilename() const;

enter image description here

 +(void)createFreeTextAnnotationOnPage:(NSInteger)pageIndex doc:(PdfMemDocument*)aDoc rect:(CGRect)aRect borderWidth:(double)bWidth title:(NSString*)title content:(NSString*)content bOpen:(Boolean)bOpen color:(UIColor*)color {
    PoDoFo::PdfMemDocument *doc = (PoDoFo::PdfMemDocument *) aDoc;
    PoDoFo::PdfPage* pPage = doc->GetPage(pageIndex);
    if (! pPage) {
        // couldn't get that page
        return;
    }
    PoDoFo::PdfAnnotation* anno;
    PoDoFo::EPdfAnnotation type= PoDoFo::ePdfAnnotation_Text;

    PoDoFo::PdfRect rect;
    rect.SetBottom(aRect.origin.y);
    rect.SetLeft(aRect.origin.x);
    rect.SetHeight(aRect.size.height);
    rect.SetWidth(aRect.size.width);
    NSData *data=UIImagePNGRepresentation([UIImage imageNamed:@"Add_button.png"]);
    anno = pPage->CreateAnnotation(type , rect);
    NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    PoDoFo::PdfString sTitle([title UTF8String]);
    PoDoFo::PdfString sContent([content UTF8String]);
    PoDoFo::PdfFileSpec data1([myString UTF8String], true, doc);
}

Solution

  • I don't see why you are using reinterpret_cast, and it's certainly being misused in the construction of data1.

    Have you simply tried:

    PoDoFo::PdfString sTitle([title UTF8String]);
    PoDoFo::PdfString sContent([content UTF8String]);
    PoDoFo::PdfFileSpec data1([myString UTF8String], true, doc);