تغيير حجم الأشكال على الشريحة
تغيير حجم الأشكال على الشريحة
واحدة من أكثر الأسئلة تكرارًا التي يطرحها عملاء Aspose.Slides لـ PHP عبر Java هي كيفية تغيير حجم الأشكال بحيث عند تغيير حجم الشريحة لا يتم قطع البيانات. تُظهر هذه النصيحة التقنية القصيرة كيفية تحقيق ذلك.
لتجنب تشويه الأشكال، يجب تحديث كل شكل على الشريحة وفقًا لحجم الشريحة الجديد.
Presentation presentation = new Presentation("D:\\TestResize.ppt"); | |
//Old slide size | |
float currentHeight = (float)presentation.getSlideSize().getSize().getHeight(); | |
float currentWidth =(float)presentation.getSlideSize().getSize().getWidth(); | |
//Changing slide size | |
presentation.getSlideSize().setType(SlideSizeType.A4Paper); | |
//New slide size | |
float newHeight = (float)presentation.getSlideSize().getSize().getHeight(); | |
float newWidth = (float)presentation.getSlideSize().getSize().getWidth(); | |
float ratioHeight = newHeight / currentHeight; | |
float ratioWidth = newWidth / currentWidth; | |
for (ISlide slide : presentation.getSlides()) | |
{ | |
for (IShape shape : slide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
} | |
presentation.save("Test.pptx",SaveFormat.Pptx); |
تحتاج إلى استخدام الكود التالي على جانبك إذا كنت بحاجة إلى تغيير حجم الشرائح مع الجداول. يعتبر ضبط عرض أو ارتفاع الجدول حالة خاصة في الأشكال حيث تحتاج إلى تغيير ارتفاع الصف الفردي وعرض العمود لتغيير ارتفاع الجدول وعرضه.
Presentation presentation = new Presentation("D:\\Test.pptx"); | |
//Old slide size | |
float currentHeight = (float) presentation.getSlideSize().getSize().getHeight(); | |
float currentWidth = (float) presentation.getSlideSize().getSize().getWidth(); | |
//Changing slide size | |
presentation.getSlideSize().setType(SlideSizeType.A4Paper); | |
//presentation.SlideSize.Orientation = SlideOrienation.Portrait; | |
//New slide size | |
float newHeight = (float) presentation.getSlideSize().getSize().getHeight(); | |
float newWidth = (float) presentation.getSlideSize().getSize().getWidth(); | |
float ratioHeight = newHeight / currentHeight; | |
float ratioWidth = newWidth / currentWidth; | |
for (IMasterSlide master : presentation.getMasters()) | |
{ | |
for (IShape shape : master.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
for (ILayoutSlide layoutslide : master.getLayoutSlides()) | |
{ | |
for (IShape shape : layoutslide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
} | |
} | |
for (ISlide slide : presentation.getSlides()) | |
{ | |
for (IShape shape : slide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
if (shape instanceof ITable) | |
{ | |
ITable table = (ITable)shape; | |
IRow row=null; | |
for(int i=0;i<table.getRows().size();i++) | |
{ | |
row=table.getRows().get_Item(i); | |
row.setMinimalHeight(row.getMinimalHeight() * ratioHeight); | |
} | |
IColumn col; | |
for (int j=0;j<table.getColumns().size();j++) | |
{ | |
col=table.getColumns().get_Item(j); | |
col.setWidth(col.getWidth() * ratioWidth); | |
} | |
} | |
} | |
} | |
presentation.save("D:\\Test.pptx", SaveFormat.Pptx); |