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

Free Support Forum - aspose.com

Css file where to start

I am trying to evaluate your product. If I can prove that it will do what we want, my company will purchase it. We would buy Aspose.Total for .net. I can’t find any examples that do what I want and I am going in circles. Please guide me on the best way to get to my goal.

  1. Staring with HTML text that has css Class names in it:
    Here is the body of the document
  2. Incorporate the css file somehow into the document. I can either reference the css file or insert the contents of the css file somehow.
  3. Manipulate the document: Add page numbers, headers, footers, etc., also with css classes
  4. Use something like Response.Write() with “application/msword” as a header so that the end-user will receive a word file to open or save.
  5. Finally, do same step as in #4, except convert to pdf first (which I assume is possible with Aspose.PDF.

Adding to this:
Found this example:
which will handle steps 4 and 5 above, but doc.Save does not take the arguments in the example. Note that I am using ver 3.5 of Words.net.

doc.Save(Response, "Aspose.Words.Demos.doc", ContentDisposition.Attachment, SaveOptions.CreateSaveOptions(SaveFormat.Doc));

The version I have has at most 2 arguments allowed for the Save method.

This message was posted using Aspose.Live 2 Forum

Hi there,
Thanks for your inquiry.
A CSS class is imported into the Aspose.Words Document Object Model as a Style. Any content inserted from HTML with a CSS class set has the style automatically applied to it.
You can load HTML content into a brand new document from file or stream like below:

// The HTML string
string htmlText = " span.someClass{color: red;}Here is the body of the document";
// Load HTML from string into a new document
MemoryStream content = new MemoryStream(Encoding.UTF8.GetBytes(htmlText));
Document doc = new Document(content);

or insert an HTML snippet into a specific point at the document builder’s current position in an existing document by using the InsertHtml method like below.

DocumentBuilder builder = new DocumentBuilder(doc);
// Insert HTML from string into an existing document.
The details and properties of a style are stored in the Style class and can be retrieved/modified like below.
// You can retrieve a style using the same name as in CSS. The properties of the style can also be modified through ere.
Style style = doc.Styles["someClass"];
You can then easily set a DocumentBuilder to use this style and insert the styled content:
// Set the current style to the one imported from HTML. Insert some content
builder.Font.StyleName = "someClass";
builder.Writeln("Content formatted with imported style.");

Finally to save a document to a response object you can use the code like you suggested, to save the document in PDF instead all you need to do is change the output file name from .doc to pdf.

doc.Save(response, "Document out.pdf", ContentDisposition.Inline, null);

Note Aspose.Words uses it’s own rendering engine to directly render to the PDF format.
There were some API changes from the older versions which is probably why you can’t find the appropriate members now. The current version you’re using is very old, I strongly suggest for you to use the latest version of Aspose.Words instead. You can download the latest version from here.

Thank you for your interest in Aspose.Words. .NET 3.5 Client Profile excludes System.Web and therefore HttpResponse is not available. This is entirely by design. If you need to use Aspose.Words in ASP.NET application, I would recommend you use .NET 2.0 Client Profile and the following overload of Save method:
Best regards,

Thank you for both responses. I was initially apprehensive about the support for this product due to my initial contact with your company on the phone, but these responses in the forum where complete and not dismissive. I am now more comfortable with my ability to obtain support when needed.
Again, Thanks.

Hi there,
Sure, please feel free to ask anytime you have any queries.