{"id":28559056,"url":"https://github.com/sdwebimage/sdwebimagepdfcoder","last_synced_at":"2025-06-10T08:36:03.161Z","repository":{"id":54727675,"uuid":"155054528","full_name":"SDWebImage/SDWebImagePDFCoder","owner":"SDWebImage","description":"A PDF coder plugin for SDWebImage, using Apple's built-in framework","archived":false,"fork":false,"pushed_at":"2023-10-24T07:34:28.000Z","size":367,"stargazers_count":27,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-04T03:24:31.824Z","etag":null,"topics":["ios","macos","pdf","sdwebimage","tvos","watchos"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SDWebImage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-10-28T09:31:17.000Z","updated_at":"2024-12-30T15:23:05.000Z","dependencies_parsed_at":"2023-11-27T13:07:15.269Z","dependency_job_id":"8637e507-0a82-4d98-a42c-4fa763e9f072","html_url":"https://github.com/SDWebImage/SDWebImagePDFCoder","commit_stats":{"total_commits":50,"total_committers":2,"mean_commits":25.0,"dds":"0.020000000000000018","last_synced_commit":"2aecb0a16e4d054c7f36a140f7feef6e1ede7bb6"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImagePDFCoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImagePDFCoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImagePDFCoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImagePDFCoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SDWebImage","download_url":"https://codeload.github.com/SDWebImage/SDWebImagePDFCoder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDWebImage%2FSDWebImagePDFCoder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259039578,"owners_count":22796865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","pdf","sdwebimage","tvos","watchos"],"created_at":"2025-06-10T08:36:00.752Z","updated_at":"2025-06-10T08:36:03.137Z","avatar_url":"https://github.com/SDWebImage.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SDWebImagePDFCoder\n\n[![CI Status](https://img.shields.io/travis/SDWebImage/SDWebImagePDFCoder.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImagePDFCoder)\n[![Version](https://img.shields.io/cocoapods/v/SDWebImagePDFCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImagePDFCoder)\n[![License](https://img.shields.io/cocoapods/l/SDWebImagePDFCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImagePDFCoder)\n[![Platform](https://img.shields.io/cocoapods/p/SDWebImagePDFCoder.svg?style=flat)](https://cocoapods.org/pods/SDWebImagePDFCoder)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImagePDFCoder)\n[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager/)\n\n## What's for\nSDWebImagePDFCoder is a PDF coder plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the image loading support for [PDF](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics). The PDF rendering is done using Apple's built-in framework (UIKit/AppKit/Core Graphics).\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\nYou can modify the code or use some other PDF files to check the compatibility.\n\n## Requirements\n\n+ iOS 9+\n+ tvOS 9+\n+ macOS 10.11+\n+ watchOS 2+\n+ Xcode 13+\n\n## Installation\n\n#### CocoaPods\n\nSDWebImagePDFCoder is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SDWebImagePDFCoder'\n```\n\n#### Carthage\n\nSDWebImagePDFCoder is available through [Carthage](https://github.com/Carthage/Carthage).\n\n```\ngithub \"SDWebImage/SDWebImagePDFCoder\"\n```\n\n#### Swift Package Manager (Xcode 11+)\n\nSDWebImagePDFCoder is available through [Swift Package Manager](https://swift.org/package-manager).\n\n```swift\nlet package = Package(\n    dependencies: [\n        .package(url: \"https://github.com/SDWebImage/SDWebImagePDFCoder.git\", from: \"1.0\")\n    ]\n)\n```\n\n## Usage\n\nTo use PDF coder, you should firstly add the `SDImagePDFCoder` to the coders manager. Then you can call the View Category method to start load PDF images.\n\n### Use UIImageView vector rendering (iOS/tvOS 11+, Mac)\n\n**Important**: Apple add the built-in vector image support for PDF format  for UIKit from iOS/tvOS 11+. Which means you can create a `UIImage` with PDF data, and set it on the `UIImageView`. When the imageView bounds/contentMode changed, the PDF image also get scaled without losing any detail. You can also use `+[UIImage imageNamed:]` with Xcode Asset Catalog for PDF image, remember to turn on `Preserve Vector Data`.\n\nFor macOS user, `NSImage`/`NSImageView` support PDF image from the day one. Use it as usual.\n\n+ Objective-C\n\n```objectivec\nSDImagePDFCoder *PDFCoder = [SDImagePDFCoder sharedCoder];\n[[SDImageCodersManager sharedManager] addCoder:PDFCoder];\nUIImageView *imageView;\n[imageView sd_setImageWithURL:url];\n```\n\n+ Swift\n\n```swift\nlet PDFCoder = SDImagePDFCoder.shared\nSDImageCodersManager.shared.addCoder(PDFCoder)\nlet imageView: UIImageView\nimageView.sd_setImage(with: url)\n```\n\n### Use UIImageView bitmap rendering (iOS/tvOS 10-)\n\nFor firmware which is below iOS/tvOS 11+, `UIImage` \u0026\u0026 `UIImageView` does not support vector image rendering. Even you can add PDF image in Xcode Asset Catalog, it was encoded to bitmap PNG format when compiled but not support runtime scale. \n\nFor `UIImageView`, we will only parse PDF with a fixed image size (from the PDF mediaBox information). But we also support you to specify a desired size during image loading using `.imageThumbnailPixelSize` context option. And you can specify whether or not to keep aspect ratio during scale using `.imagePreserveAspectRatio` context option.\n\nNote: Once you pass the pixel size, we will always generate the bitmap representation even on iOS/tvOS 11+. If you want the vector format, do not pass them, let `UIImageView` to dynamically stretch the PDF.\n\n+ Objective-C\n\n```objectivec\nSDImagePDFCoder *PDFCoder = [SDImagePDFCoder sharedCoder];\n[[SDImageCodersManager sharedManager] addCoder:PDFCoder];\nUIImageView *imageView;\nCGSize bitmapSize = CGSizeMake(500, 500);\n[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(bitmapSize)];\n```\n\n+ Swift\n\n```swift\nlet PDFCoder = SDImagePDFCoder.shared\nSDImageCodersManager.shared.addCoder(PDFCoder)\nlet imageView: UIImageView\nlet bitmapSize = CGSize(width: 500, height: 500)\nimageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])\n```\n\n## Export PDF data\n\n`SDWebImagePDFCoder` provide an easy way to export the PDF image generated from framework, to the original PDF data.\n\nIf the input image is already vector PDF based, will export that instead (fast).\nElse we will create an empty PDF page with the bitmap image drawn on (slow).\n\n+ Objective-C\n\n```objectivec\nUIImage *pdfImage; // UIImage with vector image, or NSImage contains `NSPDFImageRep`\nNSData *pdfData = [pdfImage sd_imageDataAsFormat:SDImageFormatPDF]; // May return the vector data, or create new PDF with current image drawn on\n```\n\n+ Swift\n\n```swift\nlet pdfImage: UIImage // UIImage with vector image, or NSImage contains `NSPDFImageRep`\nlet pdfData = pdfImage.sd_imageData(as: .PDF) // May return the vector data, or create new PDF with current image drawn on\n```\n\n## Screenshot\n\n\u003cimg src=\"https://raw.githubusercontent.com/SDWebImage/SDWebImagePDFCoder/master/Example/Screenshot/PDFDemo.png\" width=\"300\" /\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/SDWebImage/SDWebImagePDFCoder/master/Example/Screenshot/PDFDemo-macOS.png\" width=\"600\" /\u003e\n\nThese PDF images are from [icons8](https://github.com/icons8/flat-color-icons/tree/master/pdf), you can try the demo with your own PDF image as well.\n\n## Author\n\nDreamPiggy\n\n## License\n\nSDWebImagePDFCoder is available under the MIT license. See the LICENSE file for more info.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdwebimage%2Fsdwebimagepdfcoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdwebimage%2Fsdwebimagepdfcoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdwebimage%2Fsdwebimagepdfcoder/lists"}