0

我使用 Apple 的文档创建了一个多页 PDF。我需要在 PDF 中呈现的文本下方放置一个 UIImage。这是我到目前为止所拥有的:

    UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);

    pageSize = CGSizeMake(612, 792);
    CFRange currentRange = CFRangeMake(0, 0);
    NSInteger currentPage = 0;
    BOOL done = NO;

    do {
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);

        currentPage++;
        [self drawPageNumber:currentPage];

        [self drawHeader];

        currentRange = [self renderPage:currentPage withTextRange:currentRange andFramesetter:framesetter];

        // If we're at the end of the text, exit the loop.
        if (currentRange.location == CFAttributedStringGetLength((CFAttributedStringRef)currentText))
            done = YES;
    }

    while (!done);

然后,我在单独的 PDF 页面中添加图像:

    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);

    currentPage++;
    [self drawPageNumber:currentPage];

    [self drawHeader];

    [self drawImages];
    // Close the PDF context and write the contents out.
    UIGraphicsEndPDFContext();

但是,如果创建的 PDF 上的文本很少,就会有很多未填充的空白。如果有空间,我需要将图像放在当前 PDF 的底部,如果没有,我需要创建一个新的 PDF。所以,我需要检查文本的“y”位置。

我该怎么做?

4

0 回答 0