3

I'm using Office 2010 interop and C# 4. How can I convert just the 1st page of a word document to PDF? This question ("How do I convert Word files to PDF programmatically?") helped me to get started but it only shows me how to save the whole document as PDF.

Is there a way:

  • to save just the 1st page as PDF? (most ideal option)
  • delete all remaining pages and then save as PDF?

How do I go about doing it?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
inquisitive_one
  • 1,465
  • 7
  • 32
  • 56

4 Answers4

6

You can click on Save As, change the type to PDF, and above the "save" button, you have an option button. Click on that, and you should have the choice to select which pages you want to convert to PDF.

Manon
  • 69
  • 1
  • 2
1

In case it's helpful for someone, in Word 2016, select Save As option, choose PDF as the file format, on this same window once you've done this a new button 'Options' then will appear to the left of the OK button, click on this and choose the page range that you want save.

MargaretL
  • 11
  • 1
1

Use the SaveasPdf option and save the entire document to Pdf. To get the first page you can use PDFSharp opensource library for processing PDF using C#.

Here is an example to split pdf documents.

Kiru
  • 3,489
  • 1
  • 25
  • 46
0

Using Document.ExportAsFixedFormat is more like it -> MSDN

Then you simply write something like this:

doc.ExportAsFixedFormat(path, WdExportFormat.wdExportFormatPDF, Item: WdExportItem.wdExportDocumentWithMarkup, CreateBookmarks: WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, 
            Range: WdExportRange.wdExportFromTo, From: 1, To: 1);