I would like to be able to print the chart I make with silverlight-toolkit.
The application is written in Silverlight 4.
However I have no idea how to get this done.
Does anybody know how this works or has a tutorial somewhere?
I have been searching at Google to see if I could find something, but I didn't find anything that worked for me.
Thanks in advance.
EDIT:
I'm useing the following code after I click on the print button but nothing happends:
Chart chartToPrint; // The element to be printed
PrintDocument doc = new PrintDocument(); // Create the PrintDocument object that will do the printing
doc.PrintPage += (s, args) =>
{
// Set the chart that needs to be printed.
// As soon as this is set, printing starts
args.PageVisual = chartToPrint;
}
Edit:
Things I have tried:
http://gergelyorosz.com/2010/05/printing-in-silverlight-printing-charts-and-auto-scaling/
http://kb.yworks.com/article507.html
http://www.visiblox.com/blog/2010/05/advanced-printing-in-silverlight-printing-charts-and-auto-scaling
http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.landscape(v=vs.110).aspx
printing an image in landscape orientation?
http://msdn.microsoft.com/en-us/magazine/hh148152.aspx
Have a look at this site:http://kb.yworks.com/article507.html . Hope this helps you!
Related
hi I'm trying to add a text window that opens when I hover over a image in Uwp
I'm not meant to use xaml and I'm having troubles I pretty much want it to do this:
ToolTip tp = new ToolTip(); tp.Content = this.ToString(); ToolTipService.SetPlacementTarget(tp,Img);
but i cant get it to be added to the image any help would be appreciated.
does any one know what to do?
Call SetToolTip() with the image as the first parameter.
ToolTipService.SetToolTip(image, "this is my tip");
I have built an app on WPF C# that holds invoices and I have created a usercontrol that is assigned to a scrollview.
Everything works perfect until I notice this really anoying printing bug.
So the user control is in the size of an A4. If the scroll view is scrolled to the top at the time of printing :
**PrintDialog pd = new PrintDialog();
pd.PrintVisual(scrollView, "print this off");**
No issues occur. However, if the scroll view is in middle or bottom it prints with an offset.
I have tried to remedy it by moving the scrollview to the top before printing and it does so but the prints come out wrong...
**scrollView.ScrollToHome();
PrintDialog pd = new PrintDialog();
pd.PrintVisual(scrollView, "print this off");**
and yet if I Hit the print button again it will print correctly. I have no idea why it prints before moving it to top as thats the only explanation I have for it...
PLEASE HELP
Call UpdateLayout() after scrolling home:
scrollView.ScrollToHome();
scrollView.UpdateLayout();
(from the docs of the UpdateLayout() function: "Ensures that all visual child elements of this element are properly updated for layout.")
this worked like a charm and simpler than implementing threading. Both good answers
I could not repro the problem with a very minimal sample WPF app consisting of just a ScrollViewer and a Panel. A shot in the dark: try to call scrollView.UpdateLayout() after your call to scrollView.ScrollToHome(). The docs of the UpdateLayout() function say, "Ensures that all visual child elements of this element are properly updated for layout.", and that sounds like what we want. – dlatikay
I have same problem before when I change layout of a Visual right before print action. If I print immediately, I will get wrong result. I guess that the Visual don't have enough time to render properly new layout before you print. I fixed like this:
using System.Threading.Tasks;
async void Print() // Use async
{
PrintDialog pd = new PrintDialog();
scrollView.ScrollToHome();
await Task.Delay(TimeSpan.FromSeconds(1.0)); // Wait 1 second scrollView being properly rendered.
pd.PrintVisual(scrollView, "print this off");
}
I have the following PowerPoint 2010 c# add-in code (the "Test" button only). I don't understand why a slide created manually, using this CustomLayout with ppPlaceholderBody set to ppBulletNone, produces a bulleted text box placeholder. The slide master layout in PowerPoint looks fine with no bullet. I'm sure that there must be more to setting the bullet to none than I understand. Can anyone shed any light on this?
private void button4_Click(object sender, EventArgs e)
{
PowerPoint.CustomLayout ppCL = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.CustomLayouts.Add(
Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.CustomLayouts.Count + 1);
ppCL.Name = "My Custom Master Layout - text without a bullet!";
PowerPoint.Shape ppShape = ppCL.Shapes.AddPlaceholder(PowerPoint.PpPlaceholderType.ppPlaceholderBody);
ppShape.TextFrame.TextRange.Text = "Candidate";
ppShape.TextFrame.TextRange.ParagraphFormat.Bullet.Type = PowerPoint.PpBulletType.ppBulletNone;
}
Thanks in advance for helping... I've been working on it for longer than I'd like to admit.
-Aaron
Here's the solution: the shape text needs to be set after the ppBulletNone is applied. This makes sense because the paragraph text was created using the default bullet and not automatically changed when the shape was changed. Duh.
Just flip the last two lines in the original question like so:
ppShape.TextFrame.TextRange.ParagraphFormat.Bullet.Type = PowerPoint.PpBulletType.ppBulletNone;
ppShape.TextFrame.TextRange.Text = "Candidate";
Anyone give me a point so that I can begin to help others?
I am trying to print the page in my WPF application. I have decided to create it as a canvas, thanks to the ease of the PrintVisual() method.
The issue though is I can't set the printer name dynamically - using the Print Dialogue box is not an option either, staff must be able to click the print button and it automatically prints to their assigned printer (assigned by reading from a config file, not based upon the Windows default printer). This is possible using the print page eventhandler (part of PrintDocument, eg pd.PrintPage += new PrintPageEventHandler(pageLayoutForPrint))) because I can also set the printer name (as a string), but I am trying to be lazy and take advantage of the inbuilt methods.
I'm very new to printing but here are my 2 questions
Can the printerName be set if I use the PrintVisual method?
If the printerName cannot be set, what is the best way to print my canvas? Is the theory of printing effectivly mapping coordinates and then passing it to the printer. EG, to print a document with just a textbox we could use the following pseudo code:
int left = textbox.Left;
int top = textbox.Top;
e.Graphics.DrawString(Textbox.Text, printFont, Brushes.Black, left, top, new StringFormat());
The answer is embeded here
WPF MVVM background printing databinding issue
And the short answer:
1) Import System.Printing (may need to add a reference
2) This code does it (assuming there is a canvas already created)!
PrintDialog dialog = new PrintDialog();
PrintQueue queue = new LocalPrintServer().GetPrintQueue(printerName);
dialog.PrintQueue = queue;
dialog.PrintVisual(canvas, "");
Use the PrintDialog with PrintVisual(). You don't have to display the print dialog.
You can easily do it with this simple code. I regret to say that your question is duplicated.
private void Button_Click(object sender, RoutedEventArgs e)
{
PrintDialog _PrintDialog = new PrintDialog();
_PrintDialog.PrintQueue = new PrintQueue(new PrintServer(), "Printer Name");
_PrintDialog.PrintVisual(CanvasOrAnyVisualName, "Printing Job Name");
}
I need to programmatically change the print orientation for one of my webbrowser controls in a winforms app. From what I'm reading in other posts... it looks like the only way to do it is via a programmatic registry edit, print, then change the registry back.
Is this the only solution? If so, can anyone help with the correct way to do this in code?
I figured... Here's how its done in WPF:
var dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
System.Printing.PrintTicket pt = dialog.PrintTicket;
pt.PageOrientation = System.Printing.PageOrientation.Landscape;
dialog.PrintTicket = pt;
// Print the element.
dialog.PrintVisual(ReportContentPresenter, "Report");
}
Weird part here is that though, you'll not find PrintTicket in System.Printing even after adding reference to this DLL. You'll also have to add a reference of ReachFramework to get PrintTicket in the intelisense.. Microsoft never stops creating mysteries out of simple things..!! Enjoy!
Have you tried:
printDialog.Document.DefaultPageSettings.Landscape = true;