Convert PowerPoint Presentations to Pdf | |
Using the SelectPdf PowerPoint to Pdf Converter for .NET, a PowerPoint presentation can be converted to pdf with a few lines of code - its slides, its notes pages or handouts with several slides on a page. The converter reads pptx, pptm, potx, potm, ppsx and ppsm files. The conversion runs in-process: no engine is launched.
The PowerPoint to Pdf converter is available only in the full commercial SelectPdf library. It is not available in the free SelectPdf community edition. |
The PowerPointToPdf class exposes ConvertFile(String), ConvertStream(Stream) and ConvertBytes(Byte).
The result is a PdfDocument, exactly as the html converter returns one: it can be modified further, saved to a file, a stream or a byte array, and must be closed. The Options, Header and Footer properties mirror the html and Word converters', so a document setup written for HtmlToPdf applies here unchanged - page size and margins, header and footer bands, PDF/A and PDF/X standards, security, viewer preferences, document properties, compression, page ranges and single-page mode. The options are reviewed in Options Review.
Publish decides what the pdf holds:
Slides (the default): one page per slide.
NotesPages: one page per slide, the slide with its speaker notes below it.
Handouts: pages holding SlidesPerHandout slides each (1, 2, 3, 4, 6 or 9; 6 by default). Notes pages and handouts are not produced as a tagged (accessible) document: publish the slides for one.
The slides hidden in the presentation are left out unless ShowHiddenSlides is set.
PageSetup decides what the page size options mean:
Document (the default) makes every page a slide (or a notes or handout page) at the size the presentation defines. The page size and orientation options are ignored; the margins and the header and footer bands are added around it.
Options scales every slide uniformly to fit the page size and orientation of the options, inside their margins and the bands - for example, a widescreen deck printed on A4 landscape pages.
This sample converts a presentation to handouts of four slides on A4 portrait pages, with page numbers.
PowerPointToPdf converter = new PowerPointToPdf(); // four slides on each page, the pages A4 portrait converter.Options.Publish = PowerPointPublish.Handouts; converter.Options.SlidesPerHandout = 4; converter.Options.PageSetup = PowerPointPageSetup.Options; converter.Options.PdfPageSize = PdfPageSize.A4; converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait; // a page-number footer converter.Options.DisplayFooter = true; converter.Footer.Height = 30; converter.Footer.Add(new PdfTextSection(0, 10, 500, "Page {page_number} of {total_pages}", PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 9), new PdfColor(80, 80, 80))); PdfDocument doc = converter.ConvertFile("deck.pptx"); doc.Save("handouts.pdf"); doc.Close();
The slides themselves, as an accessible PDF/UA-1 document:
PowerPointToPdf converter = new PowerPointToPdf(); converter.Options.AccessibilityStandard = PdfUAStandard.UA1; converter.Options.Title = "Quarterly review"; converter.Options.Language = "en-US"; byte[] pptx = File.ReadAllBytes("deck.pptx"); PdfDocument doc = converter.ConvertBytes(pptx); doc.Save("deck.pdf"); doc.Close();
Every font the presentation uses is embedded in the pdf as a subset (or complete, with EmbedCompleteFonts). A font family the host does not have is served from the fonts the library bundles - the Liberation faces, metric-compatible with Arial, Times New Roman and Courier New - so the same presentation converts on a Windows server, a Linux container with no fonts installed, or a Mac. Scripts those faces do not cover (CJK, Arabic, Indic) need fonts installed on the host.
Every PDF/A level and PDF/X-1a are produced the way the html converter produces them, through PdfStandard.
Accessible (tagged) output is declared the way it is on the html and Word converters: Tagged builds the logical structure - the slides' titles, text, lists, tables, pictures with their descriptions and links - and AccessibilityStandard declares PDF/UA-1 or PDF/UA-2 (which is written as PDF 2.0). A declared document needs a Title and a Language. PdfStandard.PdfA3A turns tagging on by itself, and combines with PDF/UA-1; PDF/A-4 is the archiving level that combines with PDF/UA-2.
Give every picture and chart a description in PowerPoint for a document that is accessible in substance and not only in form. Check the produced document at the level it declares with PdfValidator.Validate (Pdf Validation).