Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1

TOPIC:

Get View,Context,Image of PDFPage 9 years 8 months ago #6864

  • Mahesh007
  • Mahesh007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 16
  • Thank you received: 0
I want to show all pdf page in gridvieww (Collection view). how to get view,context,image or any nsdata from PDFPage so we show all pages in gridview.please reply asap.

Please Log in or Create an account to join the conversation.

Get View,Context,Image of PDFPage 9 years 8 months ago #6866

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
step 1. create PDFDIB object for render, and invoke [PDFPage renderPrepare];
step 2. render the page to PDFDIB object using [PDFPage render];
step 3. create CGImage like:
Byte *data = (Byte *)[dib data];
int w = [dib width];
int h = [dib height];
CGDataProviderRef provider = CGDataProviderCreateWithData( NULL, data, w * h * 4, NULL );
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGImageRef img = CGImageCreate( w, h, 8, 32, w<<2, cs, kCGBitmapByteOrder32Little|kCGImageAlphaNoneSkipFirst, provider, NULL, FALSE, kCGRenderingIntentDefault );
step 4. set CGImageRef to image view of cell.

notice: step 1 - 3 can be run on backing thread, and do not release PDFDIB object till CGImageRef object not used.

Please Log in or Create an account to join the conversation.

Get View,Context,Image of PDFPage 9 years 8 months ago #6870

  • Mahesh007
  • Mahesh007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 16
  • Thank you received: 0
i am using your step but this gives me blank image. please help on this.


PDFDIB *dib = [[PDFDIB alloc] init:100 :100];
PDFMatrix *mat = [[PDFMatrix alloc] init:10 :10 :100 :100];
[page renderPrepare:dib];
[page render:dib :mat :1];
Byte *data = (Byte *)[dib data];
int w = [dib width];
int h = [dib height];
CGDataProviderRef provider = CGDataProviderCreateWithData( NULL, data, w * h * 4, NULL );
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGImageRef img = CGImageCreate( w, h, 8, 32, w<<2, cs, kCGBitmapByteOrder32Little|kCGImageAlphaNoneSkipFirst, provider, NULL, FALSE, kCGRenderingIntentDefault );
UIImage *image = [UIImage imageWithCGImage:img];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[self saveImage:image withFileName:@"mahesh" ofType:@"jpeg" inDirectory:documentsDirectory];

Please Log in or Create an account to join the conversation.

Get View,Context,Image of PDFPage 9 years 8 months ago #6871

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
parameters are wrong.
codes like this:
int pageNO = 0;
float scale = 1.2f;
int width = [PDFDoc pageWidth:pageNO] * scale;
int height = [PDFDoc pageHeight:pageNO] * scale;
PDFDIB *dib = [[PDFDIB alloc] init:width :height];
PDFMatrix *mat = [[PDFMatrix alloc] init: scale : -scale : 0 : height ];
[page renderPrepare:dib];
[page render:dib :mat :1];
...
The following user(s) said Thank You: felipe1234

Please Log in or Create an account to join the conversation.

Last edit: by .

Get View,Context,Image of PDFPage 9 years 8 months ago #6873

  • Mahesh007
  • Mahesh007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 16
  • Thank you received: 0
Thanks for help..

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum