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 6869555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:34:20+00:00 2026-05-27T03:34:20+00:00

I am having some trouble with saving a PDF page as UIImage…the pdf is

  • 0

I am having some trouble with saving a PDF page as UIImage…the pdf is loaded from the internet and it has one page(original PDF has been splitted in sever)…but the converted image sometimes is cropped…sometimes it is small and leave white space when it is putted on UIImageview…

here is the code

-(UIImage *)imageFromPdf:(NSString *) pdfUrl{

NSURL *pdfUrlStr=[NSURL URLWithString:pdfUrl];

CFURLRef docURLRef=(CFURLRef)pdfUrlStr;


UIGraphicsBeginImageContext(CGSizeMake(768, 1024)); //840, 960
NSLog(@"save begin");

CGContextRef context = UIGraphicsGetCurrentContext();

//CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("/file.pdf"), NULL, NULL);

CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(docURLRef);

NSLog(@"save complete");

CGContextTranslateCTM(context, 0.0, 900);//320

CGContextScaleCTM(context, 1.0, -1.0);

CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);

CGContextSaveGState(context);


CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, CGRectMake(0, 0, 768, 1024), 0, true);

CGContextConcatCTM(context, pdfTransform);

CGContextDrawPDFPage(context, page);

CGContextRestoreGState(context);

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext();

return resultingImage;

}

btw I have prepared my UIImageview by coding like this

self.PDFImageVIew.contentMode  = UIViewContentModeScaleAspectFit;
self.PDFImageVIew.clipsToBounds = YES;

I just want this image perfectly fitted on UIImageview and may be its reducing the quality of image…can you have suggesion how can I keep the quality also? please help and give me some suggestion

thanks

  • 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-27T03:34:20+00:00Added an answer on May 27, 2026 at 3:34 am
    CGContextTranslateCTM(context, 0.0, 900);//320
    
    • Here generally last parameter of translate operation should be the height of context or height of rectangle for which you creating image. So, i think it should be 1024(You have taken height of image context is 1024 so here i am assuming that status bar is not present). This may eliminate the issue of cropping. Some more things that i have noted on your code you should have to save the state of graphics before any operation on context. You have are saving it but after few operations.
    • Above code will try to make it height fit so if height of actual page is bigger than your context height then it will be scaled down. so you can obviously see white space around page.
    • One more thing if your original pdf page have white space in it then there is no way to eliminate it as far as i know.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working with a simple model and was having some trouble saving the
Been having some trouble implementing a single-column index in LaTeX. I've been employing the
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
I'm having some trouble saving some data after using PHP's simplexml_load_file function. I want
I'm trying to remove vowels from a text file and am having some trouble.
I am having some trouble importing a class from a particular module. The class
I'm having some trouble saving multiple entries in CakePHP. I'm not sure whether saveAll()
I'm having some trouble with my EF Code First model when saving a relation
I am having some trouble saving the state of my current view. Currenly I
Having some trouble with what should be a very simple scenario. For example purposes,

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.