I'm using 2.0.0 .NET to place a barcode image in a word document on mailmerge. The target xDimension is .406 mm. This produces an image measured in Word of .94x1.46 inch. Printed and measured the xDimension appears to be about .25 mm. which is too small. This was compared with the existing barcode generation system using Word fonts and is smaller.
Here is the interesting part - a non-linearity - gradually increasing the xDimension, the image width stays the same until reaching .53 mm at which time the image in Word jumps to .94x2.67 inch - now much too large. It stays that size as xDimension is further increased to 1.0 mm., and probably beyond.
Here is the code I am using in VS J#:
BarCodeBuilder bb = new BarCodeBuilder();
// AutoSize = true/false tried with no effect.
// Set the Code text for the barcode bb.set_CodeText("71040343386001192576"); // Drop the text from the code image bb.set_CodeLocation(CodeLocation.None); // Set size to .75 - .8 inch bb.set_BarHeight(20.0f); //20 mm. printed // Remove border bb.set_BorderVisible(false); // Set small bar/space width to 16 mils bb.set_xDimension(0.406f); // .406 mm. printed
Sorry I left that out - it was 128. Here is the event handler code:
private static void HandleMergeImage(Object sender, MergeImageFieldEventArgs e) { if(e.get_FieldName().equals("barcode_data")) { // Find out if a barcode is needed for row and find out the row int recordNum = e.get_RecordIndex(); // Get the requested barcode, skipping the first, label, row String bcRequested = cells.get_Item(recordNum+1, 2).get_StringValue(); // Set blank image if there is no requested barcode if (bcRequested.charAt(0) == ' ') { e.set_ImageFileName(blankImageName); return; }
BarCodeBuilder bb = new BarCodeBuilder();
// Set the Code text for the barcode bb.set_CodeText("71040343386001192576"); // Drop the text from the code image bb.set_CodeLocation(CodeLocation.None); // Set size to .75 - .8 inch bb.set_BarHeight(20.0f); //20 mm. printed // Remove border bb.set_BorderVisible(false); // Set small bar/space width to 16 mils bb.set_xDimension(0.406f); // .406 mm. printed
// Set the symbology type to Code128 bb.set_SymbologyType(Symbology.Code128);
// Pass the image to the document merge e.set_Image(bb.get_BarCodeImage()); }//if(e.get_FieldName().equals("barcode_data")) }
Hmm, I think it could be something about the resolution setting differences.
Could you please set the resolution of BarCodeBuilder to higher? By default the resolution is 96dpi * 96 dpi.
Like:DpiX = 600; DpiY = 600;
//Create doc with Aspose.Word Document doc = new Document(); //Create builder for doc DocumentBuilder builder = new DocumentBuilder(doc); //Insert the BarCode image into doc Aspose.BarCode.BarCodeBuilder bb = new Aspose.BarCode.BarCodeBuilder(); bb.Resolution.DpiX = 600; //set the DpiX to 600 bb.Resolution.DpiY = 600; //set the DpiY to 600 bb.SymbologyType = Aspose.BarCode.Symbology.Code128; bb.xDimension = 0.406f; bb.CodeText = "71040343386001192576"; builder.InsertImage(bb.BarCodeImage);
Thank you for the quick response. I am happy to report that your solution seems to have fixed the problem. There may still be something for your team to work on, of course, as even 96 dpi should resolve to a couple hundreths; but, I don’t need that fixed.