我试图通过CGPDF和CGPDFContext将文本添加到现有的PDF文件中,该文件有5页,但是失败了。我设置了字体,DrawingMode,FillColor ......我在代码中遗漏了什么?
CGContextRef writeContext = NULL;
CGRect mediaBox;
CGPDFPageRef page;
size_t i;
page = CGPDFDocumentGetPage(inputDoc, 1);
mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
if (! writeContext)
writeContext = CGPDFContextCreateWithURL(url, &mediaBox, NULL);
CGPDFContextBeginPage(writeContext, NULL);
CGContextDrawPDFPage(writeContext, page);
//Add text
CGContextSelectFont(writeContext, "Helvetic", 26, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(writeContext, kCGTextFill);
CGContextSetRGBFillColor(writeContext, 0, 0, 0, 1);
const char *text="Hello Text Test";
CGContextShowTextAtPoint(writeContext, 100, 100, text, strlen(text));
//=========
CGPDFContextEndPage(writeContext);
}
if (writeContext)
{
CGPDFContextClose(writeContext);
CGContextRelease(writeContext);
}
答案 0 :(得分:0)
我发现您的字体名称为Helvetic a
CGContextSelectFont(writeContext, "Helvetica", 26, kCGEncodingMacRoman);