-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An error occurred while processing /ppt/slides/slide4.xml #130
Comments
Could you provide some code for me to reproduce this issue? Or will this occur on all PptxGenJS buffers? I've never tried this 😄 |
const automizer = new Automizer({
// this is where your template pptx files are coming from:
templateDir,
// specify the directory to write your final pptx output files:
outputDir,
// turn this to true if you want to generally use
// Powerpoint's creationIds instead of slide numbers
// or shape names:
useCreationIds: false,
// Always use the original slideMaster and slideLayout of any
// imported slide:
autoImportSlideMasters: true,
// truncate root presentation and start with zero slides
removeExistingSlides: true,
// activate `cleanup` to eventually remove unused files:
cleanup: false,
// Set a value from 0-9 to specify the zip-compression level.
// The lower the number, the faster your output file will be ready.
// Higher compression levels produce smaller files.
compression: 0,
// You can enable 'archiveType' and set mode: 'fs'.
// This will extract all templates and output to disk.
// It will not improve performance, but it can help debugging:
// You don't have to manually extract pptx contents, which can
// be annoying if you need to look inside your files.
archiveType: {
mode: 'fs',
baseDir: `${__dirname}/csvs/tmp`,
cleanupWorkDir: true,
},
// use a callback function to track pptx generation process.
statusTracker: (status) => {
console.log(status.info + ' (' + status.share + '%)');
},
});
const presentationFileName = process.argv[2] || 'Presentation.pptx';
const suggestionsFileName = `${templateDir}/sugesstions.json`;
const categories = [
'Category 1',
];
const updatePresentation = async (data) => {
console.log(`Loading file: ${presentationFileName}`);
// 'binary',
// const rootTemplate = fs.readFileSync(
// path.resolve(`${templateDir}/${presentationFileName}`)
// );
let pres = automizer
.loadRoot(presentationFileName)
.load(presentationFileName, 'root');
const presInfo = await pres.getInfo();
const rootSlides = presInfo.slidesByTemplate('root');
console.log('@@@@@@@@@@@@@@@', rootSlides) // [ ]
rootSlides.forEach((_, index) => {
// add each slide from root template
pres.addSlide('root', index + 1); // tried to add by index, but no luck here as well
});
console.log('Getting suggestions slides...');
const suggestionPresentations = await Promise.all(categories.map((category) => {
const suggestionsData = data
.filter((s) => {
return s.category === category && !!s.suggestions
});
return generateCategorySuggestions(category, suggestionsData);
}));
// preload bufferized category slides as templates
// suggestionPresentations.forEach(({ category, buffer }) => {
// pres.load(buffer, category);
// });
// suggestionPresentations.forEach(async ({ category }) => {
// const slideNumbers = await pres.getTemplate(category).getAllSlideNumbers();
// for (let slideNumber of slideNumbers) {
// // add each slide from category template
// pres.addSlide(category, slideNumber);
// }
// });
// const finalJSZip = await pres.getJSZip();
// const buffer = await finalJSZip.generateAsync({ type: 'nodebuffer' });
// fs.writeFileSync(`${outputDir}/${presentationFileName}`, buffer);
// @TODO: original save
await pres.write(presentationFileName).then((summary) => {
console.log(summary);
});
console.log(`Saved file: ${presentationFileName} to ${outputDir}`);
console.log(`Done.`);
console.log(`==================================================`);
} |
@singerla hi, was the code sample helpful? |
Hi @igor-sobolev, I was playing around with loading My current approach:
But (un?)fortunately everything works as expected. import Automizer from './index';
import pptxgen from 'pptxgenjs';
const run = async () => {
const outputDir = `${__dirname}/../__tests__/pptx-output`;
const templateDir = `${__dirname}/../__tests__/pptx-templates`;
let presPptxGen = new pptxgen();
let slide = presPptxGen.addSlide();
let textboxText = 'Hello World from PptxGenJS!';
let textboxOpts: pptxgen.TextPropsOptions = {
x: 1,
y: 1,
color: '363636',
objectName: 'Text 1',
};
slide.addText(textboxText, textboxOpts);
for (let i = 2; i <= 10; i++) {
presPptxGen.addSlide().addImage({
path: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg',
objectName: 'Image ' + i,
x: 1,
y: 2,
});
}
await presPptxGen.writeFile({
fileName: templateDir + '/presPptxGenTmp.pptx',
});
const automizer = new Automizer({
templateDir,
outputDir,
removeExistingSlides: true,
archiveType: {
mode: 'fs',
baseDir: `${__dirname}/tmp`,
cleanupWorkDir: true,
},
});
let pres = automizer
.loadRoot(`presPptxGenTmp.pptx`)
.load(`presPptxGenTmp.pptx`, 'root')
.load(`SlideWithShapes.pptx`, 'shapes')
.load(`EmptySlide.pptx`, 'emptySlide');
const presInfo = await pres.getInfo();
const rootSlides = presInfo.slidesByTemplate('root');
console.log('@@@@@@@@@@@@@@@', rootSlides); // [ ]
rootSlides.forEach((_, index) => {
// add each slide from root template
pres.addSlide('root', _.number); // tried to add by index, but no luck here as well
});
pres.addSlide('shapes', 1, (slide) => {
slide.addElement('root', 1, 'Text 1');
slide.addElement('root', 1, 'Image 1');
pres.write(`myOutputPresentation.pptx`).then((summary) => {
console.log(summary);
});
});
};
run().catch((error) => {
console.error(error);
}); Where is this double Have a great week anyway! 😄 |
Hey, thanks for a reply, double |
It's hard to reproduce without the underlying pptx files generated by pptxGenJs. Every combination that I am testing with v0.6 works without double I was trying this code to produce my own files: import Automizer, { CmToDxa, modify } from './index';
import pptxgen from 'pptxgenjs';
const run = async () => {
const outputDir = `${__dirname}/../__tests__/pptx-output`;
const templateDir = `${__dirname}/../__tests__/pptx-templates`;
let presPptxGen = new pptxgen();
for (let i = 2; i <= 10; i++) {
presPptxGen.addSlide().addImage({
path: 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg',
objectName: 'Image ' + i,
x: 1,
y: 2,
});
}
await presPptxGen.writeFile({
fileName: templateDir + '/presPptxGenTmp.pptx',
});
await presPptxGen.writeFile({
fileName: templateDir + '/presPptxGenTmp2.pptx',
});
const automizer = new Automizer({
templateDir,
outputDir,
removeExistingSlides: true,
autoImportSlideMasters: true,
// archiveType: {
// mode: 'fs',
// baseDir: `${__dirname}/tmp`,
// cleanupWorkDir: false,
// },
});
let pres = automizer
.loadRoot(`presPptxGenTmp.pptx`)
.load(`presPptxGenTmp.pptx`, 'root');
const presInfo = await pres.getInfo();
const rootSlides = presInfo.slidesByTemplate('root');
console.log('@@@@@@@@@@@@@@@', rootSlides); // [ ]
rootSlides.forEach((_, index) => {
// add each slide from root template
pres.addSlide('root', _.number); // tried to add by index, but no luck here as well
});
const suggestionPresentations = [{ category: `presPptxGenTmp2.pptx` }];
for (const { category } of suggestionPresentations) {
pres.load(category);
const slideNumbers = await pres.getTemplate(category).getAllSlideNumbers();
for (let slideNumber of slideNumbers) {
// add each slide from category template
pres.addSlide(category, slideNumber);
}
}
pres.load(`presPptxGenTmp2.pptx`, 'presPptxGenTmp2');
pres.addSlide('presPptxGenTmp2', 3, (slide) => {
slide.modifyElement('Image 4', modify.updatePosition({ x: CmToDxa(5) }));
});
pres.write(`myOutputPresentation.pptx`).then((summary) => {
console.log(summary);
});
};
run().catch((error) => {
console.error(error);
}); |
Seems the previous issue was coming from
Will try to investigate whether there's something with my presentations |
This error seems to point to a problem with the prepended XML-Tag |
@igor-sobolev could you find a solution? |
Background: need to append PptxGenJS buffer presentation into the main one, for some reasons just appending slides cut off last 2 slides, so was trying to combine
.loadRoot
and.load
for getting root template but getting empty array forpres.getTemplate('myTemplate.pptx').getAllSlideNumbers()
. There's an unknown issue with reading slides when reading presentation info (one example below):I can see it's extracted into temp folder I use, but I don't see anywhere
ppt//
mentioned.Seems like I have troubles with a prefix of
ppt//
when accessing presentation withawait pres.getInfo()
. The error persists both forjszip
andfs
modes. I could skip that and get at least some info within
helper/archive/archive-fs.js
read()
function, but it failed in relations later.Any ideas/suggestions what could be wrong?
OS: Linux Ubuntu
Node: 20.12.2
The text was updated successfully, but these errors were encountered: