ในบทช่วยสอนนี้ เราจะมุ่งเน้นไปที่วิธี แปลง SVG เป็น Presentation โดยใช้ Python โดยไม่ต้องพึ่ง PowerPoint แอปพลิเคชันนี้สามารถนำไปใช้ภายในสภาพแวดล้อมใดๆ ของ .NET core และ Python ที่กำหนดค่าไว้ในระบบปฏิบัติการ เช่น Windows, Linux หรือ macOS สำหรับ การแปลง SVG เป็น PPTX ใน Python
ขั้นตอนในการส่งออก SVG เป็น PPTX ใน Python
- กำหนดค่าสภาพแวดล้อมเป็น ใช้ Aspose.Slides สำหรับ Python ผ่าน .NET ในแอปพลิเคชันของคุณเพื่อแปลง SVG เป็นงานนำเสนอ
- สร้างงานนำเสนอเริ่มต้นโดยใช้อินสแตนซ์ของคลาส Presentation
- โหลดสไลด์แรกจากคอลเลกชันสไลด์ของงานนำเสนอ
- เปิดไฟล์ SVG อ่านเนื้อหาเป็นสตริง แล้วใส่ลงในคอลเลกชั่นภาพนำเสนอ
- แทรกกรอบรูปภายในสไลด์ด้วยภาพ SVG ที่เพิ่มเข้ามาโดยใช้อินสแตนซ์ของ IPictureFrame
- บันทึกไฟล์ PPTX ด้วยภาพ SVG บนดิสก์
ขั้นตอนง่ายๆ ข้างต้นใน Python ส่งออก SVG เป็นการนำเสนอ PPT โดยใช้อินเทอร์เฟซ API อย่างง่าย เราจะเริ่มต้นด้วยการสร้างงานนำเสนอเริ่มต้นโดยใช้อินสแตนซ์ของคลาสการนำเสนอ และเข้าถึงสไลด์เริ่มต้นแรกจากคอลเลกชันสไลด์ของงานนำเสนอ จากนั้นเราจะโหลดและอ่านเนื้อหาไฟล์ SVG เป็นสตริงจากดิสก์ และเพิ่มไปยัง IPPImage ภายในคอลเลกชันรูปภาพการนำเสนอ สุดท้าย ด้วยการใช้อินสแตนซ์คลาส IPictureFrame รูปร่างกรอบรูปจะถูกเพิ่มซึ่งจะใช้ไฟล์ SVG ที่เพิ่มเข้ามาก่อนที่จะบันทึกการนำเสนอที่เป็นผลลัพธ์ลงในดิสก์
รหัสเพื่อแปลง SVG เป็น PPTX ใน Python
import aspose.slides as slides | |
filepath = "C://Words//" | |
#Applying the licence for Aspose.Slides to convert SVG to PPTX | |
svgtoSlidesLicense = slides.License() | |
svgtoSlidesLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic") | |
# Make an empty presentation using the Presentation class object | |
with slides.Presentation() as sampleSvgPres: | |
#Access the first slide of the newly created presentation | |
slideForSvg = sampleSvgPres.slides[0] | |
#Load the SVG file content and insert that inside the presentation image collection | |
with open(filepath + "410.svg", 'r') as svgfile: | |
svgContent = svgfile.read().rstrip() | |
ppSVGImage = slides.SvgImage(svgContent) | |
#Add an SVG Image from the disk inside the images collection of the presentation | |
svgImageForSlide = sampleSvgPres.images.add_image(ppSVGImage) | |
#Insert a picture frame inside the shapes collection of the slide | |
slideForSvg.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 0, 0, 720, 540, svgImageForSlide) | |
#Save the presentation in PPTX format with an SVG image on the disk | |
slideForSvg.save(filepath + "PresentationWithSvg.pptx", slides.export.SaveFormat.PPTX) | |
print("Process Completed") | |
หัวข้อนี้อธิบายวิธี แทรก SVG ในการนำเสนอโดยใช้ Python หากคุณสนใจที่จะเรียนรู้เกี่ยวกับการแทรกตารางภายในสไลด์ PowerPoint โปรดดูบทความใน วิธีสร้างตารางใน PowerPoint โดยใช้ Python