Ejemplo n.º 1
0
func DuplicateSlide(pptRootPath, slideName string) (newSlideName string, err error) {
	newSlideName = uuid.NewV4().String() + ".xml"
	newSlideName = "slilde2.xml"

	slidePath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, slideName)
	newSlidePath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, newSlideName)

	err = fo.CopyFile(slidePath, newSlidePath)
	if err != nil {
		return "", err
	}

	sourceSlideRelsPath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, c.RelsFolder, slideName+relsExtension)
	newSlideRelsPath := filepath.Join(pptRootPath, c.PPTFolder, c.SlideFolder, c.RelsFolder, newSlideName+relsExtension)

	err = fo.CopyFile(sourceSlideRelsPath, newSlideRelsPath)
	if err != nil {
		return "", err
	}

	rid, err := createRelations(pptRootPath, newSlideName)
	if err != nil {
		return "", err
	}

	err = addSlideInPresentation(pptRootPath, rid)
	if err != nil {
		return "", err
	}

	return newSlideName, addSlideContentTypeInContentTypes(pptRootPath, newSlideName)
}
Ejemplo n.º 2
0
func main() {
	sourcePPT := "Template.pptx"
	tempFolder := "tmp"
	targetPPT := "new.pptx"
	newImage := "img.jpg"

	err := z.Unzip(getAbsolutePath(sourcePPT), getAbsolutePath(tempFolder))
	if err != nil {
		fmt.Println("Error unziping : ", err)
		return
	}
	defer util.Remove(getAbsolutePath(tempFolder))

	//duplicate slide
	newSlideName, err := openxml.DuplicateSlide(getAbsolutePath(tempFolder), templateSlideName)
	if err != nil {
		fmt.Println("Error while duplicationg slide : ", err)
		return
	}

	slidePath := filepath.Join(tempFolder, c.PPTFolder, c.SlideFolder, newSlideName)

	replacements := make([]m.SlideReplacement, 1)
	replacements = append(replacements, m.SlideReplacement{PlaceHolder: "#title#", Replacement: "This is replaced title"})
	replacements = append(replacements, m.SlideReplacement{PlaceHolder: "#footer#", Replacement: "This is replaced footer"})

	//replace text placeholders
	err = fo.ReplaceTextInFile(getAbsolutePath(slidePath), replacements)
	if err != nil {
		fmt.Println("Error while content replacing", err)
		return
	}

	targetImgPath := filepath.Join(tempFolder, c.PPTFolder, c.MediaFolder, templateImgName)

	//replace image placeholder
	err = fo.CopyFile(getAbsolutePath(newImage), getAbsolutePath(targetImgPath))
	if err != nil {
		fmt.Println("Error while image replacing", err)
		return
	}

	err = z.Zipit(getAbsolutePath(tempFolder), getAbsolutePath(targetPPT))

	if err != nil {
		fmt.Println("Error ziping : ", err)
	}
}