My app shows PDF files using the PDFKit and lets users make annotations on pdf files through my own code using UIKit
and CoreGraphics
frameworks. Since I would like to use the PencilKit framework to make annotations better, I’m in the process to implement the PencilKit
framework but I’ve found some issues which I am stuck with.
What I did is to add a PKCanvasView
over the DocumentView
of a PDFView. In essence, it works fine, I can annotate using the tools of the PencilKit
and I can navigate through the pages of the PDF.
The problem appears when I zoom-in on a PDF page. Since the PKCanvasView
is not zooming itself as it’s inside the DocumentView
, the ink annotations appear pixelated. The PKCanvasView
is not redrawing its content with a new scale because its zoom has not changed and updating the contentScaleFactor
to make the drawing sharper doesn’t work.
Another problem is, in some way related to the previous one, since the app fits each PDF page to use all the screen, this makes the zoom of the UIScrollView
, which contains the DocumentView
of the PDFView, vary in function of the size of the PDF page. This makes that if I open a PDF which has small pages and another with large pages, in terms of size (Width x Height), I will see the width of the lines of the inking tool with different sizes even if I have selected the smallest line width on the PKToolPicker
for both files.
So I wonder if it could be possible to add a PKCanvasView
and a PDFView separately to a UIViewController’s
view, so they both have the same superview
, with the same ContentSize and maximum/minimum zoom level and, when panning and zooming on the PKCanvasView
, the PDFView does too.
Anyway, if there's a workaround I would be happy to know. ;)