Frequently Asked Question

Draw bitmap with transparent background (iOS)
Last Updated 11 months ago

You can use the below code to draw a bitmap with transparent background, drawing the image as page content:

    // 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:200 :200 :100 :100];

    [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]; 

Loading ...