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

TOPIC:

Writing Annot data to image 8 years 3 months ago #9986

  • mobileAsd
  • mobileAsd's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 25
  • Thank you received: 0
Hi,

We are using below code to output our pdf doc to images, however it seems all annot data cannot be written, is there any step we are missing? Please advise, thanks.

int totalPage = Document_getPageCount(pdfDoc);
NSMutableArray *imgDataList = [NSMutableArray arrayWithCapacity:totalPage];

for (int i=0; i<totalPage; i++) {
PDF_PAGE page = Document_getPage(pdfDoc,i);
int w = Document_getPageWidth(pdfDoc,i);
int h = Document_getPageHeight(pdfDoc,i);

PDF_DIB m_dib = NULL;
PDF_DIB bmp = Global_dibGet(m_dib, w, h);
PDF_MATRIX mat = Matrix_createScale(1, -1, 0, h);
Page_renderPrepare( page, bmp );
Page_render(page, bmp, mat,false,1);
Matrix_destroy(mat);

void *data = Global_dibGetData(bmp);

Page_close(page);


CGDataProviderRef provider = CGDataProviderCreateWithData( NULL, data, w * h * 4, NULL );
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGImageRef m_img = CGImageCreate( w, h, 8, 32, w<<2, cs, kCGBitmapByteOrder32Little|kCGImageAlphaNoneSkipFirst, provider, NULL, FALSE, kCGRenderingIntentDefault );
UIImage *img = [UIImage imageWithCGImage:m_img];

[imgDataList addObject:img];
CGColorSpaceRelease(cs);
CGDataProviderRelease( provider );

}
if(pdfDoc)
{
Document_close(pdfDoc);
}
for (int i=0; i<[imgDataList count]; i++) {
NSString *imgOutputPath = [outputDir stringByAppendingString:resultantFileName];
[UIImageJPEGRepresentation((UIImage *)[imgDataList objectAtIndex:i], 1) writeToFile:imgOutputPath atomically:YES];
}

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

Writing Annot data to image 8 years 3 months ago #9987

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Hi,

when you call Page_render, you have to set the bool value to true: Page_render(page, bmp, mat,true,1);
As written in the method declaration's, it is show_annots bool.
The following user(s) said Thank You: mobileAsd

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

Writing Annot data to image 8 years 3 months ago #9989

  • mobileAsd
  • mobileAsd's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 25
  • Thank you received: 0
Thank you, it works. Didn't realize the setting as just copy from the sample app

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

  • Page:
  • 1
Powered by Kunena Forum