Skip to content

Commit

Permalink
fix dpi naming to ppi
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 17, 2023
1 parent 9f8f654 commit c46a32e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/composables/save-scanned-pdf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface PDFRenderer {
blob: Blob;
height: number;
width: number;
dpi: number;
ppi: number;
}>;
getNumPages(): Promise<number>;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ export function useSaveScannedPDF(
blob: scanPage,
width,
height,
dpi: scale_ * 72,
ppi: scale_ * 72,
};
})
);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/pdf-builder/jsPDF/images-to-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type ImageInfo = {
blob: Blob;
width: number;
height: number;
dpi: number;
ppi: number;
};

export async function imagesToPDF(
Expand All @@ -21,10 +21,10 @@ export async function imagesToPDF(
throw new DOMException("Aborted", "AbortError");
}

const { blob, width, height, dpi } = image;
const { blob, width, height, ppi } = image;
const buffer = new Uint8Array(await blob.arrayBuffer());
const physicalWidth = width / dpi;
const physicalHeight = height / dpi;
const physicalWidth = width / ppi;
const physicalHeight = height / ppi;
const format = getImageFormat(blob);
const orientation = physicalWidth > physicalHeight ? "l" : "p";

Expand Down
8 changes: 4 additions & 4 deletions src/utils/pdf-builder/pdf-lib/build-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ interface ImageInfo {
blob: Blob;
width: number;
height: number;
dpi: number;
ppi: number;
}

export async function buildPDF(images: ImageInfo[]): Promise<Blob> {
const pdfDoc = await PDFDocument.create();

for (const image of images) {
const { blob, width, height, dpi } = image;
const physicalWidthDots = (width / dpi) * 72;
const physicalHeightDots = (height / dpi) * 72;
const { blob, width, height, ppi } = image;
const physicalWidthDots = (width / ppi) * 72;
const physicalHeightDots = (height / ppi) * 72;
const page = pdfDoc.addPage([physicalWidthDots, physicalHeightDots]);

const imageBytes = await blob.arrayBuffer();
Expand Down
6 changes: 3 additions & 3 deletions src/utils/pdf-renderer/pdfjs/PDF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface PDFPageInfo {
height: number;
width: number;
scale: number;
dpi: number;
ppi: number;
}

export interface PDFInfoType {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class PDF implements PDFRenderer {
): Promise<PDFPageInfo> {
await this.initPromise;

const dpi = scale * 72;
const ppi = scale * 72;
const pdfDocument = await this.getDocument();
const pdfPage = await pdfDocument.getPage(page);
const viewport = pdfPage.getViewport({ scale });
Expand Down Expand Up @@ -112,7 +112,7 @@ export class PDF implements PDFRenderer {
height,
width,
scale,
dpi,
ppi,
};

pdfPage.cleanup();
Expand Down

0 comments on commit c46a32e

Please sign in to comment.