We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to convert some doc pages as pdf pages

Hi, support:
I want to convert some doc pages as pdf pages that keep in the source doc. Does the words.dll support this feature? If so, how to perform it?

That is to say:
for example, a doc has 10 pages, and the third page is to be converted as pdf page, the output doc has 10 pages too, but when open the output doc, and click the third page, the adobe acrobat professional application will be launched to open the pdf page.

@ducaisoft

Please use PdfSaveOptions.PageSet property to render specific number of pages to PDF as shown below. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add five pages to the document.
for (int i = 1; i < 6; i++)
{
    builder.Write("Page " + i);
    builder.InsertBreak(BreakType.PageBreak);
}

PdfSaveOptions options = new PdfSaveOptions();

// Use the "PageSet" property to select a set of the document's pages to save to output PDF.
// In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
options.PageSet = new PageSet(0, 1, 3);

doc.Save(MyDir + "pages.pdf", options);

Thanks for your prompt reply.

I know how to convert a doc page and save it as a separate pdf file.
But my demand is that there is no separate pdf file to be output, and some doc page will display as pdf page. That is to say: the temp pdf will be then inserted into the source doc. how to do it?

@ducaisoft

To ensure a timely and accurate response, please attach your input and expected output documents. We will then provide you more information about your query.

Please refer to the sample input and output docx.
And please pay attention to the output.docx, in which the third page is a pdf page, if clicking the third page in the output.docx, the Adobe Acrobat Application will be called to open the third pdf page. And the content of the third page in the output.docx is same as that in the input.docx.
Input.docx (14.0 KB)
Output.docx (118.4 KB)
Output2.docx (133.0 KB)

@ducaisoft

Yes, you can achieve your requirement using Aspose.Words. Please use the following code example to convert 3rd page of document to OLE (PDF). Hope this helps you.

Document doc = new Document(MyDir + "Input.docx");
//Extract the 3rd page of document and save it image. 
Document page = doc.ExtractPages(2, 1);
MemoryStream pageimage = new MemoryStream();
page.Save(pageimage, SaveFormat.Png);

//Extract the 3rd page and save it to PDF.
page = doc.ExtractPages(2, 1);
MemoryStream pagePDF = new MemoryStream();
page.Save(pagePDF, SaveFormat.Pdf);
pagePDF.Position = 0;
//Extract first two pages of document and insert 3rd page as OLE.
Document dstDoc = doc.ExtractPages(0, 2);
DocumentBuilder builder = new DocumentBuilder(dstDoc);
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.SectionBreakContinuous);

//Set the page margins
PageSetup ps = builder.CurrentSection.PageSetup;
ps.LeftMargin = 0;
ps.RightMargin = 0;
ps.TopMargin = 0;
ps.BottomMargin = 0;
Shape shape = builder.InsertOleObject(pagePDF, "AcroExch.Document.7", false, pageimage);

//Extract the remaining pages of document and insert them after OLE.
page = doc.ExtractPages(3, doc.PageCount - 3);

builder.InsertDocument(page, ImportFormatMode.KeepSourceFormatting);
dstDoc.Save(MyDir + "21.8.docx");