Date
1 - 5 of 5
Drawing to a PDF context
Sandor Szatmari
Jim,
On Mar 4, 2020, at 11:56 AM, Jim <jimcfl@...> wrote:Yea, we are printing and distributing the PDF so it’s important to retain the vector nature of the PDF. People need to be able to zoom in to read the finer details. Thanks!
|
|
Sandor Szatmari
Quincey,
Also interesting. If I call [NSGraphics currentContext] before trying to set the context it returns nil.
Thank you!
|
|
Jim
On Mar 4, 2020, at 11:06 AM, Quincey Morris <quinceymorris@...> wrote:When I wrote an app that added things to an existing PDF a couple years ago, I was able to use text and custom annotations to display elements on a document in a PDFView, but was unable to figure out how to use PDFKit to save the annotations into the document so that they would be visible with Preview or Acrobat. It appears that PDFKit is primarily oriented around on-screen display and markup of a PDF, not creating or modifying a PDF. So to save the changes I had to redraw the existing document in a CGPDFContext and then draw the elements as images in that context as well. This turns each PDF page into an image, which wasn’t a problem in my case, but is usually not desirable. Jim Crate |
|
Quincey Morris
On Mar 4, 2020, at 06:52 , Sandor Szatmari <admin.szatmari.net@...> wrote:
Well, by default, NWView coordinates are flipped vs. CGContext coordinates. I suggest you try temporarily forcing the point you’re drawing at to be the center of the context or view, and see if the text even appears. If so, you should be able to see what you need to do to transform the point at which you’re drawing (based on which direction the text is running, and whether it’s upside down). Are you switching over to PDFKit? In that case, you’ll have to respect whatever coordinate system it uses. It looks like there’s some advice on that subject in the “Override the Draw Method and Add Your Custom Graphic” section of https://developer.apple.com/documentation/pdfkit/adding_custom_graphics_to_a_pdf. |
|
Sandor Szatmari
I need to replace calls to CGShowTextAtPoint() with calls to -drawAtPoint:withAttributes:
I made this change and drawing fails… :/ i.e. no text rendered, no exception, logging of errors, etc. simply no text The CG implementation of this code has been working with no leaks, crashes, etc for at least 10+ years. Original context is created as follows: CGContextRef ctx; ctx = CGPDFContextCreateWithURL(…) I tried setting the current NS graphics context like so [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:ctx flipped:NO] … but this causes the app to crash. Any thoughts? Is this an ownership issue? Should I be letting the NSGraphics side of things know not to dispose of the context… Thanks in advance, Sandor |
|