Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用硬代码创建简单的pdf文件_Iphone - Fatal编程技术网

Iphone 使用硬代码创建简单的pdf文件

Iphone 使用硬代码创建简单的pdf文件,iphone,Iphone,我已经生成了pdf程序bt的问题是文本不出现在pdf中。 PLz为我提供了pdf创建者的简单示例 这是我的代码: -(void) MyCreatePDFFile //(CGRect pageRect, const char *filename)// 1 { CGRect pageRect=CGRectMake(10,10,400,600); const char *filename="/Users/msoni/Desktop/my.pdf"; CGContextRef pdfCo

我已经生成了pdf程序bt的问题是文本不出现在pdf中。 PLz为我提供了pdf创建者的简单示例

这是我的代码:

-(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);

    CGContextBeginPage (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

}
正在等待答复


谢谢

请使用以下代码和url来完成本教程

nameText=[NSString stringWithFormat:@“%@”,nameField.text]

然后使用

CGContextSelectFont(pdfContext,“Helvetica”,24,kCGEncodingMacRoman); CGContextSetTextDrawingMode(pdfContext、kCGTextFill); CGContextSetRGBFillColor(pdfContext,0,0,1); 常量字符*text2=[nameText UTF8String]; CGContextShowTextAtPoint(pdfContext,50375,text2,strlen(text2))