Help with displaying encrypted PDF image

  • Hi, im trying to displaying encrypted pdf formated images in cocoa.
    this is  my code to load these images, but nothing is displayed,
    however non encrypted pdf displayed with zero problems. All my
    encrypted images seems to be decrypted because the printf statement
    "unlocked" is reached always. Any help will be appreciated, thanks.


      NSImage *pix2;

      NSData *pdfData=[[NSData alloc]initWithContentsOfFile:image_path_];
      PDFDocument *pdfImage=[[PDFDocument alloc]initWithData:pdfData];

      if([pdfImage isLocked]) {
      if([pdfImage unlockWithPassword:@"xxxx"]) {
        printf("unlocked");
      }
      else {
        printf("error");
      }
      }

      pix2=[[NSImage alloc]initWithData:[pdfImage dataRepresentation]];

      [pix2 drawInRect:[spritesGCObjectsArray_ returnSpriteRect_]
            fromRect:NSZeroRect
            operation:NSCompositeCopy
            fraction:1];

    Mario Gajardo Tassara
  • On Feb 17, 2008, at 2:52 PM, Mario Gajardo Tassara wrote:

    > Hi, im trying to displaying encrypted pdf formated images in cocoa.
    > this is  my code to load these images, but nothing is displayed,
    > however non encrypted pdf displayed with zero problems. All my
    > encrypted images seems to be decrypted because the printf statement
    > "unlocked" is reached always. Any help will be appreciated, thanks.

    Off the top of my head: this is probably related to the inability to
    write encrypted but unlocked documents back out to file. Try drawing
    your PDFDocument into an NSImage instead of initializing an NSImage
    from the dataRepresentation of the PDFDocument. Something to the
    effect of:

    NSImage *pix2 = [[NSImage alloc] initWithSize:[pdfImage
    boundsForBox:kPDFDisplayBoxMediaBox].size];

    [pix2 lockFocus];
    [[pdfImage pageAtIndex:0] drawWithBox:
    boundsForBox:kPDFDisplayBoxMediaBox];
    [pix2 unlockFocus];

    (Typed directly into Mail, so untested.)

    -António

    --------------------------------------------
    I try to take one day at a time, but sometimes, several days attack me
    all at once!
    --------------------------------------------
  • On Feb 17, 2008, at 5:52 AM, Mario Gajardo Tassara wrote:
    > Hi, im trying to displaying encrypted pdf formated images in cocoa.
    > this is  my code to load these images, but nothing is displayed,
    > however non encrypted pdf displayed with zero problems. All my
    > encrypted images seems to be decrypted because the printf statement
    > "unlocked" is reached always.

    Yes, for an encrypted PDF document, -[PDFDocument dataRepresentation],
    -[PDFDocument writeToURL:], etc. do nothing.

    You can still get the image data by hand by drawing the PDFPage into a
    CGPDFContext.

    John Calhoun—