Check Mobile App
Read now

Create PDF view programmatically using PDFKit in swift.

Save

In the article, I will discuss, how we can create PDF programmatically using the PDFKit framework.

First of all, The PDFKit is a framework available in AppKit since iOS 11.0 and macOS 10.4. Please click here to read more about PDFKit.

PDFView is mainly used to show the pdf file in our application and also it allows users to set zoom level, select content, navigate through a document, and copy the textual content to the Pasteboard, and also keeps track of page history.

Getting Started

Swift version: 5
iOS version: 13
Xcode: 11.3

First Create a project from Xcode.

File ▸ New ▸ Project…. Choose the iOS ▸ Application ▸ Single View App template and create a new project.

Then create a PDFCreator class where we will add all functions and variables which helps us to create the PDF.

Now we will add basic variables that manage the PDF layout.

pageWidth : To define page width of PDF.

pageHeight : To define page Height of PDF.

marginPoint : To define the page margin of PDF.

currentPage : To Store page count of the PDF.

Now create a function that creates the actual PDF data.

Now add a page footer in the PDF.

And, Now show this PDF Data in the ViewController.

 

PDF Screenshot

 

I hope this code will help you better to understand how PDF generates. If you feel any doubt or query please comment below.

Thank you.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Dipesh
    Can you link you git project how you have worked it , tried same but could not get something working
    • Debabrata Roy (Moderator)
      We don’t have any git project for this blog. please share issue details here, we will help you to fix it.
  • css.php

    Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

    Deniel Kerr

    Owner and Founder. Opencart

    Talk to Sales
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home