5

I have one PDF Kit I want to save the File in A4 Size

here is my code

let newPagetxt = PDFPage(image:image!)

let apdf = PDFDocument()
apdf.insert(newPagetxt!, at:index)

apdf.documentAttributes!["Title"] =  sampleFilenameTitle
apdf.documentAttributes!["Author"] = sampleFilenameAuthre
apdf.write(to: destination)

how can to set te size in A4 with one Standard Class

Vladislav Kovalyov
  • 763
  • 10
  • 24

1 Answers1

10

In one of my projects, I used this way.

  if let pdfPage = PDFPage(image: image) {

     let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8) // A4, 72 dpi
     pdfPage.setBounds(page, for: PDFDisplayBox.artBox)

     let pdfDoc = PDFDocument()
     pdfDoc.insert(pdfPage, at: 0)
     // Some code to save the doc...
  }
Tim S
  • 136
  • 1
  • 4