Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-01-2011, 02:03 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Falkensee, Germany
Posts: 23
HHuckebein is on a distinguished road
Default Shrink PDF Document Size/Writing footer

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 drawPageNumberdfContext 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
HHuckebein is offline   Reply With Quote
Old 11-01-2011, 02:13 AM   #2 (permalink)
Kenya Safari Packages
 
Join Date: Sep 2011
Location: P.O. BOX NO: 13536, GPO: 00800, NAIROBI, KENYA
Posts: 1
escapetoafrica is on a distinguished road
Default Reply to Thread

Nice Information for sharing for the Code.
I think i have use in my live site, then the i show the effects "OK"

Thank You.
escapetoafrica is offline   Reply With Quote
Reply

Bookmarks

Tags
pdf, quartz2d

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
12 members and 388 guests
13dario13, 7twenty7, buggen, EvilElf, j.b.rajesh@gmail.com, LunarMoon, morterbaher, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0