title: How do I draw something on a PDF in Swift?
body: <p>Here is what I am doing currently.</p>
  
  <p>First, I get the document. Next I create a PDF View and assign the document to the view. Then I create a view and do my drawing in the view, then add the view to the PDFView as a subview. Then I convert the PDFView to data, then to PDF document. Since I'm doing the drawing on the first page of the PDF, I remove the first page from the original PDF, insert the new first page, and return the document.</p>
  
  <pre><code>guard let document = PDFDocument(url: url) else { return nil }
  guard let page = document.page(at: 0) else { return nil }
  let pageBounds = page.bounds(for: .mediaBox)
  
  let pdfView = PDFView(frame: pageBounds)
  pdfView.document = document
  pdfView.enclosingScrollView?.autohidesScrollers = true
  
  let view = /// code for subview that I am drawing on
  pdfView.addSubview(view)
  
  let data = pdfView.dataWithPDF(inside: pageBounds)
  guard let pdf = PDFDocument(data: data) else { return nil }
  
  document.removePage(at: 0)
  document.insert(pdf.page(at: 0)!, at: 0)
  return document
  </code></pre>
  
  <p>Is there a better way to do this? To add a wrinkle, my final product has a weird scroll bar image (see Screenshot). I tried adding auto hide scrollers &amp; enclosingScrollView?.hasVerticalScroller = false but neither seem to hide the scroll bar. </p>
  
  <p>Thanks in advance!</p>
  
  <p><a href="https://i.stack.imgur.com/nLyKU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nLyKU.png" alt="Scroll Bar Img"></a> </p>