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

Free Support Forum - aspose.com

For convert split/docx to pdf

I have word document(docx) with some data in each page. I want to split this document based on some criteria(value for a particular field in a line) and convert those to pdf file.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Is possible using Aspose. If yes please advise how?

Hi there,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please share the criteria for which you want to split the document
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

As soon as you get these pieces of information to us we will then provide you more information about your query along with code.

Hi Tahir,

Please see attached word file.This is source file.

You can see “Fleet No” field value in this file. I need to split this file in PDFs file for each "Fleet No"

Attached PDF file is output file for one fleet 12291 , i need to be able to split in same way for all “Fleet No” in file.

This would need to run on Citrix Enviornment on Windows Server 2008 R2

Let me know if feasible in using Aspose.

Thanks
Dhiraj

Hi Dhiraj,


Thanks
for your inquiry. In your case, you need to find the pages on which fleet number exists. Once you have the page number, please use the PageFinder utility to extract the specific pages from the document.

The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages. Please the detail from here:
http://www.aspose.com/docs/display/wordsnet/LayoutCollector+Class
http://www.aspose.com/docs/display/wordsnet/LayoutEnumerator+Class

I have attached the PageFinder code with this post. Hope this helps you. Please let us know if you have any more queries.


Document doc = new Document(MyDir + "ShieldInsurance.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

PageNumberFinder pageFinder = new PageNumberFinder(doc);

string fleetno = "12291";

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

int pageStart = 0, pageEnd = 0;

Boolean blnFirst = true;

foreach (Paragraph para in collection)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{

var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;

//RectangleF location = layoutEnumerator.Rectangle;

int page = layoutEnumerator.PageIndex;


if (blnFirst)

{

pageStart = page;

blnFirst = false;

}

pageEnd = page;

}

}

// Set up the document which pages will be copied to. Remove the empty section.

Document dstDoc = new Document();

PageNumberFinder finder = new PageNumberFinder(doc);

// Split nodes which are found across pages.

finder.SplitNodesAcrossPages(true);

// Remove any nodes on pages that are outside our desired page range.

ArrayList sectionsToRemove = new ArrayList();

sectionsToRemove.AddRange(finder.RetrieveAllNodesOnPages(pageEnd + 1, doc.PageCount + 1, NodeType.Section));

sectionsToRemove.AddRange(finder.RetrieveAllNodesOnPages(0, pageStart, NodeType.Section));

foreach (Section section in sectionsToRemove)

section.Remove();

doc.Save(MyDir + "Out.docx");



<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

Hi Tahir,

Thanks for your assistance on this.

I tried adding the given code. but its not giving final output with the pages for only that fleet.

I tried for 3 fleets 12291, 12296 and 22309. Getting same file in all cases...

Attached are file generated. Realsiized that you creating "dstDoc" but its not been used. Could that be issue.

Code i have use to save as pdf is as something like this.

doc.Save(MyDir + "Out_" + fleetno + ".pdf", SaveFormat.Pdf);

Do you know how will it get pages in output file only for the specific fleet.Thanks again for your help.

Regadrs

Dhiraj

Hi Dhiraj,


Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.10.0) from here:
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/entry507269.aspx

In your case, I suggest you please use the PageSplitter to achieve your requirement. Please check the PageSplitter sample from the offline samples pack.

Please see the following highlighted modified code with PageSplitter. I have attached the PageSplitter code and output Pdf files with this post for your kind reference. Hope this helps you. Please let us know if you have any more queries.



Document doc = new Document(MyDir + "ShieldInsurance.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

PageNumberFinder pageFinder = new PageNumberFinder(doc);

string fleetno = "22309";

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

int pageStart = 0, pageEnd = 0;

Boolean blnFirst = true;

foreach (Paragraph para in collection)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{

var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;


int page = layoutEnumerator.PageIndex;


if (blnFirst)

{

pageStart = page;

blnFirst = false;

}

pageEnd = page;

}

}

// This will build layout model and collect necessary information.

doc.UpdatePageLayout();

