Question

I've loaded a PDF Document into a UIView Class, and displayed it on screen using CGDrawRect. So Now I can visually see the PDF: What I want to do is have the user click certain points of the file, which will bring up the key board, allowing the user to directly add text to the PDF, which will later need to be rendered - some direction or guide would be very helpful ?

  • I understand its a lot simpler to draw a PDF from scratch then to manipulate it
  • I also understand Quartz 2d may be the way to go, but a bit confused with the samples
Was it helpful?

Solution

There are two possible scenarios here:

Editing existing PDF text is very difficult, even with something like PSPDFKit. It is no accident that there are no PDF-based word processors.

Annotating PDF content is more straightforward:

Add any additional content as subviews to the UIView that contains the PDF document. Additional content can be in the form of text, vectors or images - anything that can be added to a UIView. At this point you do not need to worry whether the added content is "part of" the PDF.

When you want to render the added content to the PDF, simply render the container view (which contains both the original document and annotations) to a PDF Context using UIGraphicsBeginPDFContextToFile and UIGraphicsBeginPDFPage.

Check this question and answer for a simple example and a method for ensuring that the PDF is rendered as vectors, not as a bitmap: Rendering a UIView into a PDF as vectors on an iPad - Sometimes renders as bitmap, sometimes as vectors

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top