Skip to content

increase margin for first page #41

@mrhaxic

Description

@mrhaxic

Hi

I used this class to print pdf from HTML string, I need to add header only for the first page and increase the TOP MARGIN only for the first page how could I do like this ?

Code edited as below:

- (NSData*) printToPDF
{
    NSMutableData *pdfData = [NSMutableData data];
    
    UIGraphicsBeginPDFContextToData( pdfData, self.paperRect, nil );
        
    [self prepareForDrawingPages: NSMakeRange(0, self.numberOfPages)];
    
    CGRect bounds = UIGraphicsGetPDFContextBounds();
        
    for ( int i = 0 ; i < self.numberOfPages ; i++ )
    {
        UIGraphicsBeginPDFPage();
        
        [self drawPageAtIndex: i inRect: bounds];
        [self drawFooterForPageAtIndex:i inRect:bounds];
        
        if (i == 0) {
            [self drawHeaderForPageAtIndex:i inRect:bounds];

        }
    }
    
    UIGraphicsEndPDFContext();
        
    return pdfData;
}

-(void)drawHeaderForPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)headerRect {
    
    CGPoint startPoint = CGPointMake(headerRect.origin.x, headerRect.origin.y + headerRect.size.height - 1);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    
    
    CGContextBeginPath(context);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextMoveToPoint(context, startPoint.x + 5, 50);
    CGContextAddLineToPoint(context, headerRect.size.width - 5, 50);
    CGContextStrokePath(context);

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions