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

Free Support Forum - aspose.com

Having difficulty running example code

I downloaded and installed trial versions of ASPOSE.Words and ASPOSE.PDF on two different systems, one running XP with Visual Studio 2008 and the other running Windows 7 with Visual Studio 2012. I am not able to run your example code for either Words or PDF on either system.


For W7/VS2012: Should your example code run under VS 2012? If I load one of the 2010 sln files, it doesn’t tell me it is converting to 2012 - just gives me a lot of errors and will not run.

For XP/VS2008: If I try to load, for example, the WinForms.2008.sln project, I get 102 errors and 3 warnings. Warnings say something like “The referenced component ‘Aspose.Pdf’ could not be found.” Errors say things like: “Type ‘Pdf’ is not defined.”, “Type ‘Section’ is not defined.”, Type ‘Paragraph’ is not defined."

I must have missed a step when installing. Can you help? Thanks.

Hi there,


Thanks for your inquiry. Yes, you can use Aspose.Words with Visual Studio 2008/2010/2012.

Basically, Aspose.Words is a DLL (Aspose.Words.dll) which provides you the API for working with a document object model. I suggest you please read following documentation links for your kind reference.

Moreover, you can use the Aspose.Words DLL for both ASP.NET and winForms. You can confidently use Aspose.Words for .NET to build any type of x86 or x64 (32-bit or 64-bit) .NET application including ASP.NET, Web Services and WinForms.

I have created a simple console application with following code snippet in Visual Studio 2010. Please test the attached application at your side in Visual Studio 2012 and let us know if you face any issue.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document();<o:p></o:p>

doc.Save("c:\\Out.docx", SaveFormat.Docx);

Hi there,


Further to my last post, the Aspose.Words web demo uses Aspose.Word, Aspose.Cells and Aspose.Barcode references. I have added all reference to the demo application and complied it by using Visual Studio 2012. Please find the Aspose.Words demo in attachment.

Please download and check offline samples of Aspose.Words from here:
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1177.aspx

Hope this answers your query. Please let us know if you have any more queries.

Thanks for the reply and the updated demo code. I am able to get that project to run under VS 2012, but am still missing something basic. It fails with references to files in a ‘Common’ directory that I don’t seem to have. Initially, it was: \common\documents\DinnerInvitationDemo.doc. When I created a sample DinnerInvitationDemo.doc in that directory, I then see a failure with reference to the Northwind DB: ‘C:\Common\Database\Northwind.mdb’ is not a valid path.


Apparently I’m missing part of the basic install files?

I found a Northwind.mdb from another project and was able to get this demo functional using it and my sample Word doc. It only functions for the first ‘Dinner Invitation’ example, however, as when I try to run any of the others they all report various missing documents. I notice that none of these example inputs are HTML. Do you have an example which uses HTML as input with Word and PDF outputs? For my application, I need to take a dynamically created web page and produce both Word and PDF files which can be used as attachments to email. Thanks.

Hi,


Thanks for your inquiry. Please note that when you install Aspose.Words, following will be the directory structure under installed directory for demo application.

install directory\Aspose\Aspose.Words for .NET\Demos

Document and Database : install directory\Aspose\Aspose.Words for .NET\Demos\Common

WebForms and DocumentExplorer :install directory\Aspose\Aspose.Words for .NET\Demos\CSharp
WebForms and DocumentExplorer :install directory\Aspose\Aspose.Words for .NET\Demos\VisualBasic
KenCAC:
I notice that none of these example inputs are HTML. Do you have an example which uses HTML as input with Word and PDF outputs? For my application, I need to take a dynamically created web page and produce both Word and PDF files which can be used as attachments to email.
You can load HTML document into Aspose.Word’s DOM and can convert HTML document into Doc/Docx/Pdf as shown in following code snippet. Could you please share some more information about your query what exact you want to achieve by using Aspose.Words? We will then provide you more information on this along with code.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • “in.html”);<o:p></o:p>

//Your code....

doc.Save(MyDir + "Out.docx", SaveFormat.Docx);

doc.Save(MyDir + "Out.Pdf", SaveFormat.Pdf);


Moreover, If you are facing any issue while using Aspose.Pdf, please post your query at Aspose.Pdf forum.

I am having several issues. First, when I try to run your sample code (just above), the ‘SaveFormat.pdf’ line shows an error: ‘Aspose.Words.SaveFormat’ does not contain a definition for ‘pdf’. When I capitalize the ‘P’ in pdf: ‘SaveFormat.Pdf’, the error goes away. I’m assuming your example code should have had the ‘P’ capitalized?


Regardless, the .Docx and the .Pdf files generated from my HTML code look dramatically different from the HTML as rendered in a browser. I have attached: (1) My original HTML file - note that it is zipped - phstest.htm file with associated files in a phstest_files folder alongside, (2) Aspose generated .Docx, (3) Aspose generated .Pdf, and (4) PDF generated by a client-side printer driver.

I understand that there may be minor differences, but my customer is able to ‘Print to PDF’ from their browser and the generated PDF file looks very close to the HTML rendering - which is what we needed to do on the server with a product like Aspose so that we can remove the dependency of using a PDF printer driver on the client side. The customer is asking why we can’t replicate the results they are seeing with their PDF printer driver on the client side with something like Aspose on the server side and we don’t have a good answer. (See attachment #4 above for the PDF generated on the client side.)

Aside from this issue, the final product needs to stream the HTML directly to Aspose to do the format conversions because the HTML is dynamically generated for custom reporting. I found some example code on your forum for streaming, but when I try to stream my complex HTML page (the one attached) using it, I get an ‘overflow exception’ error. If I substitute a simple, static HTML page, it does not get the overflow exception (although the converted document has formatting issues), so I think the code is correct.

Any help you can provide would be greatly appreciated.

Hi there,


Thanks for your inquiry.
KenCAC:
I am having several issues. First, when I try to run your sample code (just above), the ‘SaveFormat.pdf’ line shows an error: ‘Aspose.Words.SaveFormat’ does not contain a definition for ‘pdf’. When I capitalize the ‘P’ in pdf: ‘SaveFormat.Pdf’, the error goes away. I’m assuming your example code should have had the ‘P’ capitalized?
Please accept my apologies for your inconvenience. Yes, the ‘P’ is capital (SaveFormat.Pdf). Please read Aspose.Words LoadFormat and SaveFormat form following documentation links.
http://www.aspose.com/docs/display/wordsnet/LoadFormat+Enumeration
http://www.aspose.com/docs/display/wordsnet/SaveFormat+Enumeration
KenCAC:
I understand that there may be minor differences, but my customer is able to ‘Print to PDF’ from their browser and the generated PDF file looks very close to the HTML rendering - which is what we needed to do on the server with a product like Aspose so that we can remove the dependency of using a PDF printer driver on the client side. The customer is asking why we can’t replicate the results they are seeing with their PDF printer driver on the client side with something like Aspose on the server side and we don’t have a good answer. (See attachment #4 above for the PDF generated on the client side.)
Please note that Aspose.Words tries to mimic the same behavior as MS Word do. Please convert your document to HTML by using MS Word and check the HTML output. Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting/importing here:
KenCAC:
Aside from this issue, the final product needs to stream the HTML directly to Aspose to do the format conversions because the HTML is dynamically generated for custom reporting. I found some example code on your forum for streaming, but when I try to stream my complex HTML page (the one attached) using it, I get an ‘overflow exception’ error. If I substitute a simple, static HTML page, it does not get the overflow exception (although the converted document has formatting issues), so I think the code is correct.
In this case, I suggest you please use the LoadOptions.BaseUri Property. This property is used to resolve relative URIs into absolute in the following cases:

  • When loading an HTML document from a stream and the document contains images with relative URIs and does not have a base URI specified in the BASE HTML element.
  • When saving a document to PDF and other formats, to retrieve images linked using relative URIs so the images can be saved into the output document.


<span style=“font-size:
10.0pt;font-family:“Courier New”;color:green;mso-no-proof:yes”>// We are
opening this HTML file: <o:p></o:p>

//

//

//

Simple file.

//

//

//

string fileName = MyDir + "Document.OpenFromStreamWithBaseUri.html";

// Open the stream.

Stream stream = File.OpenRead(fileName);

// Open the document. Note the Document constructor detects HTML format automatically.

// Pass the URI of the base folder so any images with relative URIs in the HTML document can be found.

LoadOptions loadOptions = new LoadOptions();

loadOptions.BaseUri = MyDir;

Document doc = new Document(stream, loadOptions);

// You can close the stream now, it is no longer needed because the document is in memory.

stream.Close();

// Save in the DOC format.

doc.Save(MyDir + "Document.OpenFromStreamWithBaseUri Out.doc");


Thanks for the information. Using your example code, I am able to load my HTML without getting the overflow error. However, the ASPOSE-saved .DOC file still looks dramatically different from my HTML page as rendered in a browser. I understand that there are going to be minor differences, but I can open the original HTML page directly in Word 2010 and, other than margin settings, it looks very close to the HTML which is rendered in a browser. Apparently ASPOSE.Words is not going to be able to handle this process with this particular HTML code? In this case, should I be building my document in Word, saving in HTML, then using the saved HTML as a template for my dynamic pages so that Aspose.Words can more accurately make the translation back to Word?


Also, I need to also convert this same HTML to PDF. When trying to save to PDF with Aspose.Words, am I limited by the Word “mimicking” you speak of? As I said earlier in this thread, like the DOC file, the Aspose.Words-saved PDF rendering is very different from the browser-rendered HTML. Should I be using the Aspose.PDF product for that process instead of Aspose.Words? If so, can you provide a working example for that? (I am unable to make the demo code for Aspose.PDF work under Visual Studio 2012.) As I also said earlier, I am able to make an accurate PDF rendering using a client-side PDF printer driver - just need to do the same thing server-side with something like Aspose. Thanks.

Hi there,


Thanks for your inquiry. Could you please attach your input HTML document here for testing? I will investigate the issue on my side and provide you more information.

It is the same document that I attached to my 4-10-2013 posting above.

Hi there,

Thanks for sharing the details. There is an issue while converting HTML to Pdf by using Aspose.Words. The contents under column heading like Overall Wellness Components, Cancer Risk Factors, Heart Risk Factors etc. are missing in output PDF file.

I have logged this issue as WORDSNET-8096 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-8096) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.