// file-preview.service.ts

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class FilePreviewService {
  static PreviewPDF(base64: string): void {
    if (base64) {
      const byteCharacters = atob(base64);
      const byteNumbers = new Array(byteCharacters.length);

      for (let i = 0; i < byteCharacters.length; i++) {
        byteNumbers[i] = byteCharacters.charCodeAt(i);
      }

      const byteArray = new Uint8Array(byteNumbers);
      const blob = new Blob([byteArray], { type: 'application/pdf' });

      // 画面表示
      if (blob.size !== 0) {
        const fileUrl = URL.createObjectURL(blob);
        window.open(fileUrl, '_blank');
      }
    } else {
      console.error('Invalid base64 string');
    }
  }
}
