0

我试图通过 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);
    }
4

1 回答 1

0

我发现您的字体名称 Helvetic a有错字

CGContextSelectFont(writeContext, "Helvetica", 26, kCGEncodingMacRoman);
于 2016-02-01T04:47:33.103 回答