تغيير حجم الأشكال في الشريحة
تغيير حجم الأشكال في الشريحة
أحد الأسئلة الأكثر شيوعًا التي يطرحها عملاء Aspose.Slides لـ 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); |