Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Oct 21, 2021 8:25 am

Hello,

I use Spire.doc to create PDFs using
WordDocument.SaveToFile(outputPDF, Spire.Doc.FileFormat.PDF);

This works fine but I need to create a PDF for eache page of the WordDocument, so if the WordDocument has 3 pages I need 3 PDF files:
Page1.pdf
Page2.pdf
Page3.pdf

Is this possible ?

Heinz4711
 
Posts: 20
Joined: Thu Feb 07, 2019 5:22 pm

Thu Oct 21, 2021 9:32 am

Hello Heinz,

Thanks for your inquiry.
Our products can achieve your requirement. Please download and use Spire.Office Platinum(Hotfix) Version:6.10.0. Here is sample code for reference.
Code: Select all
            Spire.Doc.Document doc = new Spire.Doc.Document();
            doc.LoadFromFile(WordFile);
            Stream pdfStream = new MemoryStream();
            doc.SaveToStream(pdfStream,Spire.Doc.FileFormat.PDF);
            Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
            pdf.LoadFromStream(pdfStream);
            pdf.Split("SplitDocument-{0}.pdf");


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Oct 21, 2021 11:53 am

Hello,

thank you for your answer, it works.

Would it also be possible to create a PDF from a certain page of a Wordfile?
For example if the Wordfile has 10 pages I need only page 5 saved as PDF.

Heinz4711
 
Posts: 20
Joined: Thu Feb 07, 2019 5:22 pm

Fri Oct 22, 2021 5:59 am

Dear Heinz,

Thanks for your feedback.
Sorry there is no direct way to convert the specific pages from Word file to PDF file, but you can first convert the entire Word file to a PDF file, and then remove the pages that are not needed.
Sample code for reference.
Code: Select all
      Spire.Doc.Document doc = new Spire.Doc.Document();
            doc.LoadFromFile(WordFile);
            Stream pdfStream = new MemoryStream();
            doc.SaveToStream(pdfStream, Spire.Doc.FileFormat.PDF);
            Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
            pdf.LoadFromStream(pdfStream);

            int pageCount=pdf.Pages.Count;
            for (int i = pageCount - 1; i > 4; i--)
            {
                pdf.Pages.RemoveAt(i);

            }

            pdf.SaveToFile(pdfFile);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Oct 26, 2021 7:55 am

Dear Heinz,

Greetings from E-iceblue!
Has your issue been solved? Could you please give us some feedback?

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc