Free Support Forum - aspose.com

Convert PPT to PDF with A4 as resultant page size

Using - Aspose.Slides for .NET API version 5


When i convert a PPT to PDF by using Presentation.Save(Stream, SaveFormat) method i get the resultant PDF with page size that of PPT i.e a 4:3 ratio.

What i want is the default A4 size of PDF.

How can i get this.

Here’s my code -

private static void ConvertPPTtoPDF()
{
String inFile = @“C:\Sample.ppt”;

using (FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read))
{
Aspose.Slides.Presentation pres = new Presentation(fs);
pres.Save(@“C:\Sample.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
}
}

Hi Vibhor,


I have observed the issue shared by you and suggest you to please try using following code snippet. Please share with us if I may help any further in this regard.

private static void ConvertPPTtoPDF()
{
String inFile = @“C:\Sample.ppt”;

using (FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read))
{
Aspose.Slides.Presentation pres = new Presentation(fs);
pres.SlideSizeType = SlideSizeType.A4Paper;
pres.Save(@“C:\Sample.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
}
}

Many Thanks,

Not working. Its giving up the same 4:3 size.

Hi Vibhor,


Please share the sample presentation and generated PDF with us for necessary investigation. Please also share the sample PDF that you want to generate using Aspose.Slides. I will investigate it further on my end to help you out.

Many Thanks,

Please find the attached files.


The file Sample.pdf is generated by reading Sample.ppt and converting it to pdf.

Hi Vibhor,


I have worked over your requirements using Aspose.Slides for .NET 6.8.0 and for me setting the slide size type to A4 is working. I have used the following sample code for my investigation. I have generated two PDFs and presentation file. Sample3.pdf is generated with default presentation size 4:3. Sample2.Pdf and Sample2.PPT are generated after setting the presentation slide size to A4. You can compare your source presentation and Sample2.ppt to observe the difference. I have attached two snapshots for your reference as well. One is highlighting comparison of Sample3.Pdf(with actual 4:3 Size) and Sample2.pdf (with A4 as size). Please observe the red line drawn on the screen for reference. In second image, I have shared the A4 slide size being applied on generated presentation.

private static void ConvertPPTtoPDF()
{
String inFile = @“D:\Aspose Data\Sample.ppt”;

using (FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read))
{
Aspose.Slides.Presentation pres = new Presentation(fs);
pres.Save(@“D:\Aspose Data\Sample3.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
pres.SlideSizeType = SlideSizeType.A4Paper;
pres.Save(@“D:\Aspose Data\Sample2.ppt”, Aspose.Slides.Export.SaveFormat.Ppt);
pres.Save(@“D:\Aspose Data\Sample2.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
}
}


I hope this elaboration will be helpful to you. Please share, if I may help you further in this regard.

Many Thanks,

Mudassir,


I didnt notice that, and that is because i wanted something else. Sorry i could explain it to you in the beginning.
What i wanted was that the slide area should be that of A4. Currently whats happening is that the content takes size of A4, not the slide boundaries.
The slide area (the white area) remains the same of PPT. I want the slide area to be A4 in the resultant PDF.

Hi Vibhor,


I have tried to understand the query shared by you and like to share that you may probably need to adjust the slide orientation and probably this may work for you. Actually, you need to set the height of slide to width and width to heigh. As default orientation for slide is land scape. But, by doing so you will be able to adjust the slide size and not the slide contents. You may devise the mechanism to iterate through every shape inside slide and interchange the hight and width. The following sample code will help you in adjusting the slide size and look like A4. Please share, if I may help you further in this regard.


private static void ConvertPPTtoPDF()
{
String inFile = @“D:\Aspose Data\Sample.ppt”;

using (FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read))
{
Aspose.Slides.Presentation pres = new Presentation(fs);
pres.Save(@“D:\Aspose Data\Sample3.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
pres.SlideSizeType = SlideSizeType.A4Paper;
int temH = pres.SlideSize.Height;
int temW = pres.SlideSize.Width;
pres.SlideSize = new Size(temH, temW);
pres.Save(@“D:\Aspose Data\Sample2.ppt”, Aspose.Slides.Export.SaveFormat.Ppt);
pres.Save(@“D:\Aspose Data\Sample2.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
}
}

If it is still not what you are looking for then please share the sample PDF you are intending from Aspose.Slides to offer you.

Many Thanks,

Hi Musaddir,


This worked. But the size doesnt match the one in the PDF that i generate using Aspose.PDF.

The default size that i get when i generate Pdf using Aspose.Pdf.Pdf is a bit larger than the one i get by converting PPT to PDF (using pres.SlideSizeType = SlideSizeType.A4Paper).

So it seems like the default size of a PDF generated by Aspose.Pdf.Pdf is not A4.

By hit and trial i found that when i set the PPT size with these values
pres.SlideSize = new Size(4760, 7146)
i get the same size that i desire.

Should i use these hardcoded values or thers another way of doing this.


Hi Vibhor,


I have attached the image that is highlighting the size in inches for A4. You can see from attached image that it is 10.83’’ x 7.5’’. Also there are 576 pixels per inch for Aspose.Slides. so if you need to set the size 10.83’’ in terms of pixels, its 10.83 * 576= 6238 and 7.5 * 576= 4320. So, if you want to set size equivalent to A4, it must be as under:

pres.SlideSize = new Size(4320, 6238 )

However, if you want to continue using the values set on your end you can use them as long as they work for you. But with pixel per inch value in your hand, you can identify the set size in inches.

Many Thanks,