// Split nodes in the document into separate pages.

PageSplitter.DocumentPageSplitter splitter = new PageSplitter.DocumentPageSplitter(layoutCollector);

Document finalDoc = splitter.GetDocumentOfPageRange(pageStart, pageEnd);

finalDoc.Save(MyDir + "22309.pdf");


Hi Tahir,

Thanks for assistance so far.

I have tried use the code you have given. I needed to split the file for all fleets in it.

When i deploy this code in our Citrix server. Its taking more than 2 hours and still runing, i could see for some fleets took even more then 20 minutes to search and save file e.g. Fleet : 23401.

Process have not given error but still running for hours.

I have attached here actual log file(PARIS_2013112111270_TCLDKL.html.txt , this is acatually html file , remove txt to see content) and code function file (buildShieldPDFsNew.docx).

Can you please advise if can do something to make faster? Is there any memory issue when going in loop for big chunks becuase earliar few files saved very quickly…

Thanks
Dhiraj

Hi Tahir,

Thanks for assistance so far.

I have tried use the code you have given. I needed to split the file for all fleets in it.

When i deploy this code in our Citrix server. Its taking more than 2 hours and still runing, i could see for some fleets took even more then 20 minutes to search and save file e.g. Fleet : 23401.

Process have not given error but still running for hours.

I have attached here actual log file(PARIS_2013112111270_TCLDKL.html.txt , this is acatually html file , remove txt to see content) and code function file (buildShieldPDFsNew.docx).

Can you please advise if can do something to make faster? Is there any memory issue when going in loop for big chunks because earlier few files saved very quickly… or do i need to release local variables created inside the loop if yes how?

Thanks
Dhiraj

Hi Tahir,

Attaching code function file (buildShieldPDFsNew.docx). here , missed in last post.

Thanks
Dhiraj

Hi Tahir,

One more question. What if we find one fleet in different set of places e.g some fleet i found in Page 10, 14 and 20 (i.e. not continuous). How will Splitter work in that case.

Thanks in advance for your help.

Regards
Dhiraj


Hi Tahir,

After adding few loggings i have found that function

doc.UpdatePageLayout()

is taking more time arond 10 seconds for each fleet(when i tried for just 14 fleets). Is there any workaround for this? or this there any way to make it faster.

Thanks Again

Dhiraj

Hi Dhiraj,

Please accept my apologies for late response.

dlalwani:

When i deploy this code in our Citrix server. Its taking more than 2 hours and still runing, i could see for some fleets took even more then 20 minutes to search and save file e.g. Fleet : 23401.

I have tested the scenario at Windows 7 for Fleet : 23401 and have not found the shared issue. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.10.0) from here and let us know how it goes on your side.
dlalwani:

One more question. What if we find one fleet in different set of places e.g some fleet i found in Page 10, 14 and 20 (i.e. not continuous). How will Splitter work in that case.

In this case, you need to get the page numbers as shared in previous code example and save each page as separate document. Once you have separate document for each page e.g 10, 14, 20, please join the document by using Document.AppendDocument method.

dlalwani:

After adding few loggings i have found that function

doc.UpdatePageLayout()

is taking more time arond 10 seconds for each fleet(when i tried for just 14 fleets). Is there any workaround for this? or this there any way to make it faster.

Can you please advise if can do something to
make faster? Is there any memory issue when going in loop for big chunks
becuase earliar few files saved very quickly…

I have noticed that you are getting Fleet numbers from database. Please create a standalone/runnable simple application (for example a Console Application Project) that demonstrates the problem at your end. Please create a DataTable with the Fleet numbers which are causing problem.


Hi Tahir,

Thanks for response.

I am trying to use AppendDocument as you advised, but its saving as blank document.

I have used below code for fleet 12291, its ins pages 2, 3, 4 , 18 and 216. However Merged Document is saving as blank. Any idea???

foreach (DataRow drFleet in dsFleets.Tables[0].Rows)

