Free Support Forum - aspose.com

ColdFusion 11 Support

I am running ColdFusion 11 32 bit (with the 32 bit Java library, that has support for Word Automation via COM.

I recently upgraded from 32 bit CF7 to 32 bit CF11 and Windows 2012 64 bit, and the COM broke; it connects to the Word object, finds and replaces text within the Word .DOC files, merges and appends.DOCs, adds a header, footer, page numbers, etc. but keeps throwing an error with the .Save() and the .SaveAs("#somefile#") methods. The Cold Fusion user has Read, Write, List and Delete privileges to the Folder that it is trying to save the file to, and the CFFile command can save to the same folder with no error; only CFScript throws errors when trying to save to it. Will your product have the same errors trying to save?

Is Aspose Words .Net or .Java best? (CF11 is Java based, but the server has .NET installed). I will need to find/replace text, merge .DOCs, add headers and footers, page numbers, etc.

I am running ColdFusion 11; is .Net or .Java for Words best? I need to locate and replace text in Word .DOC and .RTF files, merge files, add headers, footers, page numbers to the final Word document after multiple .DOC and .DOCX sections are merged into one document.

Thank you.


This message was posted using Banckle Live Chat 2 Forum
I am running ColdFusion 11 32 bit (with the 32 bit Java library, that has support for Word Automation via COM.

I recently upgraded from 32 bit CF7 to 32 bit CF11 and Windows 2012 64 bit, and the COM broke; it connects to the Word object, finds and replaces text within the Word .DOC files, merges and appends.DOCs, adds a header, footer, page numbers, etc. but keeps throwing an error with the .Save() and the .SaveAs("#somefile#") methods. The Cold Fusion user has Read, Write, List and Delete privileges to the Folder that it is trying to save the file to, and the CFFile command can save to the same folder with no error; only CFScript throws errors when trying to save to it. Will your product have the same errors trying to save?

Is Aspose Words .Net or .Java best? I will need to find/replace text, merge .DOCs, add headers and footers, page numbers, etc.


This message was posted using Banckle Live Chat 2 Forum

Hi Chuck,

Can you please share the exception details? As far as .NET or Java are concerned, you can use any version according to your requirement as both versions offer same features.

Best Regards,

The first thing is that I cannot apply the license in ColdFusion (the license is in the same folder as the Aspose.Words.dll):




Error Occurred While Processing Request


<table border="0" cellpadding="0" cellspacing="0" width="500">
<tbody><tr>
    <td id="tableProps2" align="left" valign="middle" width="500">
        <h1 id="textSection1" style="COLOR: black; FONT: 13pt/15pt verdana">
        Variable LICENSE is undefined.
        </h1>
    </td>
</tr>

<tr><td valign="top"><br></td></tr><tr>
    <td height=""> </td>
</tr>


    		<tr>
    			<td colspan="2" width="400">
    			<font style="COLOR: black; FONT: 8pt/11pt verdana">

    			<br>
    				
    					<b>Called from</b> E:/inetpub/wwwroot/index.cfm: line 3<br>
    				
    			</font></td>
    		</tr>
		
			<tr>
			    <td colspan="2">

				
						<pre>71 :     <cfset assemblyPath="C:\Aspose\Aspose.Words.dll">

72 :
73 : <cfset license = license.SetLicense(“Aspose.Words.lic”)>
74 :
75 : <cfset protocolDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init()>


The below says that Aspose is not defined:
<cfset Aspose.Words.License.SetLicense(“C:\Aspose\Aspose.Words.lic”)>


These are the errors I was getting in COM that you asked about:

<!— instantiate word once —>



wordApp.Visible = false;
docsColl = wordApp.Documents;
protocolDoc = docsColl.Add();
// protocolDoc.SaveAs(#new_t_target_directory# & ‘#newFileName#’);
//The above syntax worked for many years, including in CF7
protocolDoc.SaveAs("#new_t_target_directory##newFileName#");
//CF11 was complaining about the syntax, so I changed it to the above



I am get the following error with the .SaveAs statement when I use COM and CFSCRIPT (not Aspose):







The following information is meant for the website developer for debugging purposes.



Error Occurred While Processing Request


The system has attempted to use an undefined value, which usually indicates
a programming error, either in your code or some system code.

Null Pointers are another name for undefined values.

</font></p><table border="0" cellpadding="0" cellspacing="0" width="500">
<tbody><tr>
    <td id="tableProps2" align="left" valign="middle" width="500">
        <h1 id="textSection1" style="COLOR: black; FONT: 13pt/15pt verdana">
        
        </h1>
    <br></td>
</tr>
<tr>
    <td id="tablePropsWidth" colspan="2" width="400"> 
        <font style="COLOR: black; FONT: 8pt/11pt verdana">
        
        </font>
    <br></td>
</tr>
<tr>
    <td height=""> </td>
</tr>


<tr>
    <td colspan="2">
        <font style="COLOR: black; FONT: 8pt/11pt verdana">
        Resources:
        <ul><li>Check the <a rel="nofollow" href="http://www.adobe.com/go/prod_doc" target="new">ColdFusion documentation</a> to verify that you are using the correct syntax.</li><li>Search the <a rel="nofollow" href="http://www.adobe.com/go/prod_support/" target="new">Knowledge Base</a> to find a solution to your problem.</li></ul>
        <p>
    </p></font></td>
</tr>

<tr>
    <td colspan="2"><br></td>
</tr>
</tbody></table><font style="COLOR: black; FONT: 8pt/11pt verdana">


    <table cellpadding="0" cellspacing="0" width="500">
    <tbody><tr>
        <td valign="top">
            <font style="FONT: 8pt/11pt verdana;">
            Stack Trace 
        </font></td>
    </tr>
    <tr>
        <td id="cf_stacktrace">
            <font style="COLOR: black; FONT: 8pt/11pt verdana">
            
            <br>
            <br>
            <pre>java.lang.NullPointerException


I also am getting an error when I use Aspose.Words (latest evaluation version downloaded 3 days ago):




Error Occurred While Processing Request


<table border="0" cellpadding="0" cellspacing="0" width="500">
<tbody><tr>
    <td id="tableProps2" align="left" valign="middle" width="500">
        <h1 id="textSection1" style="COLOR: black; FONT: 13pt/15pt verdana">
        
        </h1>
    <br></td>
</tr>
<tr>
    <td id="tablePropsWidth" colspan="2" width="400">
        <font style="COLOR: black; FONT: 8pt/11pt verdana">
        
        </font>
    <br></td>
</tr>
<tr>
    <td height=""> </td>
</tr>


    		<tr>
    			<td colspan="2" width="400">
    			<font style="COLOR: black; FONT: 8pt/11pt verdana">

    			The error occurred in <b>C:/temp/test.cfm: line 100</b><br>

    			
    					
    				
    			</font></td>
    		</tr>
		
			<tr>
			    <td colspan="2">

				
						<pre>98 :     <cfset assemblyPath="C:\Program Files (x86)\Aspose\Aspose.Words for .NET\bin\net2.0\Aspose.Words.dll">

99 :
100 : <cfset doc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#new_t_target_directory##newFileName#")>




<!— the following statement is giving me the error. CF11 does not give good error messages, unlike CF7 —>
<cfset doc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#new_t_target_directory##newFileName#")>

It does not give the error if I remove the file path and name from Init:
<cfset doc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init()>

CF7 COM needed the syntax to be:
(#new_t_target_directory# & ‘#newFileName#’)


Could you please give me some examples for how to do the following in ColdFusion with Aspose? I have tried modifying C# and VB methods, etc. but they keep giving me errors. I need to figure this out in a hurry so that my bosses will buy Aspose.Words; otherwise, they are going to buy another product. This is how far I have gotten so far (to the first error below).
I need examples in CF how to:


declare/define Section
declare Sections()
declare fields
.PageSetup
syntax to set LeftMargin, RightMargin, TopMargin, Bottom Margin
InsertAfter(“somephrase”)
InsertParagraphAfter()
declare header, headerRange
header.Range.Font.Size
insert header
declare footer, footerRange
insert footer
I need to insert into the footer: “Page x of y"
also: footerRange.InsertAfter(“Version Date: #dateRevised#”);
.Range
.InsertFile(“somefile”)
.Collapse()
.InsertBreak
.Font.Size
search and replace
doc.Range.MoveStart





<cfset i = i + 1>


<cfset protocolDoc=CreateObject(”.NET", “Aspose.Words.Document”, assemblyPath).Init()>
<cfset saveFormat=CreateObject(".NET", “Aspose.Words.SaveFormat”, assemblyPath)>
<cfset protocolDoc.Save("#new_t_target_directory##newFileName#", saveFormat.Doc)>
<cfset FileSetAttribute("#new_t_target_directory##newFileName#",“normal”)>

<cfset srcDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#settings.template_section_path##directory##template_section_name#.doc")>
<cfset importFormatMode=CreateObject(".NET", “Aspose.Words.ImportFormatMode”, assemblyPath)>
<cfset protocolDoc.AppendDocument(srcDoc, importFormatMode.KeepSourceFormatting)>

<!— The following doesn’t work:
If this is the second document or above being appended then unlink all headers footers in this section
from the headers and footers of the previous section.

Error Occurred While Processing Request
The Sections method was not found.
—>
<cfif i gt 1>




<!— above statement has this error:
Error Occurred While Processing Request
The Sections method was not found.
Either there are no methods with the specified method name and argument types or the Sections method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
>242 :


<!— The following doesn’t work —>


<!— The following doesn’t work —>
<cfset protocolDoc.Sections(i).HeadersFooters.LinkToPrevious(False)>

<!— The following doesn’t work —>
<!— set the margins at one inch–72 points eq 1 inch —>

cfset pSetUp.LeftMargin = 72>

<!— this didn’t work, either:

<cfset lm = pSetUp.LeftMargin = 72>
<cfset rm = pSetUp.RightMargin = 72>
—>
<!— end set page margins —>

<!— either format works:
<cfset protocolDoc.Save("#new_t_target_directory##newFileName#", saveFormat.Doc)>
—>
<cfset protocolDoc.Save(#new_t_target_directory# & “#newFileName#”, saveFormat.Doc)>

<!— I need to replace this COM script with Aspose ColdFusion code: —>

wordApp.Visible = false;
docsColl = wordApp.Documents;
protocolDoc = docsColl.Add();
protocolDoc.SaveAs("#new_t_target_directory##newFileName#");
//set the margins at one inch–72 points eq 1 inch
pSetUp = protocolDoc.PageSetup;
pSetUp.LeftMargin = 72;
pSetUp.RightMargin = 72;
//end set page margins
//add the footer
sections = protocolDoc.Sections;//get the sections collection
section = sections.Item(Val(1));//1=index; returns one section object; vb indicated by brackets; can do in cf
footers = section.Footers;//footers is a property of a section
footer = footers.Item(Val(1));//in this case val(1) is an enumeration == primary
fields = protocolDoc.Fields;//fields collection
footerRange = footer.Range();//getting the range of the footer
footerRange.InsertAfter(“Page “);//nothing in range; so don’t have to go to end
//footerRange = footer.Range();//getting the range of the footer
footerRange.Collapse(0);//go to the end of the footer range
fields.Add(footerRange,Val(33));//adding the field; msdn library – field collection object; Add method; wdFieldPage; oleView – wdFieldType, find the constant
footerRange = footer.Range();//etc. etc. etc.
footerRange.Collapse(0);
footerRange.InsertAfter(” of “);
//footerRange = footer.Range();
footerRange.Collapse(0);
fields.Add(footerRange,Val(26));
footerRange = footer.Range();//etc. etc. etc.
footerRange.Collapse(0);
footerRange.InsertParagraphAfter();
footerRange.InsertAfter(“HSR Submission Number: #settings.ss_study_id#”);
footerRange=footer.Range();
footerRange.Collapse(0);
footerRange.InsertParagraphAfter();
//footerRange.InsertParagraphAfter();
footerRange.InsertAfter(“Version Date: #dateRevised#”);
footerRange = footer.Range();
footerRange.Font.Size = 10;
//end add the footers


//begin add header
sections = protocolDoc.Sections;//get the sections collection
section = sections.Item(Val(1));//1=index; returns one section object; vb indicated by brackets; can do in cf
headers = section.Headers;//footers is a property of a section
header = headers.Item(Val(1));//in this case val(1) is an enumeration == primary
//fields = newDoc.Fields;//fields collection
headerRange = header.Range();//getting the range of the footer
headerRange.Collapse(0);
headerRange = header.Range();//getting the range of the footer
headerRange.Bold = true;
headerRange = header.Range();//getting the range of the footer
headerRange.Collapse(0);
headerRange.InsertAfter(’#study.title#’);
//insert blank lines
headerRange.InsertParagraphAfter();
headerRange.InsertParagraphAfter();
headerRange.Font.Size = 10;
//end add header


<!— end protocolCount eq 0 conditional —>

<cfif is_appendix eq 1>

<cfif trim(template_section_name) is “hipaa_criteria”><!— must enter text at the top of these —>
<!— total number of hippa appendices requrired —>


docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertBreak(Val(7));//page break before appendices
docRange = protocolDoc.Range();
docRange.Collapse(0);
//begin insertion of template name
//docRange.InsertAfter(’#template_section_name#.doc’);
//docRange.MoveStart(Val(2), Val(-1));
//docRange.Font.Size = 16;
//docRange.InsertParagraphAfter();
//docRange.InsertParagraphAfter();
//docRange = protocolDoc.Range();
//docRange.Collapse(0);
//end insertion of template name
docRange.InsertAfter(”#Text#”);
docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertParagraphAfter();
docRange.InsertParagraphAfter();
docRange.MoveStart(Val(2), Val(-#lenText#));
docRange.Font.Size = 14;
docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertFile("#settings.template_section_path##directory##template_section_name#.doc");
docRange = protocolDoc.Range();
docRange.Collapse(0);
//end append the hipaa appendix



<!— not hipaa, still appendix —>

//begin append the non-hipaa appendix doc
docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertBreak(Val(7));//page break before appendices
docRange = protocolDoc.Range();//always retrieve and collapse the range; to go the end so can continue to append docs
docRange.Collapse(0);
docRange.InsertFile("#settings.template_section_path##directory##template_section_name#.doc");
docRange = protocolDoc.Range();
docRange.Collapse(0);
//end append the non-hipaa appendix doc

<!— end hipaa criteria —>

<!— not appendix —>

//begin append non appendix template sections = insertfile
docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertFile("#settings.template_section_path##directory##template_section_name#.doc");
docRange = protocolDoc.Range();
docRange.Collapse(0);
docRange.InsertParagraphAfter();
docRange.InsertParagraphAfter();
//end append non appendix template sections = insertfile







Hi Chuck,

We are investigating the issue with ColdFusion 11. In the meantime, can you please also contact with ColdFusion team on this issue?

Best Regards,

I really need to find out how to access sections, ranges, headers/headerRange, footerRange, and how to add headers and footers in ColdFusion. Also, when I append the sections, it is making a new page in front of each section that I need to know how to get rid of.

I have been able to add the license, and how to Open, Append, and Save documents, but unless I can find out if it possible to do the previously mentioned things, I am going to have to use ColdFusion’s PDF functions instead of Aspose. I really want to use Aspose because the formatting of the documents already look really good, like they used to with Word. Can someone please help with these problems soon? Also, this will help you sell your products to other customers who are using ColdFusion.

Thank you.

The syntax of the code that works:



<!— Install Aspose License using CF Tags —>
<cfset license=CreateObject(".NET", “Aspose.Words.License”, assemblyPath).Init()>
<cfset license.SetLicense(“C:\Aspose\Aspose.Words.lic”)>

<!— Alternate way to Install Aspose License using CFScript —>

license=CreateObject(".NET", “Aspose.Words.License”, assemblyPath).Init();
license.SetLicense(“C:\Aspose\Aspose.Words.lic”);


<cfset consentDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init()>
<cfset saveFormat=CreateObject(".NET", “Aspose.Words.SaveFormat”, assemblyPath)>
<cfset consentDoc.Save("#somepath##somefile#", saveFormat.Doc)>
<cfset FileSetAttribute("#somepath##somefile#",“normal”)>
<cfset srcDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#somepath##somefile#.doc")>

<cfset importFormatMode=CreateObject(".NET", “Aspose.Words.ImportFormatMode”, assemblyPath)>
<cfset consentDoc.AppendDocument(srcDoc, importFormatMode.KeepSourceFormatting)>

A lot of the syntax from C# and VB does not work when changed to CF. You really need more examples in CF.

I
really need to find out how to access sections, ranges,
headers/headerRange, footerRange, and how to add headers and footers in
ColdFusion. Also, when I append the sections, it is making a new page in
front of each section (lots of white space) that I need to know how to get rid of unless I can access Sections. I have
been able to add the license, and how to Open, Append, and Save
documents, but unless I can find out if it possible to do the previously
mentioned things, I am going to have to use ColdFusion’s PDF functions
instead of Aspose. I really want to use Aspose because the formatting of
the documents already look really good, like they used to with Word.
Can someone please help with these problems soon?

I've tried to use CreateObject to create Sections(0), but it says that Sections does not exist in the assembly Aspose.Words.Document

Also, using Section = Documents.Sections(0); says that the section method doesn't exist in Documents

If I could just make a Section, then I could try to add headers, footers and page numbers, and delete the white space between the appended documents.

I forgot to add to the posting that my bosses want me to add page numbers on each page (in the footers), also.

Please let me know as soon as you know how to fix any of these problems, instead of waiting until you are finished with figuring out everything with CF11. For example, how to add Sections(0) would be a big help.


Hi Chuck,

I have recently set up ColdFusion11 on my end and will update you as soon as any samples are ready.

Best Regards,

Thank you, Muhammad.

Programmers who are using ColdFusion and other non-NET languages really need a list of what Objects, Classes, Methods and Properties are available in the .NET Aspose.Words.DLL, along with examples of the syntax that the programmer should use (in CF, etc.) If you made these lists, it would be a big selling point for programmers of non-NET languages.

That’s why it’s been so difficult for me: I’ve been limited to only those objects, methods, etc. that are shown in the CF examples.

I’ve tried to use the Aspose.Words.chm help file, but it doesn’t show the proper syntax in ColdFusion and it is really difficult to try to change the syntax of C# and VB to ColdFusion’s syntax.

The syntax of the code that works:



<!— Install Aspose License using CF Tags —>
<cfset license=CreateObject(".NET", “Aspose.Words.License”, assemblyPath).Init()>
<cfset license.SetLicense(“C:\Aspose\Aspose.Words.lic”)>

<!— Alternate way to Install Aspose License using CFScript —>

license=CreateObject(".NET", “Aspose.Words.License”, assemblyPath).Init();
license.SetLicense(“C:\Aspose\Aspose.Words.lic”);


<cfset protocolDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init()>

<cfset saveFormat=CreateObject(".NET", “Aspose.Words.SaveFormat”, assemblyPath)>

<cfset protocolDoc.Save("#somepath##somefile#", saveFormat.Doc)>
<cfset FileSetAttribute("#somepath##somefile#",“normal”)>

<cfset srcDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#somepath##somefile#.doc")>

<cfset importFormatMode=CreateObject(".NET", “Aspose.Words.ImportFormatMode”, assemblyPath)>

<cfset protocolDoc.AppendDocument(srcDoc, importFormatMode.KeepSourceFormatting)>

                                <br>builder = CreateObject(".NET", "Aspose.Words.DocumentBuilder", assemblyPath).init(); <br>//the above worked with no error<br><br>Some examples of the errors that I am getting are:<br><br>pSetUp = protocolDoc.PageSetup;<br>//Element PAGESETUP is undefined in PROTOCOLDOC.<br><br>sections = protocolDoc.Sections;//get the sections collection<br>//Element SECTIONS is undefined in PROTOCOLDOC. <br><br>Section = protocolDoc.Sections();<br>//The Sections method was not found. <br><br>paragraphs = protocolDoc.GetChildNodes(NodeType.Paragraph, True);<br>//Element PARAGRAPH is undefined in NODETYPE. <br><br>page = protocolDoc.Pages.Add();<br>//Element PAGES is undefined in PROTOCOLDOC. <br><br>section = CreateObject(".NET", "Aspose.Words.Section").init();<br>//Class Aspose.Words.Section not found in the specified assembly list. <br><br>Section=CreateObject(".NET", "Aspose.Words.Section(0)", 

assemblyPath).Init("#somepath##somefile#.doc");
//Class Aspose.Words.Section(0) not found in the specified assembly list.

Section = protocolDoc.Sections(0);
//The Sections method was not found.

protocolDoc.Sections.Clear();
//Element SECTIONS is undefined in PROTOCOLDOC.

Node=CreateObject(".NET", “Aspose.Words.Node”, assemblyPath).Init();
//Unable to find a constructor for class Aspose.Words.Node that accepts parameters of type ( ‘’ ).

Node=CreateObject(".NET", “Aspose.Words.Node”, assemblyPath).Init("#somepath##somefile#.doc");
// Unable to find a constructor for class Aspose.Words.DocumentBuilder that accepts parameters of type ( java.lang.String ).

CompositeNode=CreateObject(".NET", “Aspose.Words.CompositeNode”, assemblyPath).Init();
//Unable to find a constructor for class Aspose.Words.Node that accepts parameters of type ( ‘’ ).

CompositeNode=CreateObject(".NET", “Aspose.Words.CompositeNode”, assemblyPath).Init("#somepath##somefile#.doc");
// Unable to find a constructor for class Aspose.Words.DocumentBuilder that accepts parameters of type ( java.lang.String ).

DocumentBase=CreateObject(".NET", “Aspose.Words.DocumentBase”, assemblyPath).Init("#somepath##somefile#.doc");
// Unable to find a constructor for class Aspose.Words.DocumentBase that accepts parameters of type ( java.lang.String ).

DocumentBase=CreateObject(".NET", “Aspose.Words.DocumentBase”, assemblyPath).Init();
//Unable to find a constructor for class Aspose.Words.DocumentBase that accepts parameters of type ( ‘’ ).

doc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init();
//the above works
doc.Sections(0).PageSetup.SectionStart = Aspose.Words.SectionStart.Continuous;
//The Sections method was not found.

Section=CreateObject(".NET", “doc.Section”);
//Class doc.Section not found in the specified assembly list.

Section=CreateObject(“component”, “doc.Section”);
//Could not find the ColdFusion component or interface doc.Section.

section = doc.FirstSection;
//Element FIRSTSECTION is undefined in DOC.

headersFooters = doc.FirstSection.HeadersFooters;
//Element FIRSTSECTION.HEADERSFOOTERS is undefined in DOC.

section = doc.Section;
//Element SECTION is undefined in DOC.

doc.appendChild(section);
//Variable SECTION is undefined.

section = Section(doc);
//Variable SECTION is undefined.

section = new Section(doc);
//Could not find the ColdFusion component or interface Section.

//Section=doc.Sections(0);
//The Sections method was not found.

doc.Sections.Add(newSection);
//Element SECTIONS is undefined in DOC.

protocolDoc.Sections(0).PageSetup.SectionStart = Aspose.Words.SectionStart.Continuous;
//The Sections method was not found.

section = protocolDoc.getSections().get(0);
//The getSections method was not found.

I am able to create the Document:

<cfset protocolDoc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init()>

<cfset doc=CreateObject(".NET", “Aspose.Words.Document”, assemblyPath).Init("#somepath##somefile#.doc")>

But once I create it, I cannot access any of its properties or methods, as shown in the Aspose.Words.chm for .NET manual. I’m still trying to get sections, ranges, insert headers and footers,
find/replace, insert bar code, etc. to work. If you have any ideas,
please let me know.

In
addition to .Section, .Sections(0), and .FirstSection, can you also
please check how I can access .Range, Header,
Footer, HEADERSFOOTERS, and how to add a bar code from a .png or .jpg
file? Also, find/replace text within a section or range, header or
footer.

Please keep me updated as you find out solutions to this.

Hi Chuck,

Thanks for the details. Our investigation has not been completed yet. We will start posting the pieces of code as soon as the investigation is complete. Sorry for the inconvenience.

Best Regards,

Hi Chuck,

We were able to see the same issue using Aspose.Words for .NET and we are further investigating it. There is no such issue with Aspose.Words for Java. Is it feasible for you to test with Aspose.Words for Java in the meantime?

Best Regards,

Hi Ijaz,

I am trying to use Java for Aspose Words now. I’ve gotten a temporary license for Java, and got it to install.

Now I am getting the following error when trying to flow all of the pages together without a NewPage between each one:

<cfset srcDoc=CreateObject(“java”, “com.aspose.words.Document”).Init("#SomeFolder##SomeFile#.doc")>
<cfset importFormatMode=CreateObject(“java”, “com.aspose.words.ImportFormatMode”)>
(The above two statements work.)

<cfset srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS)>
<!— the above statement doesn’t work. It gives the following error:
Element CONTINUOUS is undefined in SECTIONSTART.
—>

<cfset Section=CreateObject(“java”, “com.aspose.words.Section(0)”).Init("#SomeFolder##SomeFile#.doc")>
<!— the above statement doesn’t work. It gives the following error:
Object Instantiation Exception.
Class not found: com.aspose.words.Section(0)
—>


<!— Append the source document using the original styles found in the source document. (This statement works in Java.) —>
<cfset protocolDoc.AppendDocument(srcDoc, importFormatMode.KEEP_SOURCE_FORMATTING)>

Thank you for your help.
Chuck

Update (September 14, 2015): I cannot do any more with the Java version of Aspose Words than I could with the .NET version, and I am getting a lot of pressure from my bosses to either make some progress on this, or switch to another method.

I
really need to find out how to access sections, ranges,
headers/headerRange, footerRange, and how to add headers and footers in
ColdFusion. Also, when I append the sections, it is making a new page in
front of each section (lots of white space) that I need to know how to get rid of unless I can access Sections. I have
been able to add the license, and how to Open, Append, and Save
documents, but unless I can find out if it possible to do the previously
mentioned things, I am going to have to use ColdFusion’s PDF functions
instead of Aspose. I really want to use Aspose because the formatting of
the documents already look really good, like they used to with Word.
Can someone please help with these problems soon?

I've tried to use CreateObject to create Sections(0), but it says that Sections does not exist in the assembly Aspose.Words.Document

Also, using Section = Documents.Sections(0); says that the section method doesn't exist in Documents

If I could just make a Section, then I could try to add headers, footers and page numbers, and delete the white space between the appended documents.

I forgot to add to the posting that my bosses want me to add page numbers on each page (in the footers), also.

Unfortunately, unless I can make some progress in doing the above very soon, I will have to change all of the code to use CF's PDF commands instead; they can add headers and footers, page numbers and combine document sections without putting extra blank pages at the beginning, end, and in between each section. They only have a few commands, though, and I was hoping to be able to use Aspose Words, because it looks like it can do much more than just that.

Is there any way that you can figure out the exact syntax in CF to do these things?

Thank you for your help.

Hi Chuck,



<!--- the above statement doesn't work. It gives the following error:
Element CONTINUOUS is undefined in SECTIONSTART.

Please try the following code for this purpose. It works at my end.


<!--- the above statement doesn't work. It gives the following error:
Object Instantiation Exception.
Class not found: com.aspose.words.Section(0)

Please use the following code to get any particular section.

If I could just make a Section, then I could try to add headers, footers and page numbers, and delete the white space between the appended documents.

Please use the following code to add header/footer and page number.

<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

You can follow the same pattern to work with any example given in Aspose.Words for Java documentation and share your input document with complete code if you see any issue.

Best Regards,

Hi Muhammad,

I have tried some of the commands that you gave me, and they did work to remove the extra pages and whitespace, and to insert the header and footer into the first section. Could you tell me what ColdFusion syntax to use that will make Aspose insert the same text into the header and footer for all sections? (One line of text in the header and two in the footer.) It seems that every time I append a document, it becomes a new section, and each one needs to have the same header and footer.

Also, I need to insert a bar code (a .png picture file) only in the header only once at the very beginning of the document, not in each section. That is why I wasn’t sure if I should remove all sections before inserting headers.

A very important problem with server crashes has started happening.

Previously, I was using the .Net version of Aspose.Word and I did not get Java heap space errors, although I was getting errors with different .NET commands that did not work correctly in ColdFusion 11, but now that I am using the Java Aspose.Word instead, I am getting server hangs and crashes frequently, with error messages in the CF log files saying that the server has run out of Java Heap Space. In CF Administrator, the settings were originally 256mb Min and 512mb Max and it was crashing often (sometimes every day).

The highest that I could set Java Heap Space is 1024mb Min and 1280mb Max (this is CF11 32bit running on Windows 2012 64 bit). After I increased the Heap Space, it took a week and a half before it ran out of Heap Space and crashed, instead of crashing every day.

I can set Max to 2048mb on another test server with CF11 64bit, but I wonder if that is my problem, because when I increase the Heap Space on CF 32 bit, it still eventually gets errors and crashes – it just takes longer.

Have you ever seen these types of errors? Is it possible that these errors and crashes are happening because I need to destroy the objects that are created for each user when they exit the ColdFusion routine that created the Java objects? If so, how do I do this in CF? If I cfset them = “” or to Nothing, would that help get rid of running out of Java Heap Space and having no room for Garbage Collection?

Note: if I made Maximum JVM Heap Size >= 1536, I could stop CF but not restart it (in services.msc; I had to change Xms and Xmx settings in C:\ColdFusion11\cfusion\bin\jvm.config to lower amounts before it would start. Sometimes, it won’t stop and start by using Restart; in that case, once it stops, then start it (or use the .bat files to do it). Note that you cannot use ColdFusion Administrator unless the ColdFusion 11 Application Server is started. Please note the server has only the Java that CF 11 installed on it (jar files are in the cfusion\bin\ folder).

I got this error when trying to restart CF (this was also in the server’s System Event Log):

The ColdFusion 11 Application Server service terminated with the following service-specific error:

The system cannot find the file specified.

These are the settings that I made to CF11 32bit jvm.config that worked (i.e., the highest values for which CF11 would restart in services.msc):

# Arguments to VM
# Increased Min and Max heap space from -Xms256m -Xmx512m, added -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70, and added -Xint 9-2015 to improve stability (frequent CF hangs running out of heap space and Garbage Collection errors prior to this)

java.args=-server -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70 -Xint -Xms1024m -Xmx1280m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -XX:MaxMetaspaceSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.home={application.home} -Duser.language=en -Dcoldfusion.rootDir={application.home} -Dcoldfusion.libPath={application.home}/lib -Dorg.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER=true -Dcoldfusion.jsafe.defaultalgo=FIPS186Random -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog -Dcoldfusion.classPath={application.home}/lib/updates,{application.home}/lib,{application.home}/lib/axis2,{application.home}/gateway/lib/,{application.home}/wwwroot/WEB-INF/flex/jars,{application.home}/wwwroot/WEB-INF/cfform/jars


Thank you.
Chuck

Hi Chuck,

You can create a HeaderFooter object and loop through each section to use the same HeaderFooter for all sections. To display a different header at the beginning of the document, you can use pageSetup.setDifferentFirstPageHeaderFooter(true). This will allow you to display a different header for the first page. Please check how to create headers/footers and share your input document and expected output document if you see any difficulty in implementing this logic in ColdFusion.

As far as memory issue is concerned, I was not able to see this issue at my end. Aspose objects should be cleared as soon as garbage collector is called. You can adjust your garbage collection settings to improve the performance as you can see in the following topics.

http://www.adobe.com/devnet/coldfusion/articles/coldfusion_performance.html

http://www.talkingtree.com/blog/index.cfm/2010/9/9/JVM-Memory-Management-and-ColdFusion-Log-Analysis

Best Regards,

Hi Muhammad,

I am getting CF timeout errors when CF tries to display the page if I put PAGE or PAGENUMS in the first page’s footer (FOOTER_FIRST) and also put them in the footer of subsequent pages (FOOTER_PRIMARY) ; I can put them in either one or the other, but not both. I’ve worked around the problem by just putting “Page Number: 1” in the footer on the first page and then putting PAGE and PAGENUMS on the rest of the pages. It still would be nice to know how to be able to avoid this timeout error; I am getting that same error for many things now. (After inserting all of the .doc files, I looped in CFSCRIPT and copied all of the info from all of the sections into the first section, then removed the sections other than the first one in order to make everything in one section, so that I could use the primary header and footer.)

The most pressing problem is that I get a timeout error when I try to insert a .png barcode into the header or footer [builder.insertImage(“somefile”);] of the first page (when I have PAGE x of PAGENUMS in the footer of every page except the first one.) They require the barcode.

Do you know what is wrong?

Thanks.
Chuck


Hi Chuck,

We are preparing a detailed example for your reference and will share with you as soon as it is complete. Sorry for the inconvenience.

Best Regards,

Hi Muhammad,

If I try to add a barcode to the text in the header or footer, I get an error and it won’t build the header or footer.
I was able to add the header to the first line of the document (below the header), but they need to add a barcode to the header (or footer) on each page. The barcode is a .PNG file.



//removeSectionBreaks – Combines all sections in the document into one.
// Loop through all sections starting from the section that precedes the last one
// and moving to the first section.
for (i = consentDoc.getSections().getCount() - 2; i >= 0; i–)
{
// Copy the content of the current section to the beginning of the last section.
consentDoc.getLastSection().prependContent(consentDoc.getSections().get(i));
// Remove the copied section.
consentDoc.getSections().get(i).remove();
}

builder.moveToSection(0);

///Insert BarCode (only on certain Consents)
if (isBarCode == true) {
builder.insertImage(“E:#appRoot#\Documentation\ConsentBarCodeS1.PNG”);
}

currentSection = builder.getCurrentSection();
pageSetup = currentSection.getPageSetup();

// Specify if we want headers/footers of the first page to be different from other pages.
pageSetup.setDifferentFirstPageHeaderFooter(true);
// — Create header for the first page. —
pageSetup.setHeaderDistance(20);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);

//Write title in header on first page.
builder.writeln("#study.title#");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_FIRST);
builder.writeln(“HSR Submission Number: #settings.ss_study_id#”);
builder.writeln(“Version Date: #dateRevised#”);
builder.write(“Page Number: 1”);


//Write title in header on subsequent pages.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.writeln("#study.title#");

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
builder.writeln(“HSR Submission Number: #settings.ss_study_id#”);
builder.writeln(“Version Date: #dateRevised#”);

builder.write("Page Number: “);
builder.insertField(“PAGE”); //inserts the page number
builder.write(” of ");
builder.insertField(“NUMPAGES”); //inserts the total number of pages in the document
//FieldType.html NUMPAGES



Can you please tell me how to do this?

Thanks,
Chuck


Hi Chuck,

If you want to insert the same barcode on all pages, you can use the following code.

Document doc = new Document("Barcode.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

builder.insertImage("Image/Barcode1.jpg");

doc.save(“Document
out.docx”
);

If you want to insert a different barcode on each page, you can use something like the following.

Document doc = new Document(“Barcode.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);

<o:p> </o:p>

// The number of
pages the document should have.

int numPages = doc.getPageCount(); ;

// Move the
DocumentBuilder cursor into the primary footer.

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

Field field = null;

<o:p> </o:p>

for (int i = 1; i <= numPages; i++)

{

field = builder.insertField(“IF “);

<o:p> </o:p>

builder.moveTo(field.getSeparator());

<o:p> </o:p>

builder.insertField(“PAGE”);

<o:p> </o:p>

builder.write(” = " + i);

builder.write(” “”);

builder.insertImage(“Image/Barcode” + i + “.jpg”);

builder.write(" “”);

builder.write(" “”);

}

<o:p> </o:p>

builder.write(""");

field.update();

<o:p> </o:p>

doc.save(“Document out.docx”);

Please share your input documents, complete code and expected output document if your requirement is different.

Best Regards,