Draw Custom Text and Image before page is shown - 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: Draw Custom Text and Image before page is shown

Draw Custom Text and Image before page is shown 1 year 4 months ago #12619

  • razvar
  • razvar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0
Hi,

How can I draw a custom image and text on top of a rendered page? I don't want to modify/add pdf content. Just draw something on top of a page like a watermark text and image (no interaction or actual pdf modification - just for view).

I see the render part in PDFVPage.m (-(bool)render:(PDFDIB *)dib :(PDFMatrix *)mat :(int)quality
) and I think this is where I can do my custom draw on each page. But not sure how to draw inside the PDFDIB after the render has finished rendering the actual page. Any help will be appreciated as I'm evaluating your library for iOS and this is the last thing I need to do with it and I will go ahead and purchase it.

Thanks.

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

Draw Custom Text and Image before page is shown 1 year 4 months ago #12623

  • razvar
  • razvar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0
Hi,

I've managed to draw on the page bitmap / create a bitmap from the rendered page. But I don't know how to submit my changes to the actual cashed PDFDIB.
So, inside the -(void)Render; of @implementation PDFVCache / PDFVPage.m I have draw on the page and saved it to disk for testing. But I don't know how to replace the actual PDFDIB /m_dib with my own changed one (ie with the CGImageRef/UiImage that I've just generated from the PDFDIB ) so that my custom text will show/display.

Any help with doing this will be much appreciated; here is my testing code:
-(void)Render;
{
    if( m_status == 2 ) return;
    if( !m_page )
        m_page = [m_doc page:m_pageno];
    if( m_dib == 0 )
    {
        PDFDIB *dib = [[PDFDIB alloc] init:m_dibw: m_dibh];
        [m_page renderPrepare:dib];
        m_dib = dib;
    }
    else
        [m_page renderPrepare:m_dib];
	if( m_status == 2 ) return;
    PDFMatrix *mat = [[PDFMatrix alloc] init:m_scale: -m_scale: 0: m_dibh];
    [m_page render:m_dib :mat :renderQuality];
    
    if (m_pageno==0) //render custom text on first page for testing
        {
            Byte *data = (Byte *)[m_dib data];
            int w = [m_dib width];
            int h = [m_dib height];
            CGDataProviderRef provider = CGDataProviderCreateWithData( NULL, data, w * h * 4, NULL );
            CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
            CGImageRef imageRef = CGImageCreate( w, h, 8, 32, w<<2, cs, kCGBitmapByteOrder32Little|kCGImageAlphaNoneSkipFirst, provider, NULL, FALSE, kCGRenderingIntentDefault );
            UIFont *font = [UIFont boldSystemFontOfSize:18];
            CGSize imgsize=CGSizeMake(w, h);
            NSString *WText=[NSString stringWithFormat:@"%s" , "custom watermark test text"];
    
            UIGraphicsBeginImageContext(imgsize);
            UIImage* uiImage = [[UIImage alloc] initWithCGImage:imageRef]; 
            [uiImage drawInRect:CGRectMake(0,0,w,h)];
            CGRect rect = CGRectMake(10, 10, w, h);
            [[UIColor redColor] set];
            [WText drawInRect:CGRectIntegral(rect) withFont:font];
    
            UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            // Create path.
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];
    
            // Save image for test.
            [UIImagePNGRepresentation(newImage) writeToFile:filePath atomically:YES];
          //HOW CAN I SAVE NOW MY IMAGE CHANGES TO m_dib/PDFDIB? HELP :-)
        }
    
    
    [self RenderFinish];
}

Thank you for your time.

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

Last edit: by razvar.

Draw Custom Text and Image before page is shown 1 year 4 months ago #12624

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 523
  • Karma: 20
  • Thank you received: 60
Hi,

if you want to draw on the page without changing the pdf content, you can take a look at DrawBmp method in PDFVCanvas class.
The first DrawBmp method draws the page, the second draws the thumbnail.
You can draw contents on pages like text or images in that method without changing the original pdf content.
The following user(s) said Thank You: razvar

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

Draw Custom Text and Image before page is shown 1 year 4 months ago #12627

  • razvar
  • razvar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0
Thanks a lot! That works as expected. Do you know how can I get the page number that is currently being draw from DrawBmp method?

Thanks again.

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

Draw Custom Text and Image before page is shown 1 year 4 months ago #12628

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 523
  • Karma: 20
  • Thank you received: 60
DrawBmp is called in Draw method of PDFVPage class where you can find the page number in m_pageno.
If you need the page number also in DrawBmp method, you can add it as parameter, something like:
-(void)DrawBmp : (PDFDIB *)dib : (int)pageno : (int)x :(int)y;
Then call for example:
[canvas DrawBmp: [m_cache Bmp]: m_pageno: m_x: m_y];
The following user(s) said Thank You: razvar

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

Draw Custom Text and Image before page is shown 1 year 4 months ago #12629

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 523
  • Karma: 20
  • Thank you received: 60
DrawBmp is called in Draw method of PDFVPage class where you can find the page number in m_pageno.
If you need the page number also in DrawBmp method, you can add it as parameter, something like:
-(void)DrawBmp : (PDFDIB *)dib : (int)pageno : (int)x :(int)y;
Then call for example:
[canvas DrawBmp: [m_cache Bmp]: m_pageno: m_x: m_y];

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum