![]() #Pdfkit swift pdfConfiguring the ContextĪs a next step, we are going to implement a function that takes a cocktail, extracts all the relevant information, and using the previous extensions, adds it to the context. Go to ViewController.swift and add the following inside a new function called generatePDFData () Now that we have a function that creates the PDF we need by configuring the context, all we have left to do is get the cocktails from our API and pass them to this function. This is especially useful for apps that need to generate receipts, bills, invoices or any other confidential or important documents. ![]() PDF is useful so we can generate files that cannot be modified and shared or sent to others. After doing so, we use the function 4 ( checkContext()) that will check if our text is exceeding the bounds of the page, and if so, start a new page dynamically and reset the cursor.įinally, the function 5 calculates the height of a multi-line sentence, so that we know where the text ends and where to start the next paragraph. PDFKit is the framework by Apple that you need to display and manipulate PDF files in your app. We then use the indent and Page Size parameters to place our string in a CGRect described by the function definition (centered, single line left aligned, and multi-line left aligned). ![]() In the implementation of functions 1, 2 and 3, attributes are assigned to our text in an Attributed String variable. 1) In this section, we are going to modify various display texts from Image to PDF so that users are going to manage PDF files instead of meals. These methods are added as an extension to UIGraphicsPDFRendererContext, which is the context that is going to render our PDF.Īll we have to do is dictate to the context everything we need our PDF to have (PDF metadata, PDF dimensions, page breaks, and of course the text we are going to present on the document). ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |