Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/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
Ios 在PDF末尾添加UIImage_Ios_Objective C_Pdf_Uiimage - Fatal编程技术网

Ios 在PDF末尾添加UIImage

Ios 在PDF末尾添加UIImage,ios,objective-c,pdf,uiimage,Ios,Objective C,Pdf,Uiimage,我使用苹果的文档创建了一个多页的PDF。我需要在PDF中呈现的文本下面放置一个UIImage。以下是我目前掌握的情况: UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil); pageSize = CGSizeMake(612, 792); CFRange currentRange = CFRangeMake(0, 0); NSInteger currentPage = 0; BOOL

我使用苹果的文档创建了一个多页的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”位置


如何操作?

只需检查页面中当前的“y”位置即可。将其与图像高度和页面大小进行比较。如果图像合适,不要开始新页面。@rmaddy-这是有道理的,但我使用的是核心文本,根据苹果的文档。我可以检查什么“y”位置?