diff --git a/Example iOS-SwiftPM/Example_iOS-SPM.xcodeproj/project.pbxproj b/Example iOS-SwiftPM/Example_iOS-SPM.xcodeproj/project.pbxproj index 71d875fc..75815d45 100644 --- a/Example iOS-SwiftPM/Example_iOS-SPM.xcodeproj/project.pbxproj +++ b/Example iOS-SwiftPM/Example_iOS-SPM.xcodeproj/project.pbxproj @@ -523,7 +523,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; INFOPLIST_FILE = Example/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 12; + IPHONEOS_DEPLOYMENT_TARGET = 16; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -548,7 +548,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; INFOPLIST_FILE = Example/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 12; + IPHONEOS_DEPLOYMENT_TARGET = 16; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Shared/Examples/ExperimentFactory.swift b/Shared/Examples/ExperimentFactory.swift index b6778e04..96c4c9b8 100644 --- a/Shared/Examples/ExperimentFactory.swift +++ b/Shared/Examples/ExperimentFactory.swift @@ -8,43 +8,37 @@ import Foundation import TPPDF +import UIKit class ExperimentFactory: ExampleFactory { func generateDocument() -> [PDFDocument] { - let document = PDFDocument(format: .a4) - - let items = (0..<40).map { $0.description } - - // Simple bullet point list - let featureList = PDFList(indentations: [ - (pre: 10.0, past: 20.0), - (pre: 20.0, past: 20.0), - (pre: 40.0, past: 20.0), - ]) - - // By adding the item first to a list item with the dot symbol, all of them will inherit it - featureList - .addItem(PDFListItem(symbol: .dot) - .addItems(items.map { item in - PDFListItem(content: item) - })) - document.add(list: featureList) - - document.add(space: 20) - - // Numbered list with unusual indentation - let weirdIndentationList = PDFList(indentations: [ - (pre: 10.0, past: 20.0), - (pre: 40.0, past: 30.0), - (pre: 20.0, past: 50.0), - ]) - - weirdIndentationList - .addItems(items.enumerated().map { arg in - PDFListItem(symbol: .numbered(value: "\(arg.offset + 1)"), content: arg.element) - }) - document.add(list: weirdIndentationList) - + let document = PDFDocument(format: .b5) + document.add(.contentCenter, text: "Some Test Name") + let images = [ + "file:///Users/Philip/Downloads/test_images/0000.jpg", + "file:///Users/Philip/Downloads/test_images/0001.jpg", + "file:///Users/Philip/Downloads/test_images/0002.jpg", + "file:///Users/Philip/Downloads/test_images/0003.jpg", + "file:///Users/Philip/Downloads/test_images/0004.jpg", + "file:///Users/Philip/Downloads/test_images/0005.jpg", + "file:///Users/Philip/Downloads/test_images/0006.jpg", + "file:///Users/Philip/Downloads/test_images/0007.jpg", + "file:///Users/Philip/Downloads/test_images/0008.jpg", + "file:///Users/Philip/Downloads/test_images/0009.jpg", + ] + images[0.. PDFImage? in + guard let imageURL = URL(string: imageFileUrl), + let image = UIImage(contentsOfFile: imageURL.path(percentEncoded: false)), + image.size != .zero + else { + return nil + } + + let pdfImage = PDFImage(image: image) + return pdfImage + }).forEach({ pdfImage in + document.add(image: pdfImage) + }) return [document] } } diff --git a/Source/Internal/Image/PDFImageObject.swift b/Source/Internal/Image/PDFImageObject.swift index 0618aa45..7226bf37 100644 --- a/Source/Internal/Image/PDFImageObject.swift +++ b/Source/Internal/Image/PDFImageObject.swift @@ -56,7 +56,10 @@ class PDFImageObject: PDFRenderObject { sizeFit: image.sizeFit) let availableSize = PDFCalculations.calculateAvailableFrame(for: generator, in: container) if container.isCenter { - if imageSize.height + captionSize.height > availableSize.height || (image.sizeFit == .height && imageSize.height < image.size.height) { + let isAvailableHeightZero = availableSize.height == 0 + let isImageCaptionHeightCombinedTooSmall = imageSize.height + captionSize.height > availableSize.height + let isImageHeightTooSmall = image.sizeFit == .height && imageSize.height < image.size.height + if isAvailableHeightZero || isImageCaptionHeightCombinedTooSmall || isImageHeightTooSmall { result += try PDFPageBreakObject().calculate(generator: generator, container: container) generator.layout.heights.content = 0