Skip to content

Commit

Permalink
Generate preview for pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Nov 2, 2023
1 parent 63f38be commit 30abe5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export enum PreviewInputMimeTypes {
IMAGE_HEIF = 'image/heif',
IMAGE_TIFF = 'image/tiff',
IMAGE_WEBP = 'image/webp',
APPLICATION_PDF = 'application/pdf',
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { GetFile, S3ClientAdapter } from '@shared/infra/s3-client';
import { Logger } from '@src/core/logger';
import { PreviewInputMimeTypes } from '@src/modules/files-storage/interface';
import { subClass } from 'gm';
import { PassThrough } from 'stream';
import { PreviewFileOptions, PreviewOptions, PreviewResponseMessage } from './interface';
Expand Down Expand Up @@ -45,6 +46,10 @@ export class PreviewGeneratorService {

const preview = this.imageMagick(original.data);

if (original.contentType === PreviewInputMimeTypes.APPLICATION_PDF) {
preview.selectFrame(0);
}

if (width) {
preview.resize(width, undefined, '>');
}
Expand Down

0 comments on commit 30abe5b

Please sign in to comment.