Hello,
I am using aspose word 13.9, to save a certain page from a word document as image, i was using this code:
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
pageIndex = pageIndex-1;
options.setPageIndex(pageIndex);
options.setResolution(200);
wordDocument.save(imageStream, options);
But now i need to save a certain page from a word document as a document.
But i am not able to find an option setPageIndex inside DocSaveOptions.
Can you advise please,
Thank you
Hi Karine,
Document doc = new Document(“C:\Temp\HeaderFooter+Coordinates.docx”);ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
options.setPageCount(1);// Save each page of the document as Jpeg.
for (int i = 0; i < doc.getPageCount(); i++)
{
options.setPageIndex(i);
doc.save(“C:\Temp\out_” + i + “.jpg”, options);
}
Hello
Thank you for your reply,
It seems i didn’t clarify my request,
I need to save a certain page for example page 12 from a word document as a separate word document not as image.
I need to do something like:
Document doc = new Document(“C:\Temp\HeaderFooter+Coordinates.docx”);//how to set in the options the page index taht i need to save as separate doc file??DocSaveOptions options = new DocSaveOptions(SaveFormat.DOC);
doc.save(“C:\Temp\onePageDoc.doc”, options);
Hi Karine,
Thank you,
I will be waiting the solution,
Do you have an idea on when you can get back to me?
Because we are working on a project and we need to set a delivery date.
Thank you again for your help,
Hi Karine,
Document doc = new Document(“C:\Temp\in.doc”);
LayoutCollector layoutCollector = new LayoutCollector(doc);
doc.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Document pageDoc = splitter.GetDocumentOfPage(12);
pageDoc.save(“C:\Temp\out.doc”);
hello,
thanks for your reply,
i have tried the following:
LayoutCollector layoutCollector = new LayoutCollector(wordDocument);
wordDocument.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Document pageDoc = splitter.GetDocumentOfPage(pageIndex);
pageDoc.getCount();(this returns 1);
pageDoc.save(“c:/new.doc”);
the output document new.doc contains the whole document i was trying to read only one page from,
am i using it wrong? or am i missing anything?
Hi Karine,
please find attached a sample of a simple word document i am working on,
thank you,
Hi Karine,
Thank you for this new version of PageSplitter,
i have tried it on the document i sent earlier and it worked perfectly,
but I’m afraid it doesn’t work on just any document,
please find attached a document i have been testing on and i got the following exception:
java.lang.ClassCastException: com.aspose.words.Table cannot be cast to com.aspose.words.Paragraph
is there any way to solve this problem?
Thanks again,
Hi Karine,
Hi Karine,
Hi Awais,
Thanks for your reply and the effort put into this matter,
Is there any example on how to use this class?
Thanks in advance,
Hi Karine,
Thank you for your reply,
The new package seems to be working fine,
But i’m afraid there is still one problem,
the original document is 23 pages, when i try to switch pages,
The returning document is 28 pages, and if i do the same action again,
The document becomes of 34 pages,
Any advice?
Thank you,
Hi Karine,
LayoutCollector layoutCollector = new LayoutCollector(wordDocument);
wordDocument.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Document pageDoc = splitter.getDocumentOfPage(pageIndex);
DocSaveOptions options = new DocSaveOptions(SaveFormat.DOC);
pageDoc.save(imageStream, options);
//or even the output document in:
// pageDoc.save(“c:/new.doc”);
Hi Karine,
Document doc = new Document(“C:\Temp\ecm.docx”);
LayoutCollector layoutCollector = new LayoutCollector(doc);
doc.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Document pageDoc = splitter.getDocumentOfPage(6);
DocSaveOptions options = new DocSaveOptions(SaveFormat.DOC);
pageDoc.save(“C:\Temp\out.doc”, options);
Hello,
In my case i have the previously attached document,
I need to switch any 2 pages in that document, the application requires this business feature,
so i’m using the code to loop on all the pages in that document, and write the output to an array of bytes as follows:
LayoutCollector layoutCollector = new LayoutCollector(wordDocument);
wordDocument.updatePageLayout();
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Document pageDoc = splitter.getDocumentOfPage(pageIndex);
DocSaveOptions options = new DocSaveOptions(SaveFormat.DOC);
pageDoc.save(imageStream, options);
byte[] array = imageStream.toByteArray();
then every time add the bytes to a vector:
vectBytes<byte[]>.add(bytes);
then write the output bytes:
for (byte[] b : vectBytes) {
System.arraycopy(b,0,allBytes,0, b.length);
}
so if i have a document of 4 pages i need to switch the first 2:
i read the document by this order of page indexes: 2, 1, 3, 4, then do the above and get a new document with the first 2 pages switched,
but the problem in this case is: pages are added the document for exp:
if have a document of 4 pages and i need to switch the first 2,
when the process is over the first 2 pages are switched, but the document becomes of 6 pages,
some of texts are stretched and they do not fit in the page anymore, therefor a new page is added with a few lines or even empty sometimes,
if you need anymore information do not hesitate to contact me,
thanks in advance for your help,