I have a timetable in memory, and need to be able to print it out.
The timetable will likely be many pages, each page will look quite similar:
A grid of cells, across the horizontal axis is time, and along the vertical axis is entities. Cell x, y will contain the allocation of a particular job to entity x at timeslot y.
I'm looking at the System.Drawing.Printing.PrintDocument class but it's incredibly cumbersome. I need to set an event handler to the PrintDocument.PrintPage, yet there doesn't appear to be any way to get the page number from the PrintPageEventArgs?
I just want to construct my document and call some Print() function. I suppose if I could get the page number within the event handler, I could construct the page layout on the fly with e.Graphics and GDI.
I could potentially even put together a HTML page using tables and print that - if I could somehow control what prints on what page?
Is there a better way to construct and print documents in C#?
The target machines do have Office installed, but they're all different versions and I've had lots of trouble getting correct versions of the .Net/Office interop library to work with them.
Edit: I could potentially even create a temporary LaTeX file on the fly and compile it, then print it. This seems like a good solution, except that the target machines are locked and the users can't install new software, hence I would need to bundle the LaTeX compiler with my program, and my compiler is almost 300MB.
Sounds to me like you're giving up too soon. Handling the PrintPage event isn't that difficult and since the event is raised sequentially, all you have to do is keep a page counter in that event. That's how I've done it in the past with MetaFile images (printing Reporting Services reports through a web service call).
I build a similar tool by using the Microsoft Chart Controls, easy to use.
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&displaylang=en
If you can save it to a file, you can use this here,
Print images c#.net
Related
I'm struggling with some code using LibreOffice 7.1.0 on Windows 10 to append images from a folder into separate slides in Impress. I've been looking here and OpenOffice documentation. This call continuously fails (null): xMultiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"); and I cannot understand why? I tried using XMultiComponentFactory also, but no luck. Has it got something to do with Slide Layout, but despite being of blank type, I could drag-drop an image and it gets added in the slide.
Unfortunately, full code is on restricted system, so I have this much only. Any hints on potential causes would be very helpful.
It was simple issue: I needed to initialize xMultiServiceFactory with xComponent. I had earlier initialized it with xComponentContext.getServiceManager(). I realize again, this is why learning object model is very important. COM could get tricky unless, one knew what they were doing.
Ok I've tried this in every possible combination... I know this can be done in Access, so I know it can be done in C#...
What I'm trying to do is set up a print button, that when clicked, organizes data from various controls on my form into specific positions on a predefined template. Like say I'm generating a Job Estimate, and I want to print it... It would look silly printing the control or form, so I'd like it organized into a neat standard format on a page, that may include a logo etc. I don't want the data exported to a document, I just want the print button to auto-generate this so that it can be printed from the application.
Can anyone point me to some resource that deals with this? I have googled my mind away, and searched all over stack overflow, but I'm not even sure what the correct wording to look something like this up with is, as it keeps giving me c++ or some other random stuff to look at that has nothing to do with what I am looking for....
What you are looking for is a reporting tool, which can render a structured report to screen, or to print or to a file format like PDF.
Many reporting tools exist for .Net development, Crystal Reports, Active Reports, Reporting Services in SQL Server.
I need get the html code this site (with C#):
http://urbs-web.curitiba.pr.gov.br/centro/defmapalinhas.asp?l=n (only works with IE8)
Using the WebClient class, or HttpWebResquest, or any other library, I do not have access to the html code generated dynamically.
So my only solution (I guess) would be to use the WebBrowser Control (WPF).
I was trying and trying, using mshtml.HTMLDocument and SHDocVw.IWebBrowser2
but it is a mess, I can not find what I want on it
it seems there are many "iframe", and inside there are more "iframe".
I do not know, I tried:
IHTMLElementCollection elcol = htmlDoc.getElementsByTagName("iframe");
var test = htmlDoc.getElementsByTagName("HTML");
var test2 = doc.all;
but had no progress, does anyone know how to help me?
Observation / trivia: This is the site that shows where all bus pass in my city. This site is horrible, and only works in IE8 has serious problems. I would like to use this information to try to create a better service, using google maps or bing maps posteriorly.
The site that I was trying to get the information is no longer available, the idea to get dynamic html source code was abandoned and I cannot found the solution using a WebBrowser Control for WPF.
I believe that today there are other ways to solve this problem.
You need to use the "Frames" object in the WebBrowser control, this object collection will return all frames and iframes if I recall correctly, and you need to look at the frames collection for each newly discovered frame you find on the page, get me? So, it’s like a recursive discovery loop that you need to run, you add each frame you find to your array or collection, and for each "unsearched" frame, you must look at that frames ".Frames" collection (they will all have a .Count etc, just a typical collection) and you do this for every newly discovered frame that you find, until of course, there are no longer any newly discovered frames that haven't had their ".Frames" collection searched.
So, the function, if done as per above, will allow for infinitely nested frames to be discovered, as I've done this in a VB6 project (I'm happy to give you the source for it if you would like it). However, the nesting is not preserved in my example, but that is ok since the nesting structure isn't important and you should figure out which was what by the order of the frames that are added to the collection since the order is related to the hierarchy of the frames being added.
Once you do that, getting the html source on this is pretty straight forward and I’m sure you know how to do, probably a .DocumentText depending on the version of the WB control you are using.
Also, you say it is not possible to use the HTTP clients to directly grab the source code? I must disagree, since once you have the frame objects, you can get the URLs from each frame object and do a URL2String type call to get the URL and turn it into a string from any httpclient-like class or framework. The only way it may be prevented on their behalf if if they accept requests only from a particular referrer (ie: the referrer must be from their domain name on some of their files etc), or the USER_AGENT where if it isn't one of the specified browsers, then it is technically possible that they will reject and not return data, unlikely but possible.
However, both referrer and user_agent can be changed in the httpclient you are using, so if they are imposing limits based on this sort of stuff, you can spoof them very easily and give them the data that they expect. Once again, this is low probability stuff, but it is possible they may have set things up this way especially if their data is proprietary.
PS: My first visit to the site ended up in IE crashing and reopening that tab :), terrible site I agree.
I'm currently having a couple of reports which I print from my Forms applications.
However building printed reports only with the built-in .NET printing methods is very tedious. Even just printing a simple table on a couple of pages with a little bit of formatting is a task for a couple of hours (if it should look nice).
What I need is a WYSIWYG-Designer for the layouts, so I'd like to write one.
It shouldn't be for End-Users, but for me as a developer, it's just about to create the layout what the report will look like with various arrangements/fonts/images/formats and so on and not have to do that by trial & error in code (and restart the app a zillion times).
So my specific questions:
What would I use as a canvas for editing and display of the report? An image-control/bitmap which I draw upon like on the printed document? Is there a better way?
Is drawing on a form comparable to drawing on a printed page? What about differences in resolution printer vs. screen?
How to get real WYSIWYG? Should I get the printer settings and create my canvas with the same resolution? Is there something else to consider?
I know that there are report designers around but I think it's sometimes good to understand the basic working principles of what you use and implementing them is for me the best way to do that.
I'm aware that this is not a specific question A to which the answer is always B, but if it were that way I would find an answer in Google pretty quickly.
Thanks in advance!
I can't say much about designing a WYSIWYG editor, but I have written a few custom in-house reporting engines for use by our development team.
There's two main ways I've created reports. The first is using PDFsharp (MIT-licensed) to manually layout pages which isn't for the faint-of-heart.
The second is using Winnovative's HTML to PDF library (not free, but royalty-free) which uses the current installed version of IE to do the layout and spit out a PDF. It looks like they've recently released a new version called EVO PDF which I have never used before.*
For the HTML to PDF solution, it supports JavaScript so you can add in charts from JavaScript libraries like flot or jqplot.
*I'm not affiliated with Winnovative.
You might want to save time and use Visual Studio HTML designer as your WYSIWYG editor.
What I'm currently doing is using ASP.NET MVC 3 as a simple reporting engine. You can use the MVC pattern to really separate your reporting data source (Model) and the rendering (View) while using Visual Studio as your report designer.
From your application you can easily call your actions with the report optional parameters. For example:
http://localhost/Report/Customer/Orders/1
You simply get the returning string from a WebClient's DownloadString method and you have your report generated.
There is some down side using HTML, mainly the difficulties to know when a page would break, but by using code in your View you can calculate the amount of repeating items and add a CSS break-page and re-starting your table's header on the next page.
You can achieve anything from graphics, to table, you can even generate link to other reports.
HTH.
Printing Reports in Windows Forms
http://msdn.microsoft.com/en-us/library/ms996472.aspx
I’m selecting a report generator for my .NET winforms app and it’s driving me crazy. I’m not familiar at all with report generators so…
Does anyone knows of a report generator that:
1.- Is easy to deploy in relation to the main app
a. (Least, least, least desirable)
Have a separate scriptable/silent installer
(I can make the app installer call the
report generator installer)
b. (I can live with this) Have an
“integrable” installer (An integrated
installer for both the App and the
report generator can be made easily)
c. (Most desirable) Clickonce/xcopy
installation possible (no installer at
all!!! yay!!!!).
2.- Is scriptable to some degree:
a. (I can live with this) Is it
possible to change certain properties
(image sources, colors, visibility,
widths, etc.) at runtime?
b. (Most
desirable) Is it possible –in addition
to the previous item- to add/remove
elements to the report at runtime?
3.- Self-adjusts when you resize the page:
a. (Least desirable) You have to
manually resize things dynamically
accessing the report structures
(related to 2a)
b. (Most desirable) The report and its
elements adjust automatically to the
available canvas/paper size (as HTML
pages do, using percentages)
4.- The size of individual elements in the report grows/shrinks in accordance to the content displayed inside (elements could be grid’s columns):
a. (Least desirable) The element only
grows vertically to accommodate bigger
content (no clipping).
b. The size of the elements can be
self-adjusting to content (like a
<div> element). Columns in a grid for
example should grow/shrink according
to content (as in a HTML <table>
element without columns widths)
5.- It should be possible to export a report to at least excel and PDF.
6.- The report viewer should support languages other than English.
I don’t know if my needs are unrealistic, but report generators are not my thing, I’m at a loss here.
Anyone with experience on the field can give me any pointer in the right direction for me to investigate?
We use DevExpress' XtraReports which works in WinForms, ASP.NET, WPF and Silverlight. It is fully featured and should be capable of most if not all of what you are wanting. Find out more here:
http://devexpress.com/Products/NET/Reporting/
I have been in your position many times (architecting a WinForms app with a reporting feature) and I think your best bet is, wait for it... Crystal Reports. It meets all the criteria you laid out but does have the caveat of a very large redistributable runtime. It also has a .NET SDK, an embeddable designer etc.