| |
 |
Generate Barcode and Insert Generated Image in MS Word Document |
 |
In this online demo, you can generate the barcode by setting the codetext and selecting the symbology type.
The barcode will be generated and inserted into an MS Word document.
It shows how to integrate Aspose.BarCode with Aspose.Words to insert barcodes in a Word document.
For more details please see the following topics:
Choose image quality, barcode text, symbology and click Update Barcode Image to see how demo generates barcode
image and inserts it into Word document sending the resulting document for your review.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<%@ page language="c#" masterpagefile="~/tpl/Demo.Master" inherits="NewOnline.ToWord, App_Web_tuwfkfry" title="Generate Barcode and Insert Generated Image in MS Word Document" %>
<%@ Register TagPrefix="cc1" Namespace="Aspose.BarCode.Web.UI" Assembly="Aspose.BarCode" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="19"><img src="/Common/images/heading_lft.jpg" alt="" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg"><h2 class="demos-heading-bg" style="text-align: left">Generate Barcode and Insert Generated Image in MS Word Document</h2></td>
<td width="19"><img src="/Common/images/heading_rt.jpg" alt="" width="19" height="41" /></td>
</tr>
</table>
<br />
<p class="componentDescriptionTxt" style="text-align: left">
In this online demo, you can generate the barcode by setting the codetext and selecting the symbology type.
The barcode will be generated and inserted into an MS Word document.
It shows how to integrate Aspose.BarCode with Aspose.Words to insert barcodes in a Word document.<br><br>For more details please see the following topics:
</p>
<ul>
<li style="text-align: left">
<a href="http://www.aspose.com/docs/display/barcodenet/How+to+Integrate+Aspose.BarCode+for+.NET+with+Aspose.Words">Integrate Aspose.BarCode with Aspose.Words</a>
</li>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/set-code-text-for-barcode.html">Set Code Text for Generating BarCode Images</a>
</li>
<li style="text-align: left">
<a href="http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/save-barcode-image-to-streams.html">Generate BarCode Image and Save to Memory Stream</a>
</li>
</ul>
<p class="componentDescriptionTxt" style="text-align: left">
Choose image quality, barcode text, symbology and click <b>Update Barcode Image</b> to see how demo generates barcode
image and inserts it into Word document sending the resulting document for your review.
</p>
<table id="Table1" class="genericTable">
<tr>
<td colSpan="2">
<cc1:barcodewebcontrol id="BarCodeWebControl1" runat="server" Width="128px" Height="72px"></cc1:barcodewebcontrol></td>
</tr>
<tr>
<td style="WIDTH: 118px" align="left">Code Text:
</td>
<td align="left">
<asp:textbox id="txtCode" runat="server" Width="160px">01234567890</asp:textbox></td>
</tr>
<tr>
<td align="left">Image Quality:
</td>
<td align="left">
<asp:DropDownList ID="ddlImageQuality" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="WIDTH: 118px" align="left">Symbology:
</td>
<td align="left">
<asp:DropDownList ID="ddlSymbology" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="WIDTH: 118px">
<asp:button id="btnSet" runat="server" Width="160px"
Text="Update Barcode Image"></asp:button></td>
<td>
<asp:button id="btnOutput" runat="server" Width="160px"
Text="Get Barcode in Word"></asp:button></td>
</tr>
<tr>
<td align="center" colSpan="2">
<P> </P>
<P>
</P>
<P> </P>
</td>
<td> </td></tr>
</table>
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
using System.IO;
using System.Web.UI;
using Aspose.BarCode;
using Aspose.BarCode.Web.UI;
using Aspose.Words;
namespace NewOnline
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class ToWord : Page
{
// Fields
/// <summary>
/// Create the word document and save the barcode image in it
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOutput_Click(object sender, EventArgs e)
{
// create a new word document
Document doc = new Document();
Bitmap bmpImage = this.BarCodeWebControl1.BarCodeImage;
if (null==bmpImage)
{
throw new InvalidDataException("Bar Code image is not defined");
}
// get the image from the barcode control and insert into the document that is created above
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(bmpImage);
// create a new memory steram
MemoryStream stream = new MemoryStream();
// save the word document to the memory stream
doc.Save(stream, SaveFormat.Doc);
byte[] buffer = stream.ToArray();
try
{
if (buffer.Length > 0)
{
int length = buffer.Length;
// clear the response for saving the word document to the browser output stream
Response.Clear();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment;filename = BarCode.doc");
base.Response.ContentType = "application/msword";
Response.AddHeader("Content-length", length.ToString());
//doc.Save(Response.OutputStream, SaveFormat.Doc);
Response.BinaryWrite(buffer);
Response.End();
}
}
finally
{
// close the stream
stream.Close();
}
}
private void btnSet_Click(object sender, EventArgs e)
{
// set the symbology type, image quality and codetext of the barcode control
this.BarCodeWebControl1.SymbologyType = (Symbology)Enum.Parse(typeof(Symbology), this.ddlSymbology.SelectedValue, true);
this.BarCodeWebControl1.ImageQuality = (ImageQualityMode)Enum.Parse(typeof(ImageQualityMode), this.ddlImageQuality.SelectedValue, true);
this.BarCodeWebControl1.CodeText = this.txtCode.Text.Trim();
}
private void InitializeComponent()
{
this.btnSet.Click += new EventHandler(this.btnSet_Click);
this.btnOutput.Click += new EventHandler(this.btnOutput_Click);
base.Load += new EventHandler(this.Page_Load);
}
protected override void OnInit(EventArgs e)
{
this.InitializeComponent();
base.OnInit(e);
LoadSymbologies();
LoadImageQuality();
}
private void LoadImageQuality()
{
Array arrImageQuality = Enum.GetValues(typeof(ImageQualityMode));
ddlImageQuality.DataSource = arrImageQuality;
ddlImageQuality.DataBind();
}
private void LoadSymbologies()
{
Array arrSymbologies = Enum.GetValues(typeof(Symbology));
ddlSymbology.DataSource = arrSymbologies;
ddlSymbology.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
// initialize the barcode control if the page is loaded for the first time
if (!base.IsPostBack)
{
this.BarCodeWebControl1.xDimension = 0.6f;
this.BarCodeWebControl1.BarHeight = 15f;
this.BarCodeWebControl1.BorderVisible = false;
this.BarCodeWebControl1.CodeText = "01234567890";
ddlSymbology.SelectedValue = Symbology.Code128.ToString();
this.BarCodeWebControl1.SymbologyType = Symbology.Code128;
}
}
}
}
|
|
|
|