hi.
can u pleasehelp me with a code for converting powerpoint slide to pdf?
i want to convert every slide to pdf but i want the font not to be streching cause it overflow…
also i want to ask if it will be convert to img,text and more or just as a big image? cause after that i want to conver it to html…
Cause
To convert PowerPoint slides to PDF while ensuring that fonts do not stretch or overflow, specific options must be utilized during the conversion process. Additionally, the output should be configured to maintain text and images rather than rendering them as a single large image.
Solution
You can achieve this by using the PdfOptions
class in Aspose.Slides, which allows you to customize various aspects of the PDF output, including image quality and text compression. Here’s how you can do it:
Code
Here’s a sample code snippet to convert a PowerPoint presentation to PDF with custom options:
using Aspose.Slides;
using Aspose.Slides.Export;
public class PowerPointToPdf
{
public static void ConvertToPdf(string inputFilePath, string outputFilePath)
{
// Instantiate the PdfOptions class.
var pdfOptions = new PdfOptions
{
// Set the quality for JPG images.
JpegQuality = 90,
// Set DPI for images.
SufficientResolution = 300,
// Set the text compression level for textual content.
TextCompression = PdfTextCompression.Flate,
// Ensure fonts are preserved and not stretched.
Compliance = PdfCompliance.Pdf15
};
// Load the presentation.
using var presentation = new Presentation(inputFilePath);
// Save the presentation as a PDF document with the specified options.
presentation.Save(outputFilePath, SaveFormat.Pdf, pdfOptions);
}
}
In this code:
JpegQuality
andSufficientResolution
ensure high-quality images.TextCompression
helps in managing text size without losing quality.Compliance
ensures that the PDF adheres to certain standards, which helps in preserving the layout.
Next Steps
- Replace
inputFilePath
andoutputFilePath
with the actual paths of your PowerPoint file and desired output PDF file. - Run the code to convert your PowerPoint slides to PDF.
- After conversion, you can further manipulate the PDF as needed, including converting it to HTML.
If you have any further questions or need additional assistance, feel free to ask!
@shira,
Thank you for posting the questions. Using Aspose.Slides for .NET, you can convert a presentation (PPT, PPTX, or ODP) to PDF as shown below:
using var presentation = new Presentation("sample.pptx");
presentation.Save("output.pdf", SaveFormat.Pdf);
or
Convert.ToPdf("sample.pptx", "output.pdf");
If you need to convert every slide to PDF separately, use the following code example:
using var presentation = new Presentation("sample.pptx");
for (int index = 1; index <= presentation.Slides.Count; index++)
{
int[] slideIndices = { index };
presentation.Save($"output_{index}.pdf", slideIndices, SaveFormat.Pdf);
}
You can also use the PdfOptions class with the Presentation.Save
and Convert.ToPdf
methods to configure various conversion settings.
More examples:
Convert PPT and PPTX to PDF in C# [Advanced Features Included]|Aspose.Slides Documentation
In the output PDF, text is preserved as text, and images are preserved as individual images (not combined into one large image).
Could you please share a sample presentation file and describe the issue you encountered in more detail?