title: SwiftUI View export to PDF margin question - UIGraphicsPDFRenderer
body: <p>I am trying to export a simple SwiftUI View to PDF using UIGraphicsPDFRenderer.</p>
  <p>swiftui view:</p>
  <p><img src="https://i.stack.imgur.com/VQ2Dx.png" alt="swiftui view" /></p>
  <p>The problem I am getting is a blank margin/space appears on top of the exported PDF.</p>
  <p>PDF export:</p>
  <p><img src="https://i.stack.imgur.com/QUiSU.png" alt="pdf export" /></p>
  <p>The code I am using</p>
  <pre><code>import SwiftUI 
  struct ContentView: View {     
  var body: some View {         
  let pressGesture = TapGesture()
             .onEnded { value in
                 let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
                 let outputFileURL = documentDirectory.appendingPathComponent(&quot;SwiftUI.pdf&quot;)
                 let pdfVC = UIHostingController(rootView: self)
                 let pageSize = CGSize(width: 2.625 * 72.0, height: 1.0 * 72.0)
                 pdfVC.view.frame = CGRect(origin: .zero, size: pageSize)
                 let rootVC = UIApplication.shared.windows.first?.rootViewController
                 rootVC?.addChild(pdfVC)
                 rootVC?.view.insertSubview(pdfVC.view, at: 0)
                 let pdfRenderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: pageSize.width, height: pageSize.height))
                 DispatchQueue.main.async {
                      do {                                                    
                          try pdfRenderer.writePDF(to: outputFileURL, withActions: { (context) in
                              context.beginPage()
                              pdfVC.view.layer.render(in: context.cgContext)
                          })
                          print(&quot;wrote file to: (outputFileURL.path)&quot;)
                          pdfVC.removeFromParent()
                          pdfVC.view.removeFromSuperview()                     
                      } catch {
                          print(&quot;Could not create PDF file: (error.localizedDescription)&quot;)
                      }
                  }                
             }
      VStack(){
              Text(&quot;Hello&quot;)
      }
      .frame(width: 2.625 * 72.0, height: 1.0 * 72.0, alignment: .center)
      .gesture(pressGesture)
      .background(Color.red)
  }
  </code></pre>
  <p>}</p>
  <p>May I know what am I doing wrong? Thanks in advance.</p>