开发者

simple create pdf file with hard code

I have generated pdf programatically bt problem is text doesnt appear in pdf. PLz provide me simple example of pdf creator.

This is my code :

-(void) MyCreatePDFFile //(CGRect pageRect, const char *filename)// 1
{

 CGRect pageRect=CGRectMake(10,10,400,600);
 const char *filename="/Users/msoni/Desktop/my.pdf";

    CGContextRef pdfContext;

    CFStringRef path;

    CFURLRef url;

    CFMutableDictionaryRef myDictionary = NULL;

 //const char *filename="a.pdf";

    path = CFStringCreateWithCString (NULL, filename,kCFStringEncodingUTF8);

    url = CFURLCreateWithFileSystemPath (NULL, path,kCFURLPOSIXPathStyle, 0);

    CFRelease (path);

    myDictionary = CFDictionaryCreateMutable(NULL, 0,

            &kCFTypeDictionaryKeyCallBacks,

            &kCFTypeDictionaryValueCallBacks); // 4

    CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));

    CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));

    pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary); // 5

    CFRelease(myDictionary);

    CFRelease(url);

    CGContex开发者_JS百科tBeginPage (pdfContext, &pageRect); // 6
 CGContextStrokeRect(pdfContext, CGRectMake(20, 100, 200,300));
 const char *text = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem";
 CGContextShowTextAtPoint (pdfContext, 100, 400, text, strlen(text));
 //CGContextSetTextDrawingMode (pdfContext);
 CGContextEndPage (pdfContext);// 8

    CGContextRelease (pdfContext);// 9

}

waiting for reply..

thank


use the below code and url for this tutorial is link text http://www.iphonedevsdk.com/forum/tutorial-requests/8560-tutorial-request-creating-pdf-file-iphone-app.html

nameText = [NSString stringWithFormat:@"%@", nameField.text];

then use

CGContextSelectFont (pdfContext, "Helvetica", 24, kCGEncodingMacRoman); CGContextSetTextDrawingMode (pdfContext, kCGTextFill); CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1); const char *text2 = [nameText UTF8String]; CGContextShowTextAtPoint (pdfContext, 50, 375, text2, strlen(text2));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