![]() let firstPDFDocument = PDFDocument(url: URL_TO_YOUR_FIRST_DOC) let secondPDFDocument = PDFDocument(url: URL_TO_YOUR_SECOND_DOC) One where the page would be inserted, and another from which we’ll take the page to insert. To add or remove pages to/from PDF document we need to use Apple’s PDFKit methods.įirst, you need to initialize 2 PDF documents. You must add try? call because writing operation is throwable. pdfData method of your renderer: let data = renderer.pdfData let pageRect = CGRect(x: 0, y: 0, width: 595, height: 842) let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format) Page dimensions would be: // US Letter Width: 8.5 inches * 72 DPI = 612 points Height: 11 inches * 72 DPI = 792 points // A4 would be 595 x 842 pointsĪfter doing this math, we need to instantiate UIGraphicsPDFRenderer object, which is responsible of document rendering. PDF documents use a default resolution of 72 DPI. Second, we need to calculate PDF page dimensions. You’ll find a full list of available metadata parameters in CoreGraphics framework reference documentation, just start typing kCGPDF in your code in Xcode. let format = UIGraphicsPDFRendererFormat() let metaData = format.documentInfo = metaData as There are few simple UIKit methods for that.įirst, you need to create UIGraphicsPDFRendererFormat object to provide PDF document metadata such as author, etc. ![]() In case you need to create a new PDF file on iOS device you won’t actually need to use PDFKit at all.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |