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

Free Support Forum - aspose.com

Envelope object support?

Hi

Do you support something like the Envelope object of Word Automation?

I was asked to print addresses on envelopes (for the client currently selected in my application) and I am looking for the best way to do it.

Or maybe you have good suggestions!

Hi Eric,

Thanks for considering Aspose. Yes this sounds easy to do using Aspose.Words. I believe the quickest way to do this is to set up a letter template in your word document and then use mail merge. Please see the documentation page here for full information regarding mail merge.

If you have any queries please feel free to ask.

Thanks,

Hi

I have created a template and i cannot get it to work correctly.

If I use this code, it correctly creates the test.docx document with the correct address:

Dim doc As New Document(IO.Path.Combine(Base.App.PathReports, "Envelope10.docx"))
doc.MailMerge.Execute(New String() {"Address"}, New Object() {pAddress})
doc.Save("c:\temp\test.docx")

doc = Nothing
Return True

But if I try to print it, a blank page comes out of the printer:

Dim doc As New Document(IO.Path.Combine(Base.App.PathReports, "Envelope10.docx"))
doc.MailMerge.Execute(New String() {"Address"}, New Object() {pAddress})
'doc.Save("c:\temp\test.docx")

doc.Print()
doc = Nothing
Return True

I have also attached my template.

Hi Eric,

Please try replacing this line of code doc.MailMerge.Execute(New String() {"Address"}, New Object() {pAddress}) with doc.MailMerge.Execute(New String() {"Address"}, New String() {"Test Address 1"})

You may want to try testing whether this is working properly by first saving the document to disk using doc.Save("Envelope out.docx") and opening it with MS Word.

Also the code on this documentation page regarding print preview may be helpful.

Thanks,

Hi

In my first example, I save the document (in test.docx) and when I open it I can see that the merge has been done correctly.

I have also tested passing a string as you required and it doesn't work.

Can you try with my template?

Hi Eric,

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

Thanks for your request. I cannot reproduce the problem on my side using your template and the latest version of Aspose.Words (9.2.0). You can download this version from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards,

Hi

I already have the latest version.

Is the envelope printed correctly or did you just save it? Any modification to the code?

Because I can save it but nothing prints!

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

Your document was successfully filled with data and printed. I used the following code for testing:

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

doc.MailMerge.Execute(new string[] {"Address"}, new object[] {"My Address"});

PrinterSettings printerSettings = new PrinterSettings();

printerSettings.PrinterName = "hp LaserJet 1010 Series Driver";

doc.Print(printerSettings);

Best regards,

I really don't understand.

I just created a brand new C# test project, copied your code and only blank pages are printed! What I don't understand is that if I save the doc, the saved document contains the dummy "My Address".

Any other ideas? I am about to look around for a working solution.

BTW, I double-checked my Aspose.Words.dll component and it is version 9.2.0.0.

private void button1_Click(object sender, EventArgs e)

{

Document doc = new Document(@"c:\_junk\Envelope10.docx");

doc.MailMerge.Execute(new string[] { "Address" }, new object[] { "My Address" });

//doc.Save(@"c:\_junk\test.docx");

PrinterSettings printerSettings = new PrinterSettings();

printerSettings.PrinterName = "Samsung SCX-4x28 Series PCL6";

doc.Print(printerSettings);

}

Hi

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

Thank you for additional information. Could you please create simple application, which will allow me to reproduce the problem on my side? I will check it and provide you more information.

Also, have you tried using other printer?

Best regards,

You will find attached a test project.

The demo saves the results of the mail merge correctly but only print 2 completly blank pages.

I have also tried on another printer (so far a Samsung and a HP - both laser).

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

Thank you for additional information. But I still cannot reproduce the problem on my side. I have changed just the printer name and the document was successfully printed (in your example it’s two pages, the one of them with data the other is empty).

Best regards,

I don't know what to say other then it is not working on my side.

it is probably printing 2 pages because the license is not set (because it is a demo application).

You can also see which version of the DLL I am using since it is in the bin folder.

One last thing (a shot in the dark), I am on Windows 7 64-bits. Can it be related?

Hi

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

Thank you for additional information and patience. I managed to reproduce the problem on my side using Windows 7 as my test environment. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.

Best regards,

This is reassuring for me. It confirms that I'm not (that) crazy!

Do you have an ETA? If it is more then a week, I will have to find a workaround.

Thanks for your request. Unfortunately, I cannot provide you any reliable estimate regarding this issue at the moment. Please expect a reply before next hotfix (within 3-4 weeks). We might just fix the problem or provide you more information.

Also could you please try executing the following code and sent the output XPS to me:

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

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

doc.MailMerge.Execute(new string[] { "Address" }, new object[] { "My Address" });

PrinterSettings printerSettings = new PrinterSettings();

printerSettings.PrinterName = "Microsoft XPS Document Writer";

printerSettings.PrintToFile = true;

printerSettings.PrintFileName = @"C:\Temp\out.xps";

doc.Print(printerSettings);

Best regards,

Very strange, it is throwing an execption (Win32Exception) "The operation completed successfully" and the file is not getting created.

Hi

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

Thank you for additional information. You can print to file using other printers, which are installed on your side and send output .prn file to us.

Best regards,

I just tried outputing the file to a .prn and the Aspose component is not producing the same file content as if I do it from Word directly!

This is my latest code:

Dim doc As New Document(IO.Path.Combine(Application.StartupPath, "Envelope10.docx"))

doc.MailMerge.Execute(New String() {"Address"}, New String() {pAddress})

Dim ps As New System.Drawing.Printing.PrinterSettings

'ps.PrinterName = "FGL HP LasetJet 4050PCL 6"

'ps.PrinterName = "Microsoft XPS Document Writer"

ps.PrinterName = "Samsung SCX-4x28 Series PCL6"

ps.PrintToFile = True

ps.PrintFileName = IO.Path.Combine(Application.StartupPath, "out.prn")

'doc.AcceptAllRevisions()

'doc.UpdateFields()

doc.Print(ps)

doc.Save(IO.Path.Combine(Application.StartupPath, "test.docx"))

Hi

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

Thank you for additional information. We will keep you informed on any developments regarding this issue.

Best regards,