{

curFleetId =

Convert.ToInt32(drFleet["fleet_id"]);

Logger.LogInfo("Starting Extract to find Shield Insurance file for Fleet : " + curFleetId);

//Start Fleet loop to extract file for each fleet

string fleetno = "Fleet No:\t" + curFleetId;

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

int pageStart = 0, pageEnd = 0;

Boolean blnFirst = true;

Document finalDocMerged =new Document();

foreach (Paragraph para in collection)

{

if (curFleetId == 12291)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{

var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;

int page = layoutEnumerator.PageIndex;

//if (blnFirst)

if (blnFirst)

{

finalDocMerged.Save(

ConfigurationSettings.AppSettings["ShieldSplitFilePath"].ToString().Trim() + (txtWeekNo.IntVal + 200000).ToString() + "\\" + "ShieldInsurance_" + (txtWeekNo.IntVal + 200000).ToString() + "_" + curFleetId + ".pdf", SaveFormat.Pdf);

pageStart = page;

blnFirst =

false;

}

pageEnd = page;

// Save document for current page

Logger.LogInfo("##### Found Fleet : " + curFleetId + " in Shield File in : " + page + "#####");

// Split nodes in the document into separate pages.

PageSplitter.

DocumentPageSplitter splitter = new PageSplitter.DocumentPageSplitter(layoutCollector);

Logger.LogInfo("&&&&& Created Page Splitter for Fleet : " + curFleetId + " and Page No : " + page + " &&&&&");

Document finalDoc = splitter.GetDocumentOfPageRange(page, page);

Logger.LogInfo("@@@@@ Created final doc Fleet : " + curFleetId + " and Page No : " + page + "@@@@@");

finalDoc.Save(

ConfigurationSettings.AppSettings["ShieldSplitFilePath"].ToString().Trim() + (txtWeekNo.IntVal + 200000).ToString() + "\\" + "tmp_ShieldInsurance_" + (txtWeekNo.IntVal + 200000).ToString() + "_" + curFleetId + ".pdf", SaveFormat.Pdf);

finalDocMerged.AppendDocument(finalDoc,

ImportFormatMode.UseDestinationStyles);

finalDocMerged.Save(

ConfigurationSettings.AppSettings["ShieldSplitFilePath"].ToString().Trim() + (txtWeekNo.IntVal + 200000).ToString() + "\\" + "ShieldInsurance_" + (txtWeekNo.IntVal + 200000).ToString() + "_" + curFleetId + ".pdf", SaveFormat.Pdf);

Logger.LogInfo("====== Saved File for Fleet : " + curFleetId + " and Page No : " + page + "======");

}

}

}

if (pageStart > 0 && pageEnd > 0)

{

// This will build layout model and collect necessary information.

// doc.UpdatePageLayout();

// Logger.LogInfo("--- Updated Page Layout for Fleet : " + curFleetId + " ---");

shieldFleetCount = shieldFleetCount + 1;

}

else

{

Logger.LogInfo("*********** NOT Found Fleet : " + curFleetId + " in Shield File.***********");

}

fleetCount = fleetCount + 1;

progressBar1.PerformStep();

progressBar1.Update();

}

//End For Fleet loop

]

Hi Tahir,

Attached here file for last post, where i can see fleet 12291 in pages 3,4,5 , 18 and 216 and its saving as Blank final document when use AppendDocument. Files are saving indivizually for each page but i needed finally all in one pdf... Please advise asap.

Thanks

Hi Dhiraj,


Thanks
for your inquiry. Please use the following code example to achieve your requirements and let us know if you have any more queries.


Document doc = new Document(MyDir + "ShieldInsurance.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

PageNumberFinder pageFinder = new PageNumberFinder(doc);

string fleetno = "12291";

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

Document finalDocument = new Document();

finalDocument.RemoveAllChildren();

foreach (Paragraph para in collection)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{

var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;

int page = layoutEnumerator.PageIndex;

// Split nodes in the document into separate pages.

PageSplitter.DocumentPageSplitter splitter = new PageSplitter.DocumentPageSplitter(layoutCollector);

Document tempDoc = splitter.GetDocumentOfPage(page);

finalDocument.AppendDocument(tempDoc, ImportFormatMode.KeepSourceFormatting);

}

}

