Windows Presentation Foundation Print Label (Zebra Printer) - c#

I am trying to print text to display vertical in Windows Forms Host. The label is printing with report viewer in WPF. Here is my code:
// boolean is based on true or false, when printing labels
private bool _isReportViewerLoaded;
// method to display data in .rdlc
private void ReportViewer_Load(object sender, EventArgs e)
{
// if equal false run this code isReportViewerLoaded
if (!_isReportViewerLoaded)
{
// get the lot based on the parameter Id
Lot lot = BottleLotRespository.GetLotById(this.Parameter);
// settings the page settings
PageSettings pg = new PageSettings();
pg.PrinterSettings
.DefaultPageSettings
.Margins = new Margins(0, 0, 0, 0);
pg.Landscape = false;
PaperSize size = new PaperSize("110.0 x 74.0", 433, 100);
BottleLotDataSet bottleLotDataSet = new BottleLotDataSet();
DataTable reportDataTable = bottleLotDataSet.LotDataTable;
DataRow lotRow = reportDataTable.NewRow();
lotRow["Id"] = lot.Id;
lotRow["Number"] = lot.Number.ToString();
reportDataTable.Rows
.Add(lotRow);
bottleLotDataSet.BeginInit();
this._reportViewer.SetPageSettings(pg);
this.reportDataSource.Name = "DataSet1";
this.reportDataSource.Value = reportDataTable;
this._reportViewer
.LocalReport
.DataSources
.Add(this.reportDataSource);
this._reportViewer
.LocalReport
.ReportEmbeddedResource = "BottleLotWPF.View.Report1.rdlc";
bottleLotDataSet.EndInit();
_reportViewer.RefreshReport();
_isReportViewerLoaded = true;
}
}
My problem is that the Report1.rdlc is not allowing me to rotate the text and there is no settings for it. Is there away of adding a setting to it to rotate the text?

In RDLC we have the option to print vertically it seems.
please take look at the existing thread here and see if it helps.
display-text-vertically-start-

Related

Color formatting not applied to my XtraTreeList column in devexpress at time of preview

On clicking Print prieview:
private void PrintPreview_Click(object sender, EventArgs e)
{
// Adding treeList Component and it's look and feel.
PreviewPrintableComponent(treeList, treeList.LookAndFeel);
}
Code responsible for print preview:
void PreviewPrintableComponent(IPrintable component, UserLookAndFeel lookAndFeel)
{
// Create a link that will print a control.
PrintableComponentLink link = new PrintableComponentLink()
{
PrintingSystemBase = new PrintingSystemBase(),
Component = component,
Landscape = true,
PaperKind = PaperKind.A5,
Margins = new Margins(20, 20, 20, 20)
};
// I believe somewhere here I need to do something about formatting in
// 'component' and 'lookAndFeel'.
// creating preview doc
link.CreateDocument();
// showing preview
link.ShowRibbonPreview(lookAndFeel);
}
The code for formatting my TreeList. This code is run during compile time as it is event generated at design time:
private void TreeList_NodeCellStyle(object sender, GetCustomNodeCellStyleEventArgs e)
{
// "Number" is name of column in which color formatting is applied
if (e.Column.FieldName == "Number")
{
// Changing color to red for negative value.
if (Convert.ToInt32(e.Node.GetValue(e.Column.AbsoluteIndex)) < 0)
{
e.Appearance.ForeColor = Color.Red;
}
}
}
Try setting the TreeListOptionsPrint.UsePrintStyles property to false in order to use the appearance you specified in the NodeCellStyle event.

mapscript : adding Label to Layer with persian text

I am having some issues using Persian text as label. I am using C# mapscript. I am setting the following at runtime:(like button click)
private void addLayer(String layerName)
{
if (layer == null)
{
//create a layer
layer = new layerObj(mapInstance);
layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
layer.status = mapscript.MS_ON;
layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
}
// Create a classObj
OSGeo.MapServer.classObj classobj = new OSGeo.MapServer.classObj(layer);
//create Label
labelObj label = new labelObj();
label.font = "sc";
label.type = MS_FONT_TYPE.MS_TRUETYPE;
label.encoding = "utf-8";
classobj.addLabel(label);
//add user data
//create feature
shapeObj feature = new shapeObj(mapscript.MS_SHAPEFILE_POINT);
lineObj line = new lineObj();
pointObj point = new pointObj(50,50, 0, 0);
line.add(point);
feature.add(line);
feature.text = "این متن فارسی است :گژپچ";
layer.addFeature(feature);
}
But labels are displayed as '?????'.
how can i fix this? Is there any conversion I need to do before setting the text value?
Appreciate any help
Try using different font file: label.font = "sc";.
The ‘□’ comes when it can't find the letter in that .ttf file.(May be it is not mapped to ttf or mapped to a different Unicode character). You can either go into .ttf file and change the font geometry or you can install different font files to get the correct one.

WPF Printing prints on 1 system and not on other

I have a WPF application in which I have 3 forms of prints. In 2 ways, I use directly a window's visual and use PrintVisual(myPanel, "Title") to print it. And in 3rd, I got to print multiple pages so I am using FlowDocument, StackPanel and finally IDocumentPaginatorSource and call PrintDocument to print.
All the code is working perfectly on my system. I can perform Print on OneNote and XPS and it works as expected. But the same app, when I try to run on other system it shows blank page for all 3 prints. PrintVisual is supported on .NET 3.0, 3.5, 4.0, 4.5, so I can't find a reason for it not to work.
I will also share my some code, for better clarity :
// 1 PRINT
public void PrintRegister()
{
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == true)
pd.PrintVisual(this, "Register Window");
return;
}
// 2 PRINT
public static void PrintAttendanceOf(System.Data.DataRow r1) {
PrintLayoutWindowPORT plw = PrintUtility.CreatePrintLayoutWindowPORTObject(r1); // PORTRAIT
Canvas p1 = PrintUtility.CloneCanvas(plw._PrintCanvas, 5);
Grid myPanel = new Grid();
myPanel.Margin = new Thickness(10);
myPanel.Children.Add(p1);
PrintDialog pd = new PrintDialog();
pd.PageRangeSelection = PageRangeSelection.AllPages;
PrintQueue pq = pd.PrintQueue;
pq.DefaultPrintTicket.PageOrientation = PageOrientation.Portrait;
pd.PrintTicket = pq.DefaultPrintTicket;
double pageWidth = pd.PrintableAreaWidth;
double pageHeight = pd.PrintableAreaHeight;
myPanel.Measure(new Size(pageWidth, pageHeight));
//myPanel.Arrange(new Rect(new Point(1, 1), myPanel.DesiredSize));
myPanel.UpdateLayout();
if (pd.ShowDialog().GetValueOrDefault(false))
{
pd.PrintVisual(myPanel, "Attendance Chart");
}
pd = null;
plw.Close();
plw = null;
myPanel = null;
p1 = null;
return;
}
Code for the 3rd Print i.e. Multiple Pages is quiet long, hence have not added it now here. If required, can post it.
Can anyone help me know the reason for printing blank page and no contents on other system. I feel some sort of compatibility or system or resource may be required or what else?
Any help is highly appreciated.
Thanks

PrintDocument using multiple page sizes

Working in .NET 3.5.
Summary:
Trying to replicate functionality of an existing third party component, which breaks in Windows 7.
Until now the user could select a bunch of image files to print, specify a page size for each image and then send them off to print all in one go. I am in dire need of a conceptual explanation of how to go about printing switching the page size on the fly when printing each page.
Details
So far I have figured out how to print multiple images all with the same page size. I use a list of images and use a PrintDocument object, setting the HasMorePages property of the PrintPageEventArgs to true until I reach the end of the list.
Here's a class I quickly threw together to test this:
public partial class Form1 : Form
{
private List<Image> images { get; set; }
private PrintDocument printDocument { get; set; }
public Form1()
{
InitializeComponent();
this.images = new List<Image>();
this.images.Add(Image.FromFile(#"C:\test60.bmp"));
this.images.Add(Image.FromFile(#"C:\SuperLargeTest.jpg"));
this.printDocument = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
};
this.printDocument.PrintPage += printDocument_PrintPage;
}
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
e.PageSettings.PaperSize = this.paperSizes[this.currentImageIndex];
RectangleF marginBounds = e.MarginBounds;
RectangleF printableArea = e.PageSettings.PrintableArea;
int availableWidth = (int)Math.Floor(printDocument.OriginAtMargins ? marginBounds.Width : (e.PageSettings.Landscape ? printableArea.Height : printableArea.Width));
int availableHeight = (int)Math.Floor(printDocument.OriginAtMargins ? marginBounds.Height : (e.PageSettings.Landscape ? printableArea.Width : printableArea.Height));
g.DrawRectangle(Pens.Red, 0, 0, availableWidth - 1, availableHeight - 1);
g.DrawImage(this.images[currentImageIndex], printableArea);
e.HasMorePages = ++currentImageIndex < this.images.Count();
}
private void button1_Click(object sender, EventArgs e)
{
this.printDocument.OriginAtMargins = false;
this.printDocument.Print();
}
}
The thing that I really can't figure out is how to go about changing the page size for, say, the second image.
If I wanted the first image to print in A4 and then the second one to print on A3, how would I go about doing that?
I found this SO question here which seemed to suggest changing the PageSize in the PrintPageEventArgs, but had no joy there.
I also tried to use the QueryPageSettingsEventArgs event and set the PageSettings there, but that didn't seem to work either...
What I would like to achieve is print multiple pages of different size as a single document. Any suggestions, links, explanations, sample code would be very much appreciated.
Anything in C# or VB.NET is fine.
That's work for me too.
Translated to C#:
private bool SetPaperSize(PrintDocument pd, PaperKind nKind)
{
foreach(System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes)
{
if (ps.Kind == nKind)
{
pd.DefaultPageSettings.PaperSize = ps;
return true;
}
}
return false;
}
In VB.NET .. You can use this Sub ..
DocPrint is PrintDocument var
Sub SetPaperSize(ByVal nKind As PaperKind)
Dim ps As PaperSize
For ix As Integer = 0 To DocPrint.PrinterSettings.PaperSizes.Count - 1
If DocPrint.PrinterSettings.PaperSizes(ix).Kind = nKind Then
ps = DocPrint.PrinterSettings.PaperSizes(ix)
DocPrint.DefaultPageSettings.PaperSize = ps
End If
Next
End Sub
Hope this help ..
If you want all the pages to appear as one job (in short avoid being interleaved with other jobs), you can set the page size for the next page inside the PrintPage event handler by changing the default page size of the PrintDocument object.

Why does auto Zoom/Scroll not work for my Chart?

to make it short I checked on the "WinFormsChartSamples" provided by Microsoft. What I wanted to know is how to enable zooming and scrolling for Chartcontrols. The example which is shown there is pretty short.
using System.Windows.Forms.DataVisualization.Charting;
...
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
...
I tried this and nothing happened, no zooming and no scrolling. I tried two things:
In Form1.Designer.cs I added that information to the chart.
chartArea1.Name = "ChartArea1";
chartArea1.CursorX.AutoScroll = true;
chartArea1.CursorY.AutoScroll = true;
chartArea1.AxisX.ScaleView.Zoomable = true;
chartArea1.AxisY.ScaleView.Zoomable = true;
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Cursor = System.Windows.Forms.Cursors.Cross;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(297, 62);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(963, 668);
this.chart1.TabIndex = 6;
this.chart1.Text = "chart1";
I tried to add it directly into the constructor in Form1.cs.
Perhaps it is important to mention that I am using OpenFileDialog in order to add data to the series:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";
//First the description of the file separated by "|"
fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = #"C:\";
//Show Messagebox if the file was loaded (Source: MSDN - FileDialog.FilterProperty)
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("The File was loaded successfully.");
try
{
if ((fileStream = fDialog.OpenFile()) != null)
{
using (fileStream)
{
//Insert code for reading the stream here.
Spectrum newSpectrum = new Spectrum(chart1.Series.Count, fDialog.FileName,
fDialog.SafeFileName, DataHandler.readSpectrumFromFile(fileStream));
addSpectrumToView(newSpectrum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Any advice is welcome, thanks in advance,
BC++
I think you were actually really looking for this:
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
used in conjunction with what you already have should work well, which should look like this:
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
// Allow user selection for Zoom
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
Have a look here: http://archive.msdn.microsoft.com/mschart There is an example there which does zooming/scrolling and much, much more! :)
To enable easy zooming, add a trackbar and use it to zoom:
private void trackBar1_Scroll(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
(etc for however many chart areas you have)
}
the "maximium - value" is to so that the higher the trackbar value, the fewer points are shown (closer zoom)
and make sure that in designer the 'chart1->ChartAreas->Axes->(whichever axes)->scaleview->zoomable' is set to true
A scroll bar will normally appear when a datapoint exceeds the scaleview size of an axis, if it has been set (scrolling doesn't really work reliably if left at 'auto'), if it hasn't, set it, if a scrollbar doesn't appear, a trackbar can yet again be used:
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Position = trackBar2.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Position = trackBar2.Value;
(etc for however many chart areas you have)
}
Make sure you set the "Maximum" in the trackbars to a nice high number (eg 5000) and "Value" to what you desire it to load at.
Have yet to notice too much of a difference between "trackBar_Scroll" and "trackBar_ValueChanged", except "ValueChanged" works if the trackbar is moved by the program or user mouse click, whereas "Scoll" only works if moved by users mouse click.
Anything I missed?
My users dislikes the standard behavior of the mschart zooming and scrolling. That's why I implement a mouse based zoom/scroll that use dragging and mousewheel on axises.
The source code is here: https://bitbucket.org/controlbreak/mschartfriend
It is very simple and short, you can change it very quickly if you need.

Categories

Resources