Skip to content

Commit

Permalink
Merge pull request #139 from rwv/fix-133
Browse files Browse the repository at this point in the history
Fix 133
  • Loading branch information
rwv committed Jan 28, 2023
2 parents b4dd032 + 4607b7e commit 04fcb40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/utils/images-to-pdf/images-to-pdf.ts
Expand Up @@ -5,7 +5,10 @@ export type ImageInfo = {
dpi: number;
};

export async function imagesToPDF(images: ImageInfo[]): Promise<Blob> {
export async function imagesToPDF(
images: ImageInfo[],
signal?: AbortSignal
): Promise<Blob> {
const jsPDF = (await import("jspdf")).default;

const doc = new jsPDF({
Expand All @@ -14,6 +17,10 @@ export async function imagesToPDF(images: ImageInfo[]): Promise<Blob> {
doc.deletePage(1); // delete the default page

for (const image of images) {
if (signal?.aborted) {
throw new DOMException("Aborted", "AbortError");
}

const { blob, width, height, dpi } = image;
const buffer = new Uint8Array(await blob.arrayBuffer());
const physicalWidth = width / dpi;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/images-to-pdf/index.ts
@@ -1 +1 @@
export { imagesToPDFWithWorker as imagesToPDF } from "./images-to-pdf-with-worker";
export { imagesToPDF as imagesToPDF } from "./images-to-pdf";
6 changes: 3 additions & 3 deletions vite.config.ts
Expand Up @@ -41,9 +41,9 @@ export default defineConfig({
"@": path.resolve(__dirname, "src"),
},
},
worker: {
format: "es",
},
// worker: {
// format: "es",
// },
/* remove the need to specify .vue files https://vitejs.dev/config/#resolve-extensions
resolve: {
extensions: [
Expand Down

0 comments on commit 04fcb40

Please sign in to comment.