title: Show PDF in iOS from pdf data
body: <p>I'm trying to show a pdf in my iOS app using Swift. The response I get from the server is the pdf data and it's looking like this:</p>
  
  <blockquote>
    <p>%PDF-1.4 %ÓôÌá 1 0 obj &lt;&lt; /CreationDate(D:20180403085232+02'00') /Creator(PDFsharp 1.32.3057-g (www.pdfsharp.net)) /Producer(PDFsharp 1.32.3057-g (www.pdfsharp.net)) endobj 2 0 obj &lt;&lt; /Type/Catalog /Pages 3 0 R endobj 3 0 obj &lt;&lt; /Type/Pages /Count 3 /Kids[4 0 R 8 0 R 11 0 R] endobj 4 0 obj &lt;&lt; /Type/Page /MediaBox[0 0 612 792] /Parent 3 0 R /Contents 5 0 R /Resources &lt;&lt; /ProcSet [/PDF/Text/ImageB/ImageC/ImageI] /XObject &lt;&lt; /I0 6 0 R /ExtGState &lt;&lt; /GS0 7 0 R
    /Group &lt;&lt; /CS/DeviceRGB /S/Transparency /I false /K false
    endobj 5 0 obj &lt;&lt; /Length 260 /Filter/FlateDecode stream xœíRMK1½÷Wä˜M“&amp;MîÂ¢àa]oâIEDF‚¿ÞÌÌº²ø¥”4y¯—´C©@¹ŽÆÐƒáú!ÏDpñZ†2€š W9#¾g­NŽa“/…à4÷}©gåòŠàf§{¾.«õ–àî¹ˆWìÚ¡WÆT4Bµ †¡O·e[F>g^í=|UEw‡ª‚Ö$å(U‘ôÇ›„L¶ÜÑ™—~¤6•š'Ú9f”Pz›PŽ€¦¨"Ð±v_gly›Û÷Mä~.î] ™ÛëØˆ?œå€«Ul¡À™y_6þ»Aÿ—ÿ¤|èYòÿX`ìfÈ»ï³ÉõŠ¹·ò endstream endobj 6 0 obj &lt;&lt; /Type/XObject /Subtype/Image /Length 5097196 /Filter/FlateDecode /Width 2511 /Height 3531 /BitsPerComponent 8 /ColorSpace/DeviceRGB /Interpolate true stream xœìÝ œ¤g]'ðîº«ïé9rÂáˆJAE%€ Š"ë‚FQ0 Ë!º» ¢‚+^ (h</p>
  </blockquote>
  
  <p>I checked <a href="https://github.com/Alua-Kinzhebayeva/iOS-PDF-Reader" rel="nofollow noreferrer">iOS-PDF-Reader</a> and PDFKit but the main problem is that I don't understand how I can handle the response in the app. </p>
  
  <pre><code>fileprivate func loadPdf() {
      startIndication()
      var session: URLSession!
      let sessionConfig = URLSessionConfiguration.default
      session = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
  
      guard let URL = URL(string: "http://localhost:3000/pdf-download") else { return }
  
      let token = "Bearer " + self.user!.token!
  
      var request = URLRequest(url: URL)
      request.httpMethod = "POST"
      request.addValue("application/json", forHTTPHeaderField: "Content-Type")
      request.addValue(token, forHTTPHeaderField: "Authorization")
      var invData:[String:Any] = [String:Any]()
      invData["INVID"] = invoice.ID
      request.httpBody = try! JSONSerialization.data(withJSONObject: invData, options: [])
  
      let task = session.dataTask(with: request) { (data:Data?, response: URLResponse?, error:Error?) in
  
          if error == nil {
  
              guard let data = data else { return }
  
              // I get the data but I cannot do anything with it
  
          } else {
              print("response: \(String(describing: error))")
          }
      }
      task.resume()
  }
  </code></pre>
  
  <p>Any ideas? Thanks!</p>