Generating a PowerPoint or PowerPointX file from a byte array using TypeScript and Angular 2

In order to generate a .ppt/.pptx file in Angular 2, I am looking for a way to convert my byteArray response into a Blob Object. While I have successfully converted it into image and pdf formats using the code snippet below:

var blob = new Blob(resp, {type: 'application/pdf'});

I'm now seeking guidance on what type should be specified for ppt or pptx conversion. Any additional details that need to be included would also be appreciated.

Answer №1

If you need the MIME Types for Microsoft PowerPoint, here they are:

  • .ppt (exclusive format used before PowerPoint 2007)

application/vnd.ms-powerpoint

  • .pptx (accessible format introduced in PowerPoint 2007)

application/vnd.openxmlformats-officedocument.presentationml.presentation

Answer №2

If you come across this and need to categorize it for TypeScript, here's how I approached it:

export type ReportGenerationFormat = 'PPT' | 'WORD' | 'PDF';

interface ReportFileType {
  extension: string;
  mimeType: string;
}

/**
 * List of file name extensions with their corresponding MIME Types.
 * PPT is a closed format used before PowerPoint 2007.
 * PPTX is an open format introduced since PowerPoint 2007.
 * PDF is universally known as Portable Document Format.
 * DOC refers to Microsoft document format pre-Word 2007.
 * DOCX represents newer versions of Microsoft Word documents.
 */
export const ReportFileTypes: Record<string, ReportFileType> = {
  PPT: { extension: '.ppt', mimeType: 'application/vnd.ms-powerpoint' },
  PPTX: { extension: '.pptx', mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' },
  PDF: { extension: '.pdf', mimeType: 'application/pdf' },
  DOC: { extension: '.doc', mimeType: 'application/msword' },
  DOCX: { extension: '.docx', mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' },
};

Simply import the constant and leverage it using the fileType parameter, such as:

ReportFileTypes[fileType].mimeType

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Storing values globally in NodeJS from request headers

What is the most effective way to store and access the value from a request header in multiple parts of my application? One approach could be as shown in the following example from app.js: app.get('*', (req, res) => { global.exampleHeader ...

Angular httpClient: Adjusting date format within json object

I need help converting the date property of an object to a format that the server can understand when using httpClient.post(...). Currently, the date property has its natural string representation. What steps can I take to make sure it is in the correct ...

Placing the cursor on a newly created element is ineffective when the innerHtml is empty

https://codesandbox.io/s/nameless-feather-duk25?fontsize=14&hidenavigation=1&theme=dark In the code example above, I am trying to make a certain feature work. The concept is as follows: there is a contentEditable div element where text can be type ...

Exploring the process of sending post data and navigating to a URL using AngularJS

I am working on an application using angularjs 1.6 and Java 8. My goal is to send POST data to another application and navigate to the URL that this external application determines. The purpose of my application is to transmit data about a citizen who wan ...

Inaccurate Error Handling in Try-Catch Blocks

I am facing an issue with my try-catch block designed to handle errors when connecting to a Mongo Database. Even though I have implemented error handling, Express crashes in the backend when the MongoDB engine is turned off for testing purposes. Is there ...

The scroll bar only becomes visible for left and right scrolling when I reach the very bottom of the content

I want to implement scroll controls in my pdf viewer. Although scrolling up and down is working well, I am facing an issue where the horizontal scroll bar does not appear until I reach the bottom of the PDF file. Below is the CSS code I am using: .pdf-con ...

"An error has occurred: ENOENT - The specified file or directory does not exist, cannot create directory" on the live website

I am facing an issue on my website where I need to create a folder and save some files in it. While the code works perfectly fine locally, once deployed on render, I encounter the following error: Error: ENOENT: no such file or directory, mkdir '/opt/ ...

Encountered a snowflake SDK issue which resulted in a TypeError: Unable to access properties of undefined (specifically reading 'set') within OcspResponseCache.set

My current setup includes node version v17.9.0 running on a Linux OS within a Kubernetes environment. I am launching a Node.js application to interact with Snowflake and run queries. The versions of snowflake-promise and snowflake-sdk being used are 2.2.0 ...

Tips for verifying that an input field only accepts values from an array in Angular 6

In this specific scenario, the input fields are only supposed to accept values that exist in a pre-defined array. If any other values are entered, an error should be triggered. .component.html <input type="text" ([ngModel])="InputValues& ...

Observing an item with a numerical identifier in Vue

Is there a method to monitor a specific value within an object that uses a numeric key in Vue2? If the key were a standard string like obj = {keyName: []}, I am aware that you can achieve this by: watch: { 'obj.keyName'() { //Handle arra ...

Is there a way to determine which option is currently highlighted in Internet Explorer before it is actually chosen?

Despite the fact that IE does not support mouse events on <option> elements, it does highlight the option under the mouse cursor when you open a dropdown list. Is there a way in JavaScript to capture this highlighted option as the user moves the mous ...

Issues arising from the JSON responses within the Angular application

**JS Code** Currently facing an issue with retrieving JSON object values from PHP and displaying them in the console. I have set up a post method with the user value containing email and password. In my PHP file, I am validating it and returning the value ...

An issue occurred while creating a generic MessageBus in Typescript with rxjs due to a typing mismatch

I'm currently working on developing a versatile MessageBus in Typescript. My goal is to create message classes that inherit from a main MessageBusMessage class, allowing for subscription to messages of a specific class type with strong generic typing ...

Retrieve the part of a displayed element

Presently, I am developing a modal system using React. A button is located in the sidebar and the modal is represented as a div within the body. In the render function of the main component of my application, two components are being rendered: MyModal M ...

Error Message: Undefined Service in Angular version 1.5.4

I'm currently developing a sample application using AngularJS 1.5.4, built on angular seed, EcmaScript 6, and with a node.js web server. For routing, I am following the guidelines provided here: https://docs.angularjs.org/guide/component-router. Howe ...

The functionality of a basic each/while loop in jQuery using CoffeeScript is not producing the desired results

I've been experimenting with different methods to tackle this issue. Essentially, I need to update the content of multiple dropdowns in the same way. I wanted to use an each or a while loop to keep the code DRY, but my experience in coffeeScript is li ...

Positioning the infowindow in Google Maps API v3

Creating a map with various markers, each with its own info window. However, when attempting to display an info window on multiple markers, the position remains fixed at the first clicked marker. What could be causing this issue? <script type="text/jav ...

The content inside the bootstrap modal is not visible

My goal is to trigger a modal window when a specific div is clicked using bootstrap modal. However, upon clicking the div, the screen darkens but the modal body fails to appear. Code: <html> <head> <title></title> ...

"Learn the trick to easily switch between showing and hiding passwords for multiple fields in a React application

I am looking to implement a feature that toggles the visibility of passwords in input fields. It currently works for a single input field, but I am unsure how to extend this functionality to multiple input fields. My goal is to enable the show/hide passwo ...

The Art of Angular Architecture: Transmitting Information from Parent to Child

Exploring the concept of templates within a template in the example below... @Component({ selector: 'component-a', template: `<div> <component-b></component-b> </div>` }) Should component-b share a s ...