finalDocument.Save(MyDir + "12291.pdf");

finalDocument.Save(MyDir + "12291.docx");

<w:LatentStyles DefLockedState=“false” DefUnhideWhenUsed=“true”
DefSemiHidden=“true” DefQFormat=“false” DefPriority=“99”
LatentStyleCount=“267”>
<w:LsdException Locked=“false” Priority=“0” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Normal”/>
<w:LsdException Locked=“false” Priority=“9” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“heading 1”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 2”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 3”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 4”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 5”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 6”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 7”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 8”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 9”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 1”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 2”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 3”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 4”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 5”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 6”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 7”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 8”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 9”/>
<w:LsdException Locked=“false” Priority=“35” QFormat=“true” Name=“caption”/>
<w:LsdException Locked=“false” Priority=“10” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Title”/>
<w:LsdException Locked=“false” Priority=“1” Name=“Default Paragraph Font”/>
<w:LsdException Locked=“false” Priority=“11” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtitle”/>
<w:LsdException Locked=“false” Priority=“22” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Strong”/>
<w:LsdException Locked=“false” Priority=“20” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Emphasis”/>
<w:LsdException Locked=“false” Priority=“59” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Table Grid”/>
<w:LsdException Locked=“false” UnhideWhenUsed=“false” Name=“Placeholder Text”/>
<w:LsdException Locked=“false” Priority=“1” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“No Spacing”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 1”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 1”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 1”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 1”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 1”/>
<w:LsdException Locked=“false” UnhideWhenUsed=“false” Name=“Revision”/>
<w:LsdException Locked=“false” Priority=“34” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“List Paragraph”/>
<w:LsdException Locked=“false” Priority=“29” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Quote”/>
<w:LsdException Locked=“false” Priority=“30” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Quote”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 1”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 1”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 1”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 1”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 1”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 1”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 2”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 2”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 2”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 2”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 2”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 2”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 2”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 2”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 3”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 3”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 3”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 3”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 3”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 3”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 3”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 3”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 4”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 4”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 4”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 4”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 4”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 4”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 4”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 4”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 5”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 5”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 5”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 5”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 5”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 5”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 5”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 5”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 6”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 6”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 6”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 6”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 6”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 6”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 6”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 6”/>
<w:LsdException Locked=“false” Priority=“19” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtle Emphasis”/>
<w:LsdException Locked=“false” Priority=“21” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Emphasis”/>
<w:LsdException Locked=“false” Priority=“31” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtle Reference”/>
<w:LsdException Locked=“false” Priority=“32” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Reference”/>
<w:LsdException Locked=“false” Priority=“33” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Book Title”/>
<w:LsdException Locked=“false” Priority=“37” Name=“Bibliography”/>
<w:LsdException Locked=“false” Priority=“39” QFormat=“true” Name=“TOC Heading”/>
</w:LatentStyles>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

Hi Tahir/Aspose Team,



We had this conversation in late last year. After that we have been using Aspose.Word and written code as suggested to split the word file into separate PDFs.

Program has been running well so far. But for last few times when it doing split for some reason file generated for first fleet 12289 is not getting all pages from file. Please attached sources word file (ShieldInsurance(2).docx) and splitted .pdf file generated for fleet 12289 (incorrectly) . Also attached pdf file for fleet 12296 is generated correctly.

Problem is Source word file has 3 pages for fleet (search keyword) 12289 but when program runs it graps only one page. It works fine for all other fleets e.g. 12296 has been generated correctly with 2 pages.



Below is the currently used code.



private void buildShieldPDF

{

try

{

Aspose.Words.License license = new Aspose.Words.License();

license.SetLicense(“Aspose.Words.lic”);

Document doc = new Document(ConfigurationSettings.AppSettings[“FileLocationPath”].ToString().Trim() + “ShieldInsurance.docx”);



LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

PageNumberFinder pageFinder = new PageNumberFinder(doc);

int curFleetId;

//Get Fleets List

string sql;

int fleetId = 0;

int fleetCount;

int shieldFleetCount;

fleetCount = 0;

shieldFleetCount = 0;

sql = “SQL to get fleet list from table…”



IDataAdapter daFleets = AppConfig.IngresProvider.GetDataAdapter(sql, AppConfig.IngresConnection);

DataSet dsFleets = new DataSet();

daFleets.Fill(dsFleets);

Logger.LogInfo(“No. of rows found : " + dsFleets.Tables[0].Rows.Count);

progressBar1.Minimum = 0;

progressBar1.Maximum = dsFleets.Tables[0].Rows.Count;

progressBar1.Step = 1;

if (dsFleets.Tables[0].Rows.Count > 0)

{

progressBar1.Visible = true;

foreach (DataRow drFleet in dsFleets.Tables[0].Rows)

{

curFleetId = Convert.ToInt32(drFleet[“fleet_id”]);

Logger.LogInfo(“Starting Extract to find Shield Insurance file for Fleet : " + curFleetId);

//Start Fleet loop to extract file for each fleet

string fleetno = “Fleet No:\t” + curFleetId;

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

int pageStart = 0, pageEnd = 0;

Boolean blnFirst = true;

Document finalDocMerged = new Document();

finalDocMerged.RemoveAllChildren();

foreach (Paragraph para in collection)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{



var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;

int page = layoutEnumerator.PageIndex;

if (blnFirst)

{

pageStart = page;

blnFirst = false;

}

pageEnd = page;



// Split nodes in the document into separate pages.

PageSplitter.DocumentPageSplitter splitter = new PageSplitter.DocumentPageSplitter(layoutCollector);

Document tempDoc = splitter.GetDocumentOfPage(page);

finalDocMerged.AppendDocument(tempDoc, ImportFormatMode.KeepSourceFormatting);



}



}



if (pageStart > 0 && pageEnd > 0)

{

shieldFleetCount = shieldFleetCount + 1;

finalDocMerged.Save(ConfigurationSettings.AppSettings[“ShieldSplitFilePath”].ToString().Trim() + (txtWeekNo.IntVal + 200000).ToString() + “\” + “ShieldInsurance_” + (txtWeekNo.IntVal + 200000).ToString() + “_” + curFleetId + “.pdf”);

}

else

{

Logger.LogInfo(”*********** NOT Found Fleet : " + curFleetId + " in Shield File.***********”);

}



fleetCount = fleetCount + 1;



}//End For Fleet loop

MessageBox.Show(“Shield Insurance File Splitted Successfully for " + shieldFleetCount + " fleets”);

}

else

{

progressBar1.Visible = false;

MessageBox.Show(“No Fleet found to extract Shield Insurance File.”);



}

}

catch (Exception e)

{

progressBar1.Visible = false;

MessageBox.Show(“Some Error Occured in splitting Shield Insurance File(s)”);



}

}

Hi there,

Thanks for your inquiry.

I suggest you please use the latest version of Aspose.Words for .NET 14.5.0. Please use the following modified code. Hope this helps you. Please let us know if you have any more queries.


Document doc = new Document(MyDir + "ShieldInsurance.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

// Split nodes in the document into separate pages.

DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

string fleetno = "12289";

var collection = doc.GetChildNodes(NodeType.Paragraph, true);

Document finalDocument = new Document();

finalDocument.RemoveAllChildren();

foreach (Paragraph para in collection)

{

if (para.ToString(SaveFormat.Text).Trim().Contains(fleetno))

{

var renderObject = layoutCollector.GetEntity(para);

layoutEnumerator.Current = renderObject;

int page = layoutEnumerator.PageIndex;

Document tempDoc = splitter.GetDocumentOfPage(page);

finalDocument.AppendDocument(tempDoc, ImportFormatMode.KeepSourceFormatting);

}

}

finalDocument.Save(MyDir + "12289.pdf");

finalDocument.Save(MyDir + "12289.docx");