Hi community,
I've got 2 questions concerning the generation of pdf documents.
1. Shrinking PDF Document size
The document page I generate consist of a base document (pdf template) and the text I draw on top.
That leads to the situation that the final document is quite large.
As the base document is always the same I wonder if there is a way to store that template only once
and use a reference.
2. Writing footer
The number of pages varies so during page generation I don't know what the final number of pages is.
I tried to open the pages again and writing the footer but my approach wasn't successful.
UIGraphicsBeginPDFContextToFile(pdfFilePath, CGRectZero, (NSDictionary *)auxiliary);
UIGraphicsBeginPDFPageWithInfo(mediaRect, nil);
.. drawing stuff
[self drawPageNumber

dfContext document:baseDocument maxNumberOfPages:currentPage];
UIGraphicsEndPDFContext();
The pageRef I receive for i=1 is actually the last page ref all further pageRef's are NULL.
So I guess that code is completely wrong
Code:
- (void)drawPageNumber:(CGContextRef)context document:(CGPDFDocumentRef)document maxNumberOfPages:(NSInteger)maxNumberOfPages
{
int rotation = 0;
bool preserveAspectRatio = YES;
CGRect mediaRect = CGRectMake(0, 0, kMaxX_DIN_A4, kMaxY_DIN_A4);
CGPDFBox box = kCGPDFMediaBox;
for (int i = 1; i <= maxNumberOfPages; i++) {
CGPDFPageRef pageRef = CGPDFDocumentGetPage(document, i);
CGContextSaveGState(context);
// make a drawing transform with respect to rect, rotation, preserveAscpectRation for the mediabo
CGAffineTransform m = CGPDFPageGetDrawingTransform (pageRef, box, mediaRect, rotation, preserveAspectRatio);
CGContextConcatCTM (context, m);
CGContextClipToRect (context,CGPDFPageGetBoxRect (pageRef, box));
NSString *pageNumber = [NSString stringWithFormat:@"Seite %d von %d", i, maxNumberOfPages];
[pageNumber drawInRect:CGRectMake(350, kMaxY_DIN_A4 - kYOriginMinimum, 150, 10) withFont:[UIFont systemFontOfSize:kOfferNormalFontSize] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentRight];
CGContextRestoreGState(context);
}
}
I've to confess that I'm not the pdf expert.
Thx.
Bernd