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

  • Home
  • SEARCH
  • 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 581941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:38:00+00:00 2026-05-13T14:38:00+00:00

I herewith a problem that i am facing while implementing PDF file in iPhone.

  • 0

I herewith a problem that i am facing while implementing PDF file in iPhone.

What I want is simply display PDF files. and also Giving few Facilities like Zoom-in and Zoom-Out, Next Page navigation, Previous Page Navigation etc.

I am very clear with Reading PDF Documents using url, i also get the number of pages and other property, But When i try to display it in View or WebView, i mean to say when i try to draw a pdf page, I am not getting page, just get simply blank View.

To Display page, I tried 5 different approaches, but none of them leads me to Success. Hence i have to approach You Guys.

I have attached here snippet of Code with 5 different approach i used.

Kindly go through it and guide me!! Your Suggestions are welcomed.

////////////////////////////

- (void)viewDidLoad {
    [super viewDidLoad];

 const char *file = @"Pdf_first.pdf";

 CGPDFDocumentRef myDocument;
 CGPDFPageRef page;
 CGRect mediaBox;
  CFStringRef path;
 size_t noOfPages;
    CFURLRef url;
 CGContextRef pdfContext;



//////// Code to get Path and Url for the dictionary where our PDF file currently stored. /////////

 NSFileManager *FileManager = [NSFileManager defaultManager];
 NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths1 objectAtIndex:0];
 documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Pdf_first.pdf"];

 path = documentsDirectory;

    url = CFURLCreateWithFileSystemPath (NULL, path,kCFURLPOSIXPathStyle, 0);
 myDocument = CGPDFDocumentCreateWithURL(url);
 myDocument = CGPDFDocumentRetain(myDocument);


 CFMutableDictionaryRef myDictionary = NULL;
 myDictionary = CFDictionaryCreateMutable(NULL, 0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
 CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
 CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));



 page = CGPDFDocumentGetPage(myDocument, 1);
 noOfPages = CGPDFDocumentGetNumberOfPages(myDocument);
 pdfContext = CGPDFContextCreateWithURL(url, NULL, myDictionary);
 CGRect pageMediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); 

//////// Code to get Path and Url for the dictionary where our PDF file currently stored. /////////

Every Thing is fine here!! i am Getting all Values from Functions. Now Bellow i have added 5 different ways Those
i Follow for Displaying or Drawing a Page That i can see in iphone.

////////////////////////// Way 1 ///////////////////////

 CGContextTranslateCTM(pdfContext, 0.0, [webView bounds].size.height);
 CGContextScaleCTM(pdfContext, 1.0, -1.0);
 CGContextConcatCTM(pdfContext, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox,[webView bounds], 0, true));
 CGContextDrawPDFPage(pdfContext, page);    
 CGContextRestoreGState(pdfContext);

 ////////////////////////// Way 1 ///////////////////////


////////////////////////// Way 2 ///////////////////////

 CGRect bounds = CGRectMake(10, 10, 300, 300);

 CGContextSaveGState(pdfContext);
 CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, bounds, 0, true);
 CGContextConcatCTM(pdfContext, pdfTransform);
 CGContextDrawPDFPage(pdfContext, page);
 CGContextRestoreGState(pdfContext);

 ////////////////////////// Way 2 ///////////////////////

///////////////////////////////////// Way 3 ////////////////////


    for(int i = 1; i <= noOfPages; ++i) {

        CGPDFPageRef pdfPage =  CGPDFDocumentGetPage(myDocument, i);

        CGRect pageMediaBox = CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox); 

        CGContextBeginPage (pdfContext, &pageMediaBox); 

  CGContextStrokeRect(pdfContext, CGRectMake(50, 50, 500,700)); 
  CGContextShowTextAtPoint (pdfContext, 60, 699, text, strlen(text));

  CGContextDrawPDFPage(pdfContext, pdfPage);

        CGContextEndPage (pdfContext); 

    }

  ///////////////////////////////////// Way 3 ////////////////////

 /////////////////////////////// Way 4 ////////////////////////////////

 //mediaBox = CGPDFDocumentGetMediaBox(document, 1);

 CGPDFBox mediaBox = CGPDFDocumentGetMediaBox(document, 1);

 //mediaBox = CGRectMake(10,10,300,300);
 // int rotationAngle = CGPDFDocumentGetRotationAngle(document, 1);

 int rotationAngle = 30;

 //CGContextDrawPDFDocument(UIGraphicsGetCurrentContext(), CGRectMake(25,25,250,250), document, 1);

 //CGPDFPageGetDrawingTransform(<#CGPDFPageRef page#>, <#CGPDFBox box#>, <#CGRect rect#>, <#int rotate#>, <#_Bool preserveAspectRatio#>)

 CGAffineTransform transform = CGPDFPageGetDrawingTransform(page, mediaBox, CGRectMake(25, 25, 250,250), rotationAngle, TRUE);


   /////////////////////////////// Way 4 ////////////////////////////////

///////////////////////// Way 5 /////////////////////////////

 CGContextTranslateCTM(pdfContext, 0.0, 320);

 CGContextScaleCTM(pdfContext, 1.0, -1.0);

 CGContextSaveGState(pdfContext);

 CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, CGRectMake(0, 0, 280, 320), 0, true);

 CGContextConcatCTM(pdfContext, pdfTransform);

 CGContextDrawPDFPage(pdfContext, page);

 CGContextRestoreGState(pdfContext);

    ///////////////////////// Way 5 /////////////////////////////

Among above 5 diffent way not single one lead me to Result.

  • 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-05-13T14:38:01+00:00Added an answer on May 13, 2026 at 2:38 pm

    You can’t draw your view in -viewDidLoad. There’s no CGContext at this point. All your drawing code needs to go into -drawRect. You want to read the Drawing Guide.

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

Sidebar

Ask A Question

Stats

  • Questions 396k
  • Answers 396k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer <?php $str = "Lorem http://myyn.org dolor sit amet, http://google.com adipisicing… May 15, 2026 at 2:53 am
  • Editorial Team
    Editorial Team added an answer I've actually realized the problem is that public/ is not… May 15, 2026 at 2:53 am
  • Editorial Team
    Editorial Team added an answer The onclick will run first. If onclick doesn't return false… May 15, 2026 at 2:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.