• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSPDFImageRep / PDFOperationWithView question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPDFImageRep / PDFOperationWithView question


  • Subject: NSPDFImageRep / PDFOperationWithView question
  • From: Joel Norvell <email@hidden>
  • Date: Sat, 17 Nov 2007 12:38:16 -0800 (PST)

Dear Cocoa-dev People,

When I read a two page PDF file and use PDFOperationWithView to "copy" its
NSPDFImageRep* pdfRep to pdxRep:

    [pdfRep bounds] is x=0, y=0, width=612, height=792
    [pdfRep pageCount] is 2

    [pdxRep bounds] is x=0, y=0, width=612, height=1584
    [pdxRep pageCount] is 1

I'd like the pdxRep copy to have the same bounds and pageCount as the original
pdfRep.
How could I accomplish this?  Or is this change of pageCount and bounds
unavoidable?

Note about my "added code":  I tried using both:

    PDFOperationWithView:insideRect:toData:
    PDFOperationWithView:insideRect:toData:printInfo:

But adding printInfo didn't affect the pageCount or bounds.

Sincerely,
Joel

P.S. My question is similar to Brock Brandenberg's well-written
"PDFOperationWithView" question which was asked but not answered in 2002.


// I added code at the end of this method in the PDFView sample
// http://developer.apple.com/samplecode/PDFView/

// PDFImageView loadFromPath: -- Load the PDF at the specified path into the
view.
// This automatically resizes the view to fit all pages of the document.

- (void) loadFromPath: (NSString *) path
{
    NSPDFImageRep *pdfRep;
    NSImage       *pdfImage;
    NSRect        frame;

    //  Load the file into an image-representation,
    //	then create an image and add the representation to it.
    pdfRep = [NSPDFImageRep imageRepWithContentsOfFile: path];
    pdfImage = [[[NSImage alloc] init] autorelease];
    [pdfImage addRepresentation: pdfRep];

    //	Figure our frame by getting the bounds, which is really the size
    //	of one page, and multiplying the height by the page count.
    frame = [pdfRep bounds];
    frame.size.height *= [pdfRep pageCount];

    //	Install the image (remember, we're an NSImageView subclass)
    [self setImage: pdfImage];

    //  Set our frame to match the PDF's full height (all pages)
    //  (don't involve our override of -setFrame:, or things won't work right)
    [super setFrame: frame];

    //	Always scroll to show the top of the image
    if ([self isFlipped])
        [self scrollPoint: NSMakePoint (0, 0)];
    else
        [self scrollPoint: NSMakePoint (0, frame.size.height)];

   //  ADDED CODE
    NSMutableData* pdxRepData = [[NSMutableData alloc] init];
    NSPrintOperation* printOp = [NSPrintOperation PDFOperationWithView:self
                                                            insideRect:[self
frame]

toData:pdxRepData];
    [printOp runOperation];
    NSPDFImageRep *pdxRep = [[NSPDFImageRep alloc] initWithData: pdxRepData];
}




      ____________________________________________________________________________________
Be a better pen pal.
Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: (Solved) Leopard performance penalty (3x slower), NSPopAutoreleasePool
  • Next by Date: Re: Leopard performance penalty (3x slower), NSPopAutoreleasePool
  • Previous by thread: Re: Safe asynchronous file copies
  • Next by thread: Detecting new line character(s) in text file?
  • Index(es):
    • Date
    • Thread