Saving Word Doc to PDF

I am saving a word doc into pdf but I want to restrict it to save only a subset of pages of the word doc. How do i go about doing that? Thanks.

Hi

Thanks for your request. Please try using the following code to achieve what you need:

// Open documents.
Document doc = new Document("C:\\Temp\\in.doc");

// Create PdfSaveOptions object
PdfSaveOptions options = new PdfSaveOptions();

// Set page count
options.PageCount = 3;

// We should set index of the first page to render.
options.PageIndex = 1;

doc.Save("C:\\Temp\\out.pdf", options);

Also, please see this page for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.saving.pdfsaveoptions.pageindex.html

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.saving.pdfsaveoptions.pagecount.html

Best regards,

Well, not quite what I am asking. I just want to save, for example, page 1, 3, & 5 of the Word doc to a pdf. How do I do that? Thanks.

Hi Clarence,

Thanks for your inquiry.

The easiest way to achieve this would be to render the whole PDF using Aspose.Words and then post processing using Aspose.Pdf.Kit to extract only the pages you require and then save this to a new PDF.

Please let us know if this is an acceptable solution to you.

Thanks,

Thank you and that’s exactly what I have done to select pages to save.

The issues you have found earlier (filed as WORDSNET-3110) have been fixed in this Aspose.Words for .NET 20.10 update and this Aspose.Words for Java 20.10 update.

Hi guys,
but it looks like Aspose.Words.Saving.PdfSaveOptions doesn’t have any "PageCount and “PageIndex” properties.

Did i miss something?

Thank you!

@ondrej.hanak,

PageCount and PageIndex properties are no longer part of the PdfSaveOptions Class. We have now added PageSet and PageRange Classes. Sample usage is as follows:

C# example to convert all pages in Word Document to separate PDF files:

Document doc = new Document(@"C:\Temp\input.docx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
PageRange pageRange = new PageRange(0, doc.PageCount - 1); // Specify Range
pdfSaveOptions.PageSet = new PageSet(pageRange);
pdfSaveOptions.PageSavingCallback = new HandlePageSavingCallback();
doc.Save(@"C:\Temp\output.pdf", pdfSaveOptions);

And the definition of Class implementing the IPageSavingCallback interface

private class HandlePageSavingCallback : IPageSavingCallback
{
    public void PageSaving(PageSavingArgs args)
    {
        args.PageFileName = string.Format(@"C:\Temp\Page_{0}.pdf", args.PageIndex);
    }
}