diff --git a/src/app/components/attachment-dialog/attachment-dialog.component.html b/src/app/components/attachment-dialog/attachment-dialog.component.html
index 776fdab..47f8c53 100644
--- a/src/app/components/attachment-dialog/attachment-dialog.component.html
+++ b/src/app/components/attachment-dialog/attachment-dialog.component.html
@@ -1,14 +1,18 @@
- {{ data.name }}
+ {{ file.name }}
- Description: {{ data.description }}
- MimeType: {{ data.mimeType }}
+ Description: {{ file.description }}
+ MimeType: {{ file.mimeType }}
+ @if(file.mimeType.includes('image/')) {
+
+ } @else {
{{ fileContent }}
+ }
diff --git a/src/app/components/attachment-dialog/attachment-dialog.component.scss b/src/app/components/attachment-dialog/attachment-dialog.component.scss
index e69de29..abddedd 100644
--- a/src/app/components/attachment-dialog/attachment-dialog.component.scss
+++ b/src/app/components/attachment-dialog/attachment-dialog.component.scss
@@ -0,0 +1,11 @@
+iframe {
+ width: 100%;
+ height: 100%;
+ border: none;
+}
+
+img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+}
\ No newline at end of file
diff --git a/src/app/components/attachment-dialog/attachment-dialog.component.ts b/src/app/components/attachment-dialog/attachment-dialog.component.ts
index 8775365..4b2f0d7 100644
--- a/src/app/components/attachment-dialog/attachment-dialog.component.ts
+++ b/src/app/components/attachment-dialog/attachment-dialog.component.ts
@@ -26,11 +26,24 @@ import { DocumentAttachment } from '@app/types/attachment';
],
})
export class AttachmentDialogComponent {
- readonly data = inject(MAT_DIALOG_DATA);
+ readonly file = inject(MAT_DIALOG_DATA);
fileContent: string | undefined;
+ dataUrl: string | undefined;
constructor() {
- this.fileContent = new TextDecoder().decode(this.data.data);
+ this.fileContent = new TextDecoder().decode(this.file.data);
+ this.dataUrl = this.toBase64Data(this.file);
+ }
+
+ private toBase64Data(file: DocumentAttachment) {
+ return `data:${file.mimeType};base64,${blobToBase64(this.file.data)}`;
}
}
+
+export const blobToBase64 = (blob: Uint8Array) => {
+ const output = [];
+ for (let i = 0, { length } = blob; i < length; i++)
+ output.push(String.fromCharCode(blob[i]));
+ return btoa(output.join(''));
+};
diff --git a/src/app/helpers/pdf.helper.ts b/src/app/helpers/pdf.helper.ts
index 531e40b..28b7655 100644
--- a/src/app/helpers/pdf.helper.ts
+++ b/src/app/helpers/pdf.helper.ts
@@ -45,7 +45,11 @@ export const extractAttachments = (pdfDoc: PDFDocument) => {
.lookup(PDFName.of('EF'), PDFDict)
.lookup(PDFName.of('F'), PDFStream) as PDFRawStream;
- const description = fileSpec.lookup(PDFName.of('Desc'), PDFString);
+ const description = fileSpec.lookup(
+ PDFName.of('Desc'),
+ PDFString,
+ PDFHexString
+ );
const subtype = stream.dict.lookup(PDFName.of('Subtype'), PDFName);
return {