Open lan2000 opened 2 years ago
Now you must set the width and height of the picture. Can you add a choice to make it use the original width and height.
CreateImageFromPDF.kt
fun create(path: String?, outputDirPath: String?, maxWidth : Int?, maxHeight : Int? , createOneImage : Boolean?)
// val bitmap: Bitmap = page.renderBitmap(maxWidth!!, maxHeight!!, rectF) val bitmap: Bitmap = page.renderBitmap(page.width, page.height, rectF) //use original width and height.
Or scale the picture according to the maximum width and height as IOS. public static func resizeImage(img: UIImage, maxWidthGet : Int, maxHeightGet : Int) -> UIImage { var actualHeight: Float = Float(img.size.height) var actualWidth: Float = Float(img.size.width) let maxHeight: Float = Float(maxHeightGet) let maxWidth: Float = Float(maxWidthGet) var imgRatio: Float = actualWidth / actualHeight let maxRatio: Float = maxWidth / maxHeight // let compressionQuality: Float = 0.5 //50 percent compression
if actualHeight > maxHeight || actualWidth > maxWidth {
if imgRatio < maxRatio {
//adjust width according to maxHeight
imgRatio = maxHeight / actualHeight
actualWidth = imgRatio * actualWidth
actualHeight = maxHeight
}
else if imgRatio > maxRatio {
//adjust height according to maxWidth
imgRatio = maxWidth / actualWidth
actualHeight = imgRatio * actualHeight
actualWidth = maxWidth
}
else {
actualHeight = maxHeight
actualWidth = maxWidth
}
}
let rect = CGRect(x: 0.0, y: 0.0, width: CGFloat(actualWidth), height: CGFloat(actualHeight))
let newSize = AVMakeRect(
aspectRatio: img.size,
insideRect: rect
).size
// UIGraphicsBeginImageContext(rect.size)
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
img.draw(in: CGRect(origin: .zero, size: newSize))
let scaled = UIGraphicsGetImageFromCurrentImageContext() ?? img
UIGraphicsEndImageContext()
// img.draw(in:rect) // let img = UIGraphicsGetImageFromCurrentImageContext() // let imageData = img?.jpegData(compressionQuality: CGFloat(compressionQuality)) // UIGraphicsEndImageContext() return scaled }
android 10 pdf_merger 0.0.6
code: final outputDirPath= '/data/user/0/com.auc.pdf_merger_example/cache/TestPDFMergerABCEFG5.png'; CreateImageFromPDFResponse response = await PdfMerger.createImageFromPDF( path: singleFile, outputDirPath: outputDirPath, createOneImage: false);
An error will be reported when the output path has ".". error log: W/System.err(28691): java.io.FileNotFoundException: /data/user/0/com0.auc: open failed: EACCES (Permission denied) W/System.err(28691): at libcore.io.IoBridge.open(IoBridge.java:496) W/System.err(28691): at java.io.FileOutputStream.(FileOutputStream.java:235)
W/System.err(28691): at java.io.FileOutputStream.(FileOutputStream.java:125)
W/System.err(28691): at com.ril.pdf_merger.CreateImageFromPDF$create$pdfFromMultipleImage$1.invokeSuspend(CreateImageFromPDF.kt:67)
W/System.err(28691): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
W/System.err(28691): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
W/System.err(28691): at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
W/System.err(28691): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
W/System.err(28691): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
W/System.err(28691): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
W/System.err(28691): Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
W/System.err(28691): at libcore.io.Linux.open(Native Method)
W/System.err(28691): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
W/System.err(28691): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
W/System.err(28691): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
W/System.err(28691): at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8464)
W/System.err(28691): at libcore.io.IoBridge.open(IoBridge.java:482)
CreateImageFromPDF.kt
log: E/----MainActivity outputDirPath(28691): /data/user/0/com.auc.pdf_merger_example/cache/TestPDFMergerABCEFG5.png E/----MainActivity splitPath(28691): /data/user/0/com E/----MainActivity splitPathExt(28691): auc