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

Free Support Forum - aspose.com

Printing Documents using C# scripts

Hi

I am building a document from a pre-defined template and need to be able to save the document and then print it to a specified printer. I am using C# script to create the code (I am not a C# programmer!!), as shown below, and I am unable to get the printing part of the code to compile. Can I get some assistance or is there a manual I can view? Kind regards, Steve H.

using System;

using AWDotNetController;

using System.Collections.Generic;

using System.Text;

using Aspose.Words;

using Aspose.Words.Viewer;

namespace GenerateDocumentUsingAspose

{

public class GenerateDoc

{

[StartMethodAttribute()]

public void LBAMainDoc(ScriptParameters sp)

{

string Defendant_No = (string)sp.InputVariables["cDEFENDANT_NO"];

string Title = (string)sp.InputVariables["cTITLE"];

string Forename = (string)sp.InputVariables["cFORENAME"];

string Middle_Name = (string)sp.InputVariables["cMIDDLE_NAME"];

string Surname = (string)sp.InputVariables["cSURNAME"];

string Address_Line1 = (string)sp.InputVariables["cADDRESS_LINE1"];

string Address_Line2 = (string)sp.InputVariables["cADDRESS_LINE2"];

string Address_Line3 = (string)sp.InputVariables["cADDRESS_LINE3"];

string Address_Line4 = (string)sp.InputVariables["cADDRESS_LINE4"];

string Postcode = (string)sp.InputVariables["cPOSTCODE"];

string Client_ID = (string)sp.InputVariables["cCLIENT_ID"];

string Client_Name = (string)sp.InputVariables["cCLIENT_NAME"];

string Cosignor_Forename = (string)sp.InputVariables["cCOSIGNOR_FORENAME"];

string Cosignor_Middle_Name = (string)sp.InputVariables["cCOSIGNOR_MIDDLE_NAME"];

string Cosignor_Surname = (string)sp.InputVariables["cCOSIGNOR_SURNAME"];

decimal Current_Balance = (decimal)sp.InputVariables["cCURRENT_BALANCE"];

string DocName = (string)"Q:\\" + Client_ID + "\\" + Defendant_No + "\\LBAMain.doc";

Document doc = new Document("D:\\Litigation\\Templates\\Letters\\LBA.doc");

doc.MailMerge.Execute(

new string[] { "Field 1", "Field 2", "Field3", "Field4", "Field5", "Field6", "Field7", "Field8", "Field9", "Field 10", "Field11", "Field3", "Field4", "Field5", "Field12", "Field13", "Field14", "Field17" },

new object[] { Defendant_No, Title, Forename, Middle_Name, Surname, Address_Line1, Address_Line2, Address_Line3, Address_Line4, Postcode, Client_Name, Forename, Middle_Name, Surname, Cosignor_Forename, Cosignor_Middle_Name, Cosignor_Surname, Current_Balance });

doc.Save( DocName );

doc.printer.Settings("HP9mclarke");

doc.print();

}

}

}

The lines

doc.printer.Settings("HP9mclarke");

doc.print();

are incorrect.

Try to use the following lines instead:

DocumentRenderer renderer = new DocumentRenderer(doc);

renderer.PrinterSettings.PrinterName = "HP9mclarke";

renderer.Print();

Please note, however, that printing capability in Aspose.Words is in beta and very raw. We don't guarantee printing quality to be good or even fail-safe. You can use it on your own risk. We are working on a better printing functionality now and will hopefully release it later this year.

Best regards,

Vladimir

Thanks for the reply. I am a little concerned however, as to when this functionality is likely to be available. I have been routing through various other threads on this forum and noticed that this was scheduled for April 2006 and you are now stating later this year. We were recomended this product and I feel more than a little disappointed!

Kind regards

Steve H

Sorry, the printing capability is not available yet. It was never included in our official feature list and I cannot promise that it will be ready by any specific deadline. We are just working on it and working hard. And will hopefully release it later this year.

Thanks for understanding,

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

We are happy to tell you that the new Rendering Engine has replaced the “old Viewer Beta”. The Rendering Engine can print, save as images or draw onto .NET Graphics object any document page.

Please see Aspose.Words documentation to learn more about new features.

SaveToImage method renders document pages into images:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.document.savetoimage_overloads.html

In additional, new Rendering engine allows you to convert Word document to PDF directly (without using Aspose.Pdf).

SaveToPdf method converts the whole document or selected pages to PDF.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.document.savetopdf_overloads.html

The latest version of Aspose.Words is available for download from here:

http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry158153.aspx

Best regards,