DevExpress Reports different watermark image on 2 pages or alternative? - c#

I am creating a report with DevExpress in VS2013 and I need to create it according to a template. The report consists of 2 pages which need to display an image of a page from a PDF en then display data accordingly.
In my first attempt I created 2 report with their according watermark images and then added the second report to the first programmatically.
if (reportModel.Report is RequestBonusPage1)
{
var tweedePagina = new RequestBonusPage2();
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
}
If I create the report this way the data needed to display on the second page doesn't get passed, hard coded labels are. Also the watermark image itself is not displayed even though I have the DrawWatermark property set to true.
With my second attempt I removed the watermark image from the second page and added the image with a Picturebox but the labels with the data are then displayed next to the picturebox. I used this link (https://www.devexpress.com/Support/Center/Question/Details/Q323059) as an example for doing this.
Does anyone how I can make these examples work or know any alternatives as of how to achieve this?
If anything is unclear about my explanation don't be afraid to ask.
Kind regards
EDIT:
public ActionResult ExportDocumentViewer()
{
var reportModel = BuildReportModel(ModelSessionHelper.CurrentReportData);
ProcessSpecificReport(reportModel);
return DevExpress.Web.Mvc.DocumentViewerExtension.ExportTo(reportModel.Report);
}
private static void ProcessSpecificReport(ReportModel reportModel)
{
reportModel.Report.CreateDocument();
if (reportModel.Report is SalesReport)
{
var secondPage = new SalesReportPage2();
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
}
if (reportModel.Report is RequestBonusPage1)
{
var secondPage = new RequestBonusPage2();
secondPage.SetReportData(reportModel.ReportData);
secondPage.DrawWatermark = true;
secondPage.CreateDocument();
reportModel.Report.Pages.AddRange(secondPage.Pages);
CreateWatermarkRequestBonus(reportModel);
}
}
private static void CreateWatermarkRequestBonus(ReportModel model)
{
model.Report.Pages[0].AssignWatermark(new Watermark
{
Image = Properties.Resources.bonus_request_page_001,
ImageViewMode = ImageViewMode.Zoom,
PageRange = "1",
});
model.Report.Pages[1].AssignWatermark(new Watermark
{
Image = Properties.Resources.bonus_request_page_002,
ImageViewMode = ImageViewMode.Zoom,
PageRange = "2",
});
}

You can use Page.AssignWatermark method to set the watermark for particular page.
Here is example:
var report = new YourReportClass();
//...
report.CreateDocument();
var page = report.Pages[0];
var watermark = new Watermark();
watermark.Text = "Watermark text";
watermark.TextDirection = DirectionMode.ForwardDiagonal;
page.AssignWatermark(watermark);
report.ShowRibbonPreview();

Related

How to property remove (or keep) the background and contents when exporting PDF to PNG using Magic.NET-Q16-AnyCPU

https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
First time trying the Magic.NET-Q16-AnyCPU and I encounter an issue that I think I just do know the correct method to use I hope someone could lead me to get this corrected. I have a pdf with some existing texts and tables, plus a redline text added by using a pdf editing software.
Attached picture #1: depends on which software I use to view the png, some software shows black background. I like to have the background can show white or show as transparent (which is preferred) for all software. With page containing the red line text, it shows the red line one correctly but the other contents.
Attached picture #2: If I use settings.UseMonochrome = true; then this is no longer an issue but the resulting image I get is not what I prefer. I may sound stupid but with settings.UseMonochrome = false; my eyes feel better, especially when there are some graphics and tables.
Can I set settings. UseMonochrome = false; and still get all the contents shown correctly? And can I ensure the PNG background is either removed or set as White? Already try the image.BackgroundColor = MagickColors.White; but this does not impact the result.
private void button1_Click(object sender, EventArgs e)
{
var settings = new MagickReadSettings();
settings.Density = new Density(100, 100);
//Do not want to use this
//settings.UseMonochrome = true;
var filename = #"C:\Users\USER1\Desktop\dummy.pdf";
using (var images = new MagickImageCollection())
{
if(System.IO.File.Exists(filename))
{
images.Read(filename, settings);
var page = 1;
foreach (var image in images)
{
image.Write("C:\\Users\\USER1\\Desktop\\dummy.PNG");
page++;
}
}
}
}

In WPF, how do I change the source of an image programatically? [duplicate]

This question already has answers here:
How to load image to WPF in runtime?
(2 answers)
Closed 1 year ago.
I have a custom control with a default image that I want to change based on which iteration of the control it is. For example, I have one for "F1" and "NumLock" and so on. In the constructor of the control, I have this:
public FixerBox(Dictionary<string,string> deets)
{
InitializeComponent();
btnOff();
this.FixerTitle.Text = deets["Title"];
this.FixerDesc.Text = deets["Description"];
this.FixerTags.Text = deets["Tags"];
this.FixerImg.Source = new BitmapImage(new Uri(deets["Img"], UriKind.Relative));
}
The bitmap stuff was based on another answer and produces this:
Below is the control itself showing that it's correctly getting the title, tags, and description, but the image is bunk (on the left side, that thin grey line is the border that should be around the image).c#
If I was using HTML/CSS, I could right-click the image to see what exactly its properties are, but I don't know how to get that kind of information using WPF. The best I could manage was in the top area is a status window where I've manually printed a "Tostring" output of the first controls image source data. Near as I can tell, it's all correct, but there's no actual image there. Every subsequent control has the same output (one thin line where the image should be).
EDIT Per comments, here is some more of the information. The main XAML file loads up the controls like so in its constructor:
public partial class MainWindow : Window
{
private Fixers fixers = new Fixers();
// This is the custom control consisting mostly of various boxes
private Dictionary<string,FixerBox> fixerBoxes = new Dictionary<string, FixerBox> { };
public MainWindow()
{
InitializeComponent();
var fixNames = fixers.FixerNames();
foreach (string key in fixNames)
{
fixerBoxes[key] = new FixerBox(fixers.GetFix(key));
FixersArea.Children.Add(fixerBoxes[key]);
}
StatusBox.Text += fixerBoxes["F1"].FixerImg.Source.ToString();
}
}
The fixers variable is of class Fixers which consists of the below (abbreviated to show just the F1 function for brevity):
class Fixers
{
private string ClearWS(string str)
{
var first = str.Replace(System.Environment.NewLine, "");
return first.Replace("\t", "");
}
// Loads registry functions
private Regis regStuff = new Regis();
// Loads preferences from the file
private Prefs prefs = new Prefs();
// A timer to make sure the system behaves
private Timer watcher;
// Watcher action toggles
private bool watchNumL = false;
// Translation array from fix shortname to various data about them
private Dictionary<string, Dictionary<string, string>> fixers = new Dictionary<string, Dictionary<string, string>>
{
["F1"] = new Dictionary<string,string> {
["PrefName"] = "KillF1UnhelpfulHelp",
["Img"] = #"/graphics/F1key.png",
["Title"] = #"Diable F1 ""Help"" function",
["Description"] = #"
Have you ever hit the F1 key by accident and had a distracting and unhelpful window or webpage open as a result?
Windows set the F1 key to a generic help function that basically never helps and always gets in the way.
Enable this control to disable that obnoxious design choice. Note that some programs still respond to F1 on their own accord,
but this will stop the default Windows behavior in things like Windows Explorer at least.
",
["Tags"] = "#Keyboard,#Rage"
},
};
public Fixers()
{
// The readability hack above with multi-line strings introduces a bunch of extra whitespace. Let's clear that out
foreach (var fixKey in fixers.Keys)
{
fixers[fixKey]["Description"] = ClearWS(fixers[fixKey]["Description"]);
}
}
public List<string> FixerNames()
{
return fixers.Keys.ToList();
}
public bool IsFixed(string which)
{
// If we're watching, it's fixed
if ("NumL" == which) return watchNumL;
// For anything registry related
return regStuff.IsFixed(which);
}
public Dictionary<string,string> GetFix(string which)
{
return fixers[which];
}
}
if you use binding, you can create in your ViewModel a string, in which is stored the path of your image, then you can easily change programatically its path.
Then in XAML just bind image's source to the string.
In my case I have a list of objects, with the property `ImageName' :
<Image Source="{Binding DataContext.SelectedMacro.ImageName,
RelativeSource={RelativeSource AncestorType=Window}}"/>

How to import a picture from URL which is saved in database in existing data grid?

I have been looking for solution for days now and still have done nothing.
I have an database which, as one of the values has URL for picture, let´s say the attribute name is Picture_Link, I can show URL in data grid view but I have to show it as a picture with all other columns and rows.
In other data grid I have to show pictures directly from link that I have from app-i result.
All objects in data grid are shown via list which I import from data base (CRUD) and other one is via app-i key result.
CRUD Video = new CRUD();
List<YouTubeVideo> list = Video.GetVideosDB();
dataGridYT.DataSource = list;
This is how my view is imported.
Also I have some added columns, such as save and delete which are type image.
DataGridViewImageColumn oSaveButton = new DataGridViewImageColumn();
oSaveButton.Image = Image.FromFile("D:/save.png");
oSaveButton.Width = 50;
oSaveButton.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridYT.Columns.Add(oSaveButton);
dataGridYT.AutoGenerateColumns = false;
And CellContntClick functions which work.
Everything works except dinamic upload of images in both of data grid views.
private void dataGridYT_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridYT.Columns[e.ColumnIndex].Name == "Thumbnail")
{
e.Value = GetImageFromUrl("https://i.ytimg.com/vi/oZItXZtkmzg/default.jpg");
dataGridYT.Columns[e.ColumnIndex].DefaultCellStyle.BackColor = Color.Azure;
}
}
private object GetImageFromUrl(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream stream = httpWebReponse.GetResponseStream())
{
return Image.FromStream(stream);
}
}
}
I have tried this.
Still nothing, tried to make new data grid with only one column, have copied working code from repos and that one won´t work either. But if I make whole new solution it works. Added new column also.
I have tab control, with two tabs. Each tab has one data grid view, one of the columns shows values of image url´s which I have to use to show a picture, also I need that link for saving whole row in db. I have tried with foreach loop to get each cell value with link and to add image with function in code above.
dataGridYT.CellFormatting +=
new System.Windows.Forms.DataGridViewCellFormattingEventHandler(
this.dataGridYT_CellFormatting);
This line was missing and it fixed problems from above. I goes just under the code where I have added image cells such as oSaveButton.
DataGridViewImageColumn oSaveButton = new DataGridViewImageColumn();
oSaveButton.Image = Image.FromFile("D:/YouTube_KV/save.png");
oSaveButton.Width = 50;
oSaveButton.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridYT.Columns.Add(oSaveButton);
dataGridYT.AutoGenerateColumns = false;
dataGridYT.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridYT.Rows.Add(Environment.NewLine);
dataGridYT.CellFormatting +=
new System.Windows.Forms.DataGridViewCellFormattingEventHandler(
this.dataGridYT_CellFormatting);
dataGridYT.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

Xamarin.forms SwitchCell Text Does not appear fully

I am newer with Xamarin.Forms. Is there a way to display all text an a SwitchCell? The long text get's cut off.
NewsLetterSwitchCell = new SwitchCell
{
Text="abcdefghijklmnopqrstvwxyz123456789aabbccdeeffgghhjjkkllmmmnnooppqqrrsssrtg",
};
NewsLetterSwitchCell.OnChanged += switcher_Toggled;
TableView tb = new TableView();
tb.Root = new TableRoot() {
new TableSection("Enter Optional Information (* Required Fields)") {
NewsLetterSwitchCell
}
};
Content = new StackLayout
{
Children = { tb }
};
This Picture shows the result from my mobile. It contains only the first letters.
You need to write your own custom renderer for this purpose .
Below link can help you .
Forum link for custom switch

Highlighting a particular control while capturing screenshot of a dialog in web page in c#

I have a requirement to capture the screen shot of the opened dialog with a particular html control highlighted ( whose static id is given ). currently I Implemented the code following manner :
public void Snapshot()
{
Image currentImage = null;
currentImage = GetOpenedDialogFrame().CaptureImage();
}
public UITestControl GetOpenedDialogFrame()
{
var dialogsFrames = new HtmlDiv(this.BrowserMainWindow.UiMobiControlDocument);
dialogsFrames.SearchProperties.Add(new PropertyExpression(HtmlControl.PropertyNames.Class, "mcw-dialog", PropertyExpressionOperator.Contains));
var dialogs = dialogsFrames.FindMatchingControls();
if (dialogs.Count == 0)
{
return null;
}
return dialogs[dialogs.Count - 1];
}
Now I have to write the code to highlight the particular html control while taking a screenshot. The DrawHighlight() method of Microsoft.VisualStudio.TestTools.UITesting.dll does not take any parameter so how can I highlight a particular html control in the screenshot.
DrawHighlight() is a method of a UI Control. It could be used in this style:
public void Snapshot()
{
Image currentImage = null;
var control = GetOpenedDialogFrame();
// TODO: protect the code below against control==null.
control.DrawHighlight();
currentImage = control.CaptureImage();
}
Whilst that answers your question about DrawHighlight, I am not sure it will achieve what you want. Please see this question the Microsoft forums where they are trying to do a similar screen capture.
Why not simply user the playback settings:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
This will produce the html log file with all the screenshots that your codedui test went threw.
After searching for the matching controls you can try to highlight each one of them.
something like:
foreach( var control in controls)
{
control.drawhighlight();
}
that way you'll be able to which controls are located by the playback(qtagent to be more precise). furthermore this will help you decide which instance to refer to. (run and wait to see which controls are highlighted, pick the one you need and hard code it to be part of the test).
so after the test run you'll end up with something like:
var dialogs = dialogsFrames.FindMatchingControls();
dialogs[desiredLocation].drawhighlight();
hope this helps.

Categories