Add an Image on PDF - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about iOS development and PDF
  • Page:
  • 1
  • 2

TOPIC: Add an Image on PDF

Add an Image on PDF 1 year 6 months ago #12370

  • Pja
  • Pja's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Hi,

How do I add an Image on a page of document?

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

Add an Image on PDF 1 year 6 months ago #12371

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 512
  • Karma: 15
  • Thank you received: 56
Hi,

you can take a look at this Knowledge Base article: http://www.radaeepdf.com/support/knowledge-base?view=kb&tmpl=component&kbartid=28

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

Add an Image on PDF 1 year 6 months ago #12382

  • Pja
  • Pja's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
I tried using the given method, but this doesn't add the image on the document.
This adds the note image on the document.. But i need the image to be added directly on the document.
Is there any solution for this?

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

Add an Image on PDF 1 year 6 months ago #12383

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 512
  • Karma: 15
  • Thank you received: 56
Hi,

here is a quick sample of how to add an image as resource and draw it on a page:
    // Get page
    PDFPage *page = [m_doc page:0];
    
    // Create page content
    PDFPageContent *content = [[PDFPageContent alloc] init];
    
    // Get the image to add
    UIImage *img = [UIImage imageNamed:@"image"];
    
    // Create a Doc Image instance
    PDFDocImage *image = [m_doc newImage:img.CGImage :YES];
    
    // Add the image as page resource
    PDF_PAGE_IMAGE rimg = [page addResImage:image];
    [content gsSave];
    
    // Set the matrix (image position/size on page)
    PDFMatrix *matrix = [[PDFMatrix alloc] init:20 :20 :0 :0];
    [content gsCatMatrix:matrix];
    matrix = nil;
    
    // Draw the image on page content
    [content drawImage:rimg];
    [content gsRestore];
    
    // Add the content on the page
    [page addContent:content :false];
    
    // Save the file
    [m_doc save];

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

Add an Image on PDF 1 year 5 months ago #12385

  • Pja
  • Pja's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Hi Emanuele,

I am using the given method to add the image
// Create the cache file
NSString *tp = NSTemporaryDirectory();
tp = [tp stringByAppendingPathComponent:@"cache.dat"];
[m_doc setCache:tp];

// Create the PDFPage instance of the current page
PDFPage *page = [m_doc page:m_cur_page];

// Create the CGImageRef of the image
CGImageRef ref = [[UIImage imageWithData:imageData] CGImage];

//NSString *path = @"path_to_image";
//PDFDocImage *i = [m_doc newImageJPEG:path];

// Get PDFDocImage instance from CGImageRef (keeping alpha channel)
PDFDocImage *i = [m_doc newImage:ref :YES];

// Define the image rect
PDF_RECT rect;

rect.left = 100;
rect.right = 157;
rect.top = 100;
rect.bottom = 157;

// Add the image

[page addAnnotBitmap:i :&rect];


// Re-render the current page
[m_view vRenderSync:m_cur_page];
[self refresh];
Here i am getting one problem, only with the rect used in the method the image is plotted at the bottom left corner of the page.
When i change any of the rect value the image is not seen.
Can you please explain me the significance of the Rect or what values should i provide to the rect?
I need to add the image at the point where i have long pressed on the pdf.

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

Add an Image on PDF 1 year 5 months ago #12402

  • Pja
  • Pja's Avatar Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
Any updates?

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum