I am using the "C39P24DmTt" to create documents with barcodes on them. When the application is run on Windows 7 (32-bit) the document created has the barcode glyth on it. When the application is run on Windows 7 (64-bit) the document created only displays the escape character and not the glyths. I am build the application in Visual Studio 2010 targeting the "Any CPU" platform. The Apose.PDF version is 4.7.0.0.
Here is the code:
public class PdfReportBuilder: IDisposable
{
private Pdf _pdfDoc;
private bool _writeDirectToFile;
private Aspose.Pdf.TextInfo _textInfoDefault8;
private Aspose.Pdf.TextInfo _textInfoDefault6;
private Aspose.Pdf.TextInfo _textInfoBarcode24;
private Aspose.Pdf.Color _borderColor;
public PdfReportBuilder(Pdf pdfDoc, bool writeDirectToFile)
{
_pdfDoc = pdfDoc;
_writeDirectToFile = writeDirectToFile;
InitializeAsposeObjects();
}
// This region defines a standardized implementation of the IDisposable
// interface, providing safe disposal of managed and unmanaged objects.
// The _disposed private field tracks whether the object has already
// been disposed. By default the object is not disposed.
private bool _disposed = false;
/// <summary>
/// Implement IDisposable
/// Do not make this method virtual
/// A derived class should not be able to override this method
/// </summary>
public void Dispose()
{
// Since the code is directly calling the overloaded Dispose method,
// it passes true as the value for the Boolean disposing parameter.
Dispose(true);
// Now that the object has been queued for disposal, take it off
// the Garbage Collector's (GC's) finalization queue.
System.GC.SuppressFinalize(this);
// Note that at this point we are never guaranteed that the object
// has already been disposed. Whenever the GC gets around to it,
// that will be the case. Until then, the private field _disposed
// must be honored -- i.e. checked prior to accessing any fields or
// calling any methods of this class in order to guarantee safe
// code execution.
}
// Dispose(bool disposing) executes in two distinct scenarios.
// If disposing equals true, the method has been called directly
// or indirectly by a user's code. Managed and unmanaged resources
// can be disposed. If disposing equals false, the method has been
// called by the runtime from inside the finalizer and you should
// not reference other objects. Only unmanaged resources can be
// disposed in that case.
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!_disposed)
{
// If disposing equals true then the call has been made by user code.
// It is safe to reference other objects.
// Proceed to dispose all managed and unmanaged resources.
if (disposing)
{
// Dispose all managed resources
_textInfoDefault8 = null;
_textInfoDefault6 = null;
_textInfoBarcode24 = null;
_borderColor = null;
_pdfDoc = null;
if (_newDataTable != null)
{
_newDataTable.Dispose();
_newDataTable = null;
}
}
// Now that all managed resources have been disposed, proceed to dispose
// of all unmanaged resources.
}
// Flag the object as disposed (even though it will not be so until the GC
// decides it is time to do so).
_disposed = true;
}
internal static string CreateReport()
{
bool writeDirectToFile = true;
bool isCreated = false;
// Special handling for reports
string reportName = string.Empty;
FileStream stream = null;
try
{
stream = CreateReportStream(@"Barcode Sheet", out reportName);
if (stream == null)
{
return string.Empty;
}
Pdf pdfDoc;
if (writeDirectToFile)
{
pdfDoc = new Pdf(stream);
}
else
{
pdfDoc = new Pdf();
}
Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense(System.Windows.Forms.Application.StartupPath + @"\aspose.total.lic");
using (PdfReportBuilder reportBuilder = new PdfReportBuilder(pdfDoc, writeDirectToFile))
{
try
{
isCreated = reportBuilder.CreateBarcodeSheet();
}
catch (OutOfMemoryException ex)
{
MessageBox.Show(ex.Message,
@"Report Generation Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
isCreated = true;
}
if (writeDirectToFile)
{
pdfDoc.Close();
}
else
{
pdfDoc.Save(stream);
}
}
}
finally
{
if (stream != null)
{
stream.Close();
}
}
return isCreated ? reportName : string.Empty;
}
private static FileStream CreateReportStream(string headerName, out string reportName)
{
FileStream stream = null;
int counter = 0;
do
{
reportName = string.Format(CultureInfo.CurrentUICulture, Misc.ReportDirectory + @"\{0}_{1}.pdf", FSA.Utility.Misc.UncEncode(headerName), counter);
try
{
// File.Exists here to cover issues with 3rd party PDF readers not putting exclusive lock on the file - ex. FoXiT
if (File.Exists(reportName))
{
File.Delete(reportName);
}
stream = new FileStream(reportName, FileMode.Create);
}
catch (UnauthorizedAccessException)
{
counter++;
}
catch (System.Security.SecurityException)
{
counter++;
}
catch (ArgumentException)
{
counter++;
}
catch (DirectoryNotFoundException)
{
try
{
Directory.CreateDirectory(Misc.ReportDirectory);
}
catch (UnauthorizedAccessException)
{
reportName = string.Empty;
return null;
}
catch (NotSupportedException)
{
reportName = string.Empty;
return null;
}
catch (IOException)
{
reportName = string.Empty;
return null;
}
catch (ArgumentException)
{
reportName = string.Empty;
return null;
}
}
catch (IOException)
{
counter++;
}
} while (stream == null);
return stream;
}
private bool CreateBarcodeSheet()
{
string[] countOne = { @"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10" };
string[] countOneCode = { @"*0*", @"*1*", @"*2*", @"*3*", @"*4*", @"*5*", @"*6*", @"*7*", @"*8*", @"*9*", @"*10*" };
string[] countTwo = { @"Back", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20" };
string[] countTwoCode = { @"*$TV*", @"*11*", @"*12*", @"*13*", @"*14*", @"*15*", @"*16*", @"*17*", @"*18*", @"*19*", @"*20*" };
string[] specCodeName = { @"New Customer", @"Skip", string.Empty, string.Empty, string.Empty, string.Empty, @"Beep High", @"Beep Medium", @"Beep Low", @"No CR", @"CR" };
string[] specCode = { @"*$TX*", @"*0*", string.Empty, string.Empty, string.Empty, string.Empty, @"*.F014$*", @"*.F013$*", @"*.F017$*", @"*.D010$*", @"*.D012$*" };
// Create new section
Section section = _pdfDoc.Sections.Add();
section.PageInfo.Margin.Top = 30;
section.PageInfo.Margin.Bottom = 0;
section.PageInfo.Margin.Left = 20;
section.PageInfo.Margin.Right = 20;
section.PageInfo.PageHeight = PageSize.LetterHeight;
section.PageInfo.PageWidth = PageSize.LetterWidth;
section.IsLandscape = true;
//Title (for Report Titles)
Aspose.Pdf.TextInfo textInfoTitle = new Aspose.Pdf.TextInfo();
textInfoTitle.FontName = @"Helvetica";
textInfoTitle.FontSize = 20;
textInfoTitle.IsTrueTypeFontBold = true;
Table body = new Table(section);
body.ColumnWidths = @"100 125 100 125 150 150";
body.DefaultCellPadding.Bottom = body.DefaultCellPadding.Top = 2;
body.DefaultCellPadding.Left = body.DefaultCellPadding.Right = 2;
body.DefaultCellTextInfo = textInfoTitle;
// Fill Table with bar code information
Row rowItem;
Cell cellItem;
Cell cellBarCode;
Text bcText = null;
Text nameText = null;
Segment segBC = null;
for (int i = 0; i < 11; i++)
{
rowItem = new Row(body);
// Column 1
cellItem = new Cell(rowItem);
nameText = new Text(countOne[i], textInfoTitle);
nameText.TextInfo.Alignment = AlignmentType.Center;
cellItem.Paragraphs.Add(nameText);
rowItem.Cells.Add(cellItem);
// Barcode
cellBarCode = new Cell(rowItem);
cellBarCode.Padding.Top = 1.0F;
cellBarCode.DefaultCellTextInfo = _textInfoBarcode24;
bcText = new Text();
bcText.Segments.Add(@" ");
segBC = new Segment(bcText);
segBC.Content = string.Format(CultureInfo.CurrentUICulture, @"{0}", countOneCode[i]);
segBC.TextInfo = _textInfoBarcode24;
bcText.Segments.Add(segBC);
cellBarCode.Paragraphs.Add(bcText);
rowItem.Cells.Add(cellBarCode);
segBC = null;
bcText = null;
cellBarCode = null;
nameText = null;
cellItem = null;
// Column 2
cellItem = new Cell(rowItem);
nameText = new Text(countTwo[i], textInfoTitle);
nameText.TextInfo.Alignment = AlignmentType.Center;
cellItem.Paragraphs.Add(nameText);
rowItem.Cells.Add(cellItem);
// Barcode
cellBarCode = new Cell(rowItem);
cellBarCode.Padding.Top = 1.0F;
cellBarCode.DefaultCellTextInfo = _textInfoBarcode24;
bcText = new Text();
bcText.Segments.Add(@" ");
segBC = new Segment(bcText);
segBC.Content = string.Format(CultureInfo.CurrentUICulture, @"{0}", countTwoCode[i]);
segBC.TextInfo = _textInfoBarcode24;
bcText.Segments.Add(segBC);
cellBarCode.Paragraphs.Add(bcText);
rowItem.Cells.Add(cellBarCode);
segBC = null;
bcText = null;
cellBarCode = null;
nameText = null;
cellItem = null;
// Column 3
cellItem = new Cell(rowItem);
nameText = new Text(specCodeName[i], textInfoTitle);
nameText.TextInfo.Alignment = AlignmentType.Center;
cellItem.Paragraphs.Add(nameText);
rowItem.Cells.Add(cellItem);
// Barcode
cellBarCode = new Cell(rowItem);
cellBarCode.Padding.Top = 1.0F;
cellBarCode.DefaultCellTextInfo = _textInfoBarcode24;
bcText = new Text();
bcText.Segments.Add(@" ");
segBC = new Segment(bcText);
segBC.Content = string.Format(CultureInfo.CurrentUICulture, @"{0}", specCode[i]);
segBC.TextInfo = _textInfoBarcode24;
bcText.Segments.Add(segBC);
cellBarCode.Paragraphs.Add(bcText);
rowItem.Cells.Add(cellBarCode);
segBC = null;
bcText = null;
cellBarCode = null;
nameText = null;
cellItem = null;
// Add row
body.Rows.Add(rowItem);
rowItem = null;
// Add an extra line between rows
rowItem = new Row(body);
rowItem.Cells.Add(string.Empty);
body.Rows.Add(rowItem);
rowItem = null;
}
// Add Table to section
if (_writeDirectToFile)
{
section.AddParagraph(body);
}
else
{
section.Paragraphs.Add(body);
}
body = null;
// Return
return true;
}
private void InitializeAsposeObjects()
{
//Default 8
_textInfoDefault8 = new Aspose.Pdf.TextInfo();
_textInfoDefault8.FontName = @"Helvetica";
_textInfoDefault8.FontSize = 8;
//Default 6
_textInfoDefault6 = new Aspose.Pdf.TextInfo();
_textInfoDefault6.FontName = @"Helvetica";
_textInfoDefault6.FontSize = 6;
//BarCode 24
_textInfoBarcode24 = new Aspose.Pdf.TextInfo();
_textInfoBarcode24.IsFontEmbedded = true;
_textInfoBarcode24.FontName = @"C39P24DmTt";
_textInfoBarcode24.FontSize = 24;
_textInfoBarcode24.Alignment = AlignmentType.FullJustify;
_borderColor = new Aspose.Pdf.Color(@"Black");
}
}