Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:25:21+00:00 2026-06-02T08:25:21+00:00

I am developing an application in which i have to create multi page PDF

  • 0

I am developing an application in which i have to create multi page PDF the datas from plist and email such PDF. The content which is to be converted to PDF contains text as well as some images. I have seen some posts regarding this, but could not glean too much from it. Will be greatful if any one can guide in this.

here is my code for pdf creation done by me.

// create some sample data. In a real application, this would come from the database or an API. 
NSString* path = [[NSBundle mainBundle] pathForResource:@"sampleData" ofType:@"plist"];
NSDictionary* data = [NSDictionary dictionaryWithContentsOfFile:path];

NSLog(@"collections %@",data);
NSArray* students = [data objectForKey:@"Students"];
NSLog(@"collections students %@",students);



// get a temprorary filename for this PDF
path = NSTemporaryDirectory();

NSLog(@"path here %@",path);

self.pdfFilePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.pdf", [[NSDate date] timeIntervalSince1970]]];

NSLog(@"pdf file path and Name %@",self.pdfFilePath);

// Create the PDF context using the default page size of 612 x 792.
// This default is spelled out in the iOS documentation for UIGraphicsBeginPDFContextToFile
UIGraphicsBeginPDFContextToFile(self.pdfFilePath, CGRectZero, nil);

// get the context reference so we can render to it. 
CGContextRef context = UIGraphicsGetCurrentContext();

int currentPage = 0;

// maximum height and width of the content on the page, byt taking margins into account. 
CGFloat maxWidth = kDefaultPageWidth - kMargin * 2;
CGFloat maxHeight = kDefaultPageHeight - kMargin * 2;

// we're going to cap the name of the class to using half of the horizontal page, which is why we're dividing by 2
CGFloat classNameMaxWidth = maxWidth / 3;

// the max width of the grade is also half, minus the margin
CGFloat gradeMaxWidth = (maxWidth / 3) - kColumnMargin;
CGFloat yearMaxWidth = (maxWidth / 3) - kColumnMargin;


// only create the fonts once since it is a somewhat expensive operation
UIFont* studentNameFont = [UIFont boldSystemFontOfSize:17];
UIFont* classFont = [UIFont systemFontOfSize:15];

CGFloat currentPageY = 0;


UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
currentPageY = kMargin;

// iterate through out students, adding to the pdf each time. 
for (NSDictionary* student in students)
{

    // every student gets their own page 
    // Mark the beginning of a new page.


    NSString* title = [NSString stringWithFormat:@"Order List"];

    CGSize size2 = [title sizeWithFont:studentNameFont forWidth:maxWidth lineBreakMode:UILineBreakModeWordWrap];

    [title drawAtPoint:CGPointMake(kMargin, currentPageY) forWidth:maxWidth withFont:studentNameFont lineBreakMode:UILineBreakModeWordWrap];
    currentPageY += size2.height;

    CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
    CGContextMoveToPoint(context, kMargin, currentPageY);
    CGContextAddLineToPoint(context, kDefaultPageWidth - kMargin, currentPageY);
    CGContextStrokePath(context);

    // draw the student's name at the top of the page. 
    NSString* name = [NSString stringWithFormat:@"%@ %@", 
                      [student objectForKey:@"FirstName"], 
                      [student objectForKey:@"LastName"]];

    CGSize size = [name sizeWithFont:studentNameFont forWidth:maxWidth lineBreakMode:UILineBreakModeWordWrap];
    [name drawAtPoint:CGPointMake(kMargin, currentPageY) forWidth:maxWidth withFont:studentNameFont lineBreakMode:UILineBreakModeWordWrap];
    currentPageY += size.height;

    NSString* dob = [NSString stringWithFormat:@"Grade"];

    CGSize size1 = [name sizeWithFont:studentNameFont forWidth:maxWidth lineBreakMode:UILineBreakModeWordWrap];
    [dob drawAtPoint:CGPointMake(kMargin+ classNameMaxWidth + kColumnMargin, currentPageY) forWidth:maxWidth withFont:studentNameFont lineBreakMode:UILineBreakModeWordWrap];
    currentPageY += size1.height;

    NSString* year = [NSString stringWithFormat:@"Years"];

    CGSize size3 = [dob sizeWithFont:studentNameFont forWidth:maxWidth lineBreakMode:UILineBreakModeWordWrap];
    [year drawAtPoint:CGPointMake(kMargin+ classNameMaxWidth +gradeMaxWidth+ kColumnMargin, currentPageY) forWidth:maxWidth withFont:studentNameFont lineBreakMode:UILineBreakModeWordWrap];
    currentPageY += size3.height;

    // draw a one pixel line under the student's name
    CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
    CGContextMoveToPoint(context, kMargin, currentPageY);
    CGContextAddLineToPoint(context, kDefaultPageWidth - kMargin, currentPageY);
    CGContextStrokePath(context);

    // iterate through the list of classes and add these to the PDF. 
    NSArray* classes = [student objectForKey:@"Classes"];
    for(NSDictionary* class in classes)
    {
        NSString* className = [class objectForKey:@"Name"];
        NSString* grade = [class objectForKey:@"Grade"];
        NSString *year=[class objectForKey:@"Year"];

        // before we render any text to the PDF, we need to measure it, so we'll know where to render the
        // next line.
        size = [className sizeWithFont:classFont constrainedToSize:CGSizeMake(classNameMaxWidth, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];

        // if the current text would render beyond the bounds of the page, 
        // start a new page and render it there instead
        if (size.height + currentPageY > maxHeight) {
            // create a new page and reset the current page's Y value
            UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
            currentPageY = kMargin;
        }

        // render the text
        [className drawInRect:CGRectMake(kMargin, currentPageY, classNameMaxWidth, maxHeight) withFont:classFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];

        // print the grade to the right of the class name
        [grade drawInRect:CGRectMake(kMargin + classNameMaxWidth + kColumnMargin, currentPageY, gradeMaxWidth, maxHeight) withFont:classFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
       [year drawInRect:CGRectMake(kMargin +classNameMaxWidth*2+ kColumnMargin , currentPageY, yearMaxWidth, maxHeight) withFont:classFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];


        currentPageY += size.height;

    }


    // increment the page number. 
    currentPage++;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:25:24+00:00Added an answer on June 2, 2026 at 8:25 am

    You can use FDPF.
    http://www.fpdf.org/.

    Please go through the manual. If you face any problem in the way then please post .

    Happy to help you:-)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application in which i have to get data from .xls
I am developing android application in which i have to open option menu from
I am developing application in which i have to create url request when server
i'm developing a java application in which i have a JFrame with a JDesktopPane
I am developing an application which requires to add Calendar event. I have written
Hai every one I am developing an windows application in which i have to
I am developing an application in C# WPF which will have Client-Server architecture (Client
I'm developing a window application in C# VS2005. I have a dataGridView in which
In an application we are developing, I have access to a database table which
I have a project (Web Application) which I have been developing in C#/ASP.NET, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.