void PDFDocumentImage::setCurrentPage(int page) { if (!m_document) return; if (page == m_currentPage) return; if (!(page >= 0 && page < pageCount())) return; m_currentPage = page; CGPDFPageRef cgPage = CGPDFDocumentGetPage(m_document, page + 1); // get media box (guaranteed) m_mediaBox = CGPDFPageGetBoxRect(cgPage, kCGPDFMediaBox); // get crop box (not always there). if not, use media box CGRect r = CGPDFPageGetBoxRect(cgPage, kCGPDFCropBox); if (!CGRectIsEmpty(r)) m_cropBox = r; else m_cropBox = m_mediaBox; // get page rotation angle m_rotation = CGPDFPageGetRotationAngle(cgPage) * piFloat / 180.0f; // to radians }
int PDFPageGetRotation(CGPDFPageRef page) { /* From the PDF Reference: * /Rotate: The number of degrees by which the page should be rotated clockwise when * displayed or printed. The value must be a multiple of 90. */ int rotationAngle = CGPDFPageGetRotationAngle(page); if (rotationAngle % 90 != 0) return 0; else return (4 + ((rotationAngle / 90) % 4)) % 4; }
void PDFDocumentImage::computeBoundsForCurrentPage() { CGPDFPageRef cgPage = CGPDFDocumentGetPage(m_document.get(), 1); CGRect mediaBox = CGPDFPageGetBoxRect(cgPage, kCGPDFMediaBox); // Get crop box (not always there). If not, use media box. CGRect r = CGPDFPageGetBoxRect(cgPage, kCGPDFCropBox); if (!CGRectIsEmpty(r)) m_cropBox = r; else m_cropBox = mediaBox; m_rotationDegrees = CGPDFPageGetRotationAngle(cgPage); }