• 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
Re: PDFMarkupAnnotations not showing when drawing PDFPage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PDFMarkupAnnotations not showing when drawing PDFPage


  • Subject: Re: PDFMarkupAnnotations not showing when drawing PDFPage
  • From: Antonio Nunes <email@hidden>
  • Date: Fri, 16 Feb 2007 11:37:01 +0000

On Feb 15, 2007, at 9:28 PM, John Calhoun wrote:

Try making the highlight smaller for a start and see if you can get a small highlight. That would eliminate color and a few other possibilities. If it is indeed size that is the issue - you could grow it until it fails. That might illuminating. But generally, you probably would be better to have multiple highlights (one per line of text) anyway. I would pursue this approach anyway. Figure out how to break up a page into individual lines and then either create individual Highlight annotations for each line of text or create a single Highlight annotation with multiple groups of quad points.

Since I was getting nowhere, I decided to see if PDFView _would_ show the markup annotation, which revealed the following:


-As can be deduced from John's previous reply, the markup doesn't need to coincide with actual text, it can be anywhere on the page, so this allows a slight simplification of the test code.

- The markup color defaults to white (not yellow) so setting the color expressly is definitely needed.

-If I simply init the markup annotation with bounds and then try to show it, it doesn´t appear in a PDFView. However, if I set de quadrilateral points afterwards then it does appear in a PDFView, but doesn't draw in a simple NSView subclass. Also, the quadrilateral points need to be set relative to the origin of the markup's bound, not the origin of the page, which is not clear from the docs, and also unlike what the docs suggest, the points are not arranged counterclockwise, but in the Z shape John mentioned. So, counting from 0 to 3, the lower left point (which is always {0, 0}) maps to array element with index 2 in the array of quadrilateral points.

I took a copy of the PDFKitViewer sample application and added an NSView to the document window, and made it a subclass of ANPDFView:

@interface ANPDFView : NSView {
	IBOutlet PDFView	*_masterView;
}

The drawRect method of this class is:

- (void)drawRect:(NSRect)rect {
    // Get the current page of the PDFView and draw it.
	[[_masterView currentPage] drawWithBox:kPDFDisplayBoxMediaBox];
}

I connected it's single outlet to the PDFView and added an ivar to myPDFDocument to connect from there to the new view:

	IBOutlet ANPDFView				*_slaveView;

Added new action method to be able to create annotations:

- (IBAction)createNewAnnotation:(id)sender
{
#pragma unused (sender)
PDFPage *page = [_pdfView currentPage];
NSRect bounds = NSMakeRect(20, 400, 300, 60);
PDFAnnotationMarkup *markup = [[[PDFAnnotationMarkup alloc] initWithBounds:bounds] autorelease];
[markup setMarkupType:kPDFMarkupTypeHighlight];
[markup setColor:[NSColor yellowColor]];

[markup setQuadrilateralPoints: [NSArray arrayWithObjects:
[NSValue valueWithPoint: NSMakePoint(0, NSHeight(bounds))],
[NSValue valueWithPoint: NSMakePoint(NSWidth(bounds), NSHeight (bounds))],
[NSValue valueWithPoint: NSMakePoint(0, 0)],
[NSValue valueWithPoint: NSMakePoint(NSWidth(bounds), 0)],
NULL]];

[page addAnnotation:markup];

PDFAnnotationCircle *circle = [[[PDFAnnotationCircle alloc] initWithBounds:bounds] autorelease];
[page addAnnotation:circle];

[page setDisplaysAnnotations:YES];
[_pdfView setNeedsDisplay:YES];
[_slaveView setNeedsDisplay:YES];
}


As you can see, it simply creates an ad hoc rect, unrelated to anything on the page. I also incorporated drawing a 'circle'. So, now when I run the app and ask it to add an annotation it executes the createNewAnnotation method and both the markup and the circle annotations show up in the PDFView. In the custom NSView subclass though only the circle shows. No sign of the markup.

Hence the question becomes: what do I need to do in the NSView subclass to make it draw the markup annotation? Since the PDFView can do it, there must be some way (workaround?) of accomplishing this in a non PDFView subclass.

António Nunes

P.S.

The stroke line width is relative to the distance between these pairs of points. So, to highlight as you describe an entire page, would likely end up with a stroke of some 700 or so points. This could be the problem — I've never pushed CG to stroke a line that thick. Or the code to determine the line may be failing for such extreme cases....

I tried to break the stroke by experimenting with bounding boxes up to 2000 pixels high, but it all showed up great in the PDFView. So looks like there´s no need to worry about CG being able to handle a line that thick.


-----------------------------------------
Forgiveness is not an occasional act;
it is a permanent attitude.

--Martin Luther King, Jr
-----------------------------------------




_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >PDFMarkupAnnotations not showing when drawing PDFPage (From: Antonio Nunes <email@hidden>)
 >Re: PDFMarkupAnnotations not showing when drawing PDFPage (From: John Calhoun <email@hidden>)
 >Re: PDFMarkupAnnotations not showing when drawing PDFPage (From: Antonio Nunes <email@hidden>)
 >Re: PDFMarkupAnnotations not showing when drawing PDFPage (From: John Calhoun <email@hidden>)

  • Prev by Date: NSTokenField & Space Bar selection
  • Next by Date: Re: How to connect NSPopupButtons, Bindings, and Core Data Entities?
  • Previous by thread: Re: PDFMarkupAnnotations not showing when drawing PDFPage
  • Next by thread: Detecting Failed TableView Drag?
  • Index(es):
    • Date
    • Thread