Free Support Forum - aspose.com

Problems inserting a Barcode into a Word document

Hi,

I'm developing a web application using Aspose.BarCode and Aspose.Word. The application should allow the user to create a barcode and insert it into a Word file. The creation and the visualization on the web of the barcode work fine, but the codebar image inserted into the Word document using Aspose.Word is always the same, no matter what the CodeText is. Only the label containing the CodeText below the bars is different, the bars'sequence is always the same.

I'm working with a demo version of Aspose.BarCode; is the problem due to this fact?

Thank you

Andrea

Hello Andrea,

Thank you for considering Aspose.Barcode.

Normally, that would not happen. I don't think that's due to the demo version's constriction. Please paste the corresponding codes here, so that we could target that issue.

Thanks again.

You are right: in fact I tested my application using a 30 days full licence with no restrictions but the problem still persist. I have pasted the code below: as you will see it is the code of one of the on line Demo Insert to Word, I've made few marginal changes.

Please, note that also the on line Demo Insert to Word doesn't seem to work: changing the CodeText value I always obtain the same barcode's bar sequence into the Word document, while the on line barcode web image changes correctly as soon as the CodeText is changed.

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Aspose.BarCode;

using Aspose.Word;

using Aspose.BarCode.Web.UI;

public partial class BarCodeWord : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

this.btnSet.Click += new System.EventHandler(this.btnSet_Click);

this.btnOutput.Click += new System.EventHandler(this.btnOutput_Click);

}

//Handle btnOutput OnClick evnet, output the barcode image to word document

private void btnOutput_Click(object sender, System.EventArgs e)

{

Aspose.BarCode.License license = new Aspose.BarCode.License();

license.SetLicense("Aspose.BarCode.lic");

//Create BarCode

Aspose.BarCode.LinearBarCode linearBarCode = new Aspose.BarCode.LinearBarCode(this.txtCode.Text, this.BarCodeWebControl1.SymbologyType);

// Setting the bar code format

// linearBarCode.ImageQuality = (ImageQualityMode)Enum.Parse(typeof(ImageQualityMode), this.ddlImageQuality.SelectedValue.Trim(), true);

linearBarCode.ImageQuality = ImageQualityMode.Default;

//Create doc with Aspose.Word

Aspose.Word.Document wordDocument = new Aspose.Word.Document();

//Create builder for doc

Aspose.Word.DocumentBuilder builder = new Aspose.Word.DocumentBuilder(wordDocument);

//Insert the BarCode image into doc

builder.InsertImage(linearBarCode.BitmapImage);

// Save doc to Memory

System.IO.MemoryStream memoryStreamOutput = new System.IO.MemoryStream();

wordDocument.Save(memoryStreamOutput, Aspose.Word.SaveFormat.FormatDocument);

// Free Resources

wordDocument = null;

byte[] memoryStreamOutputBytes;

// Write all Data

memoryStreamOutputBytes = memoryStreamOutput.ToArray();

// Send as file to browser...

Response.ClearContent();

Response.ClearHeaders();

Response.AppendHeader("Content-Disposition", "inline;filename = " + "BarCode.doc");

Response.ContentType = "application/msword";

Response.AddHeader("content-length", System.Convert.ToString(memoryStreamOutputBytes.Length));

Response.BinaryWrite(memoryStreamOutputBytes);

Response.Flush();

Response.Close();

// Free Stream

memoryStreamOutput.Close();

}

private void btnSet_Click(object sender, System.EventArgs e)

{

Aspose.BarCode.License license = new Aspose.BarCode.License();

license.SetLicense("Aspose.BarCode.lic");

this.BarCodeWebControl1.CodeText = this.txtCode.Text;

BarCodeWebControl1.ShowBorder = false;

BarCodeWebControl1.BarHeight = float.Parse(TextBoxBarHeight.Text);

BarCodeWebControl1.xDimension = float.Parse(TextBoxModule.Text);

BarCodeWebControl1.CodeLocation = CodeLocation.Below;

}

}

Dear Andrea,

Thanks for your post.

Please try to use the built-in function of LinearBarCode to transfer the settings between the BarCodeWebControl and LinearBarCode.

public void CopyFrom(Aspose.BarCode.Web.UI.BarCodeWebControl webBarCode)

For example:

LinearBarCode lbc = new LinearBarCode();//creates a linearbarcode instance

lbc.CopyFrom(this.this.BarCodeWebControl1);//copy the setting from the webcontrol

....

I think the CopyFrom will make the tricks for your another post that the image is different from the on shown on the web page.

Thanks very much, and feel free to access me with any problems.

Dear Andrea,

We've released a new hotfix for Aspose.BarCode, verson 1.3.1.0.

Since the hotfix contains a bug fix for Codabar symbology, it is suggest you get the latest version.

Download link:

http://www.aspose.com/Downloads/Aspose.BarCode/1.3.1.0/Default.aspx

Thanks very much, and feel free to access me with any problems.

I'm sorry but I still have the same problem: the Word image and the HTML Image of the same barcode are different (see the attached image). I've installed the last version 1.3.1.0 but it seems that the Word barcode is not in Interleaved2of5 Symbology, while the HTML barcode is.

Beside the CopyFrom() function doesn't seem to work correctly: when I export the linearbarcode to the word doc I get a blank image!Only the following code works correctly:

Aspose.BarCode.LinearBarCode linearBarCode = new Aspose.BarCode.LinearBarCode(this.txtCode.Text, this.BarCodeWebControl1.SymbologyType);

Aspose.Word.Document wordDocument = new Aspose.Word.Document();

//Create builder for doc

Aspose.Word.DocumentBuilder builder = new Aspose.Word.DocumentBuilder(wordDocument);

//Insert the BarCode image into doc

builder.InsertImage(linearBarCode.BitmapImage);

I'm developing with Visual Studio 2005, using Framework 2.0.

Thanks

Andrea

Dear Andrea,



Sorry for any delay.



I have created a web demo to show how to work with BarCodeWebControl
and LinearBarCode to insert barcode images to word documents.



Here is some points:

  1. BarCodeWebControl will not save any property values changed at run-time to its viewstate.

    Therefore, any changed values will be reloaded at each page post-back.
  2. BarCodeWebControl will create a image tab to request the exact barcode image.
  3. In total, we need another field to save the changed values among the
    post-backs, and then use them to create linearbarcode instance,

    finally, the image will be available.



    For example, in the demo, I used txtCode to save the changed CodeText,
    and dropdownlist1 to save the symbologyType. After the user clicked

    the output button, I used the txtcode, dropdownlist to create the linearbarcode and then get th eimage.



    We will include the state saving feature to BarCodeWebControl the days to come. It seems a little bit confusing.



    Thanks very much and feel free to access me with any problems.



    BTW, if you are happy to provide your web project/source code, our developer team will be more than glad to work it out.