I'm currently writing an application in ASP.NET/C#, where the user needs to be able to generate PDF's of invoice summary's through the web based admin system.
The customer did not want to use an open source solution such as iTextSharp (stupid, I know) and instead purchased Adobe Acrobat/Reader (not sure which) which come with a virtual PDF printer. So we'll be interfacing with this printer on the server to generate the PDF's.
That's working well - we can easily generate PDF's and display them to the user. However, the way the content is written to the document to be printed (using the Graphics class of the PrintPageEventArgs event) is a bit foreign to me right now. Writing the text and header information is a piece of cake, but what's the easiest way of writing the contents of the GridView to the doucment?
Here's some example code of the sort of thing I'm using:
protected void Page_Load(object sender, EventArgs e)
{
PrintDocument NewDoc = new PrintDocument();
NewDoc.PrinterSettings.PrinterName = "PrinterName";
NewDoc.PrintPage += new PrintPageEventHandler(NewDoc_PrintPage);
NewDoc.Print();
}
void NewDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Test Header", new Font("Verdana", 18), Brushes.Black, 220, 120);
}
Ended up having to essentially draw the grid myself. Pretty hacky but it works.
Related
protected void btnSTart_Click(object sender, EventArgs e)
{
cam = new
VideoCaptureDevice(webcam[DropDownList1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
private void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
//pictureBox1.image = bitmap;
//This last line of code was used in C# window console
}
I am using aforge to do a video through my laptop's webcam. The webcam is working fine, but I just can't seem to find a way to display the bitmap. Do I have to use the asp Image or some other control do it and how do I use that control to do so? Any help would be appreciated.
In an ASP.NET application, the C# is executed on the server. This means that you need a way of getting the image back to the client. This can be done in a few ways (for example, cache the resulting image and provide an endpoint to the client to be able to download it).
Here is an article on getting dynamically generated images to the client. Not sure about which version of ASP.NET you are using, but the concepts will be fairly similar.
Hope this is an easy one.
I'm writing this WPF software with VS2017, I need to print the visual to an .xps file at some point and I managed to get this working like this:
private void cmdPrintClick(object sender, RoutedEventArgs e)
{
PrintDialog print = new PrintDialog();
print.PrintQueue = new PrintQueue(new PrintServer(), "XPS"); //XPS is the Microsoft XPS Document Writer
print.PrintVisual(myWindow, "Window"); //myWindow is the visual I want to print
}
This is working just fine.
What I am trying to achieve is to give progmatically the path and the filename, no need to show any dialog.
Thanks everyone for helping out.
I have a web browser control in C# that it's design mode is on. I use it to make a (WYSIWYG) HTML editor. I want to insert a photo on this without UI, when user wants to insert image I show to him/her a window that shows on it some known name for user. Then with search (s)he find her/his photo and add it to control.
this is my open image form:
Photos are in database and user only know them with names. I upload all of them in a folder and show above list to user and user selects a picture. I want to add image by it's location in hard disk and allow user to set its alignment .
How I can do this ?
Adding a new element to a document is very logical. The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.
I write an Example for you:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><body></img></body></html>";
}
private void insert_image_btn_Click(object sender, EventArgs e)
{
HtmlElement userimage = webBrowser1.Document.CreateElement("img");
userimage.SetAttribute("src", "image location");
userimage.Id = "imageid";
webBrowser1.Document.Body.AppendChild(userimage);
}
private void btn_set_aliign_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("imageid").SetAttribute("float", "right");
}
I have written a Label making program for work. It uses an opendialog to pull in the data. Splits it up and put it in tables. No issues there. Setting up the the FixedDocument to print the user control labels as well as the class that stores the Fixed Document Data all work great.
My only issue is I can't stand the restrictions on a WPF document when it comes to text searching and print control. I have gone with a printpreviewdialog but this does not use FixedDocument.
I am needing to know if it can be converted with a simple bit of code or if i Have to rewrite my entire class and go back to the drawing that printpreviewdialog uses.
The code for the call is below.
private void button3_Click(object sender, EventArgs e)
{
var avery = new Avery5160();
DataTable data = (DataTable)dataGridView1.DataSource;
var A5160 = avery.CreateDocument(data);
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = A5160;
ppd.ShowDialog();
}
The error is :
Cannot implicitly convert type 'System.Windows.Documents.FixedDocument' to
'System.Drawing.Printing.PrintDocument'
Thanks for any assistance.
I am not so sure there is a simple conversion. A simple (if not a little time-consuming) method would be to create a preview dialog with a document viewer to simulate what you would be seeing. Then printing using the FixedDocument's DocumentPaginator and a regular PrintDialog.
The answer to this question shows how to do it by creating an XpsDocument that is then used with a custom PrintPreview class.
I'm currently attempting to print a document from WPF. I'm using the web browser because it contains an active x control which has the autodesk plugin which I need to view the document.
I'm aware that WPF doesn't directly support web browser but I've just integrated the Windows Forms library for this. I've managed to get the code running and even printing, however the document that prints is blank.
I'm not sure if it could possibly be a conflict between the Windows Forms library and WPF; I'm navigating to the document and only printing once it's loaded with no errors thrown.
Here's the code I'm using:
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();
Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
w.Navigate(uri);
w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
}
void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;
w.Print();
}
One possible hitch could be that the active x control is not being allowed to be load, does anyone know how to force the control to be initialised.
Does anyone have any ideas about how to solve this or another method of printing an autodesk (.dwf) document
Thanks in advance,
SumGuy
Not really an answer of sorts but a solution if anyone out does want to print a .dwf file. Don't, use the new form .dwfx. This is the new file type Autodesk are switching too and its actually a form of XPS which makes things quite easy. You can load it into a web browser without needing active x OR (this is the better way) use the XPS libraries in visual studio because it can be loaded very simply into an XPS viewer.
The code I eventually used to print the dreaded file is below:
private PrintQueue printQueue;
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog() == true)
PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);
How easy's that??? There are loads of other ways of doing it using XPS. You can basically just use the dwfx file as an XPS document