UNPKG

react-native-pdf-from-image

Version:
35 lines (31 loc) 1.14 kB
"use strict"; import { NativeModules } from 'react-native'; import { paperSizes } from "./contants.js"; // @ts-ignore We want to check whether __turboModuleProxy exitst, it may not const isTurboModuleEnabled = global.__turboModuleProxy != null; const pdffromimage = isTurboModuleEnabled ? require('./NativePdfFromImage').default : NativeModules.PdfFromImage; export function createPdf(params) { // Sanitize document name by removing file extension const sanitizedName = params.name.replace(/\.[^/.]+$/, ''); // Sanitize image paths for iOS const sanitizedImagePaths = params.imagePaths.map(path => { if (path.startsWith('file://')) { return path.replace('file://', ''); } return path; }); // Determine the paper size let paperSize = params.customPaperSize; if (!paperSize && params.paperSize) { paperSize = paperSizes[params.paperSize]; } // Create a new ImageObject with sanitized paths const sanitizedParams = { ...params, imagePaths: sanitizedImagePaths, paperSize, name: sanitizedName }; return pdffromimage.createPdf(sanitizedParams); } //# sourceMappingURL=index.js.map