Coder Social home page Coder Social logo

Comments (7)

Rick-Kirkham avatar Rick-Kirkham commented on August 10, 2024

@Jayshiv1408Dev Please add details about what you mean when you say that the formatting is disturbed. It is a security risk to open a zip file, so I'm reluctant to do that. Could you add a screen shot of the disturbed formatting?

from office-js.

Jayshiv1408Dev avatar Jayshiv1408Dev commented on August 10, 2024

Expected Output PPT1
ExpectedOP PPT1
Error output PPT1
ErrorFile PPT1

Expected output PPT2

ExpectedOP PPT2

Error Output PPT2
ErrorFilePPT2

Expected output PPT3
ExpectedOP PPT3

Error output PPT3
ErrorFile PPT3

Here Formatting means Font style ,alignment font color and size is getting distrub.

Here is my source File For reference
PPT2.pptx
PPT3.pptx
PPT1.pptx

from office-js.

EsterBergen avatar EsterBergen commented on August 10, 2024

@Jayshiv1408Dev - Can you confirm how you're getting the original slides as base64? I think that may be the issue vs. the inserting part.

We recently released an api into preview that exports the slide as Base64. Can you try using that one to generate the Base 64 string?

https://learn.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.slide?view=powerpoint-js-preview#powerpoint-powerpoint-slide-exportasbase64-member(1)

from office-js.

Jayshiv1408Dev avatar Jayshiv1408Dev commented on August 10, 2024

@EsterBergen
When I open this original files normally in powerpoint it's look perfectly but when I open using base64 it's causing issue.
As per your guidance I have to exported its by using exportAsBase64() method and use that bytes to load slides?
Am I correct?

from office-js.

Jayshiv1408Dev avatar Jayshiv1408Dev commented on August 10, 2024

can you please provide CDN for preview. I use beta version CDN but its throw exception at exportAsBase64().
May be I'm doing something wrong.
Can you please provide some demo for this.

from office-js.

EsterBergen avatar EsterBergen commented on August 10, 2024

hi @Jayshiv1408Dev - As it's a preview API you'll need to refer to the Beta reference https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

Try that and let us know if you still have an error.

Before using the preview API for exportAsBase64(), how were you converting your slides to base64?

from office-js.

Jayshiv1408Dev avatar Jayshiv1408Dev commented on August 10, 2024

Using C# File.ReadAllBytes("mypath"); I'm taking bytes from path and after that I'm using this code to convert byte into base64.
here my api response will pass in GetPPTDataSuccess(res)

function GetPPTDataSuccess(res) {
    var Data = "";
    if (res) {
        Data = res[0];
         if (Data != null) {
            var bcontent = base64ToArrayBuffer(Data);
            var blob = new Blob([bcontent], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
            var file = new File([blob], 'test', { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
            var fr = new FileReader();
            fr.onload = ReplaceWordDocument;
            fr.readAsDataURL(file);
            ReplaceWordDocument(Data);
        } 
    }
}
  

async function ReplaceWordDocument(data) {
        if (this && this.result) {
            var startIndex = -1;
            var mybase64 = "";
                data = this.result;
                startIndex = data.indexOf("base64,");
                mybase64 = data.substr(startIndex + 7, data.length);
            if (officeview == "PowerPoint") {
                await loadslide(mybase64);
            }
           
        }
    }

async function loadslide(mybase64) {
     try {
         await PowerPoint.run(async (context) => {
             context.presentation.load("slides");
             await context.sync();
             const slides = context.presentation.slides;
             const slideCount = slides.getCount();
             slides.load("items");
             await context.sync();
             slides.items.map((slide) => {
                 slide.delete();
             });
             await context.sync();
             context.presentation.insertSlidesFromBase64(mybase64);
             await context.sync();
             Loader("hide", translate('Addin_J_302'), "S");

         });
     } catch (e) {
         console.log("e", e);
     }
 }

from office-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.