I need to print a string exactly as it is without drawing a picture before printing.
Graphic.DrawString Draws the specified text string, so I DO NOT want to use that - It draws a picture of the string. What I need is the exact string.
The only solution I found is to send a file to the printer - but I don't like that solution..
Nowdays printers is not writing machines.
In order to print anything, you got to draw a picture of it first. Keep in mind that not all pictures are jpg files.
One solution is stream your output to txt file and prompt printDialog
Related
I'd like to get the text from documents that were sent to network printers from the printer queue. Printing the contents of the printer spool file yields garbage, though. (I already had to give up my dream of capturing the JobStream itself on the fly, I read it in various sources that it's mostly null.) So, since I get a garbage output, I have a terrible suspicion: it is naive to think that characters get sent to a printer. Maybe it's just a bunch a coordinates and shade codes for black and white, or color codes for color printers. So is there any hope of acquiring the original text from the spool file or a printer jobstream?
It sure looks like graphics data that is sent to the printer. So it is too late to capture in the print queue. What is needed here is a custom print driver. I found only proprietary solutions, though.
i have a console application that writes data to a textfile. the text file gets printed out as a label.The question is can i be able to fix the size of a textfile that it must be the size of 13 lines one after the other so that the printer format doesnt have to change.
If you need a fix number of lines in a text file, try using the "\r\n" escape sequence to create the desired number of lines.
Also consider using a library such as NPOI for better formatting options.
I'm working with a WinForms app. I have an RDLC report that will be printed on 11x17 and then folded (printer supports folding). I'm rendering to EMF and drawing to pages of a PrintDocument. This works fine except for folding.
What I'd like to do is store the settings that make the printer fold. The users would select a preset from a dropdown and the app would select the printer, the paper size, the tray, whether to duplex, and whether to fold. Storing the PrinterSettings object covers most of this, but doesn't save the folding option.
I first attempted to store/retrieve something I read about called DEVMODE. For reference: http://nicholas.piasecki.name/blog/2008/11/programmatically-selecting-complex-printer-options-in-c-shar/. What I found is that even though I had extra data specific to the driver, all the bytes were 0 regardless of what driver-specific settings I changed. I'm not sure where I went wrong with this, but I abandoned it and looked at the printing capabilities in WPF.
I found that I could configure a PrintTicket for my settings, store it, and retrieve it later. It seems a bit convoluted just to save the settings, but I think I have it working. At least it seems to show up correctly in the PrintDialog. However, I'm now stuck trying to figure out how to print my report.
As I understand it, I can't take a PrintDocument from WinForms printing and use it in WPF. I also read EMF format is not supported in WPF. I thought I would render each EMF to a bitmap, then print those. But the text in my report is fuzzy and I'm not having any luck clearing it up.
Starting with a stream that contains EMF bytes that I know will render sharply with PrintDocument, I test trying to save to a file. It seems no settings that I provide will save with crisp text.
var pageImage = new Metafile(stream);
pageImage.Save(filename);
All this just to add the ability to fold. Am I just completely on the wrong track? I don't see how this should be so hard. I guess I either need to find another way to save/restore custom printer settings or I need a way to render these EMF files better.
I also tried rendering the report directly to BMP format and it's also poor quality.
I tried something slightly different and it worked! I reused my original PrintDocument code and printed to an XPS file. Then I printed the XPS file using my PrintTicket and it works fine.
In my project we need to use a virtual printer and then catch the file (most of the times its bitmap) and extract data from it. and transform it into xml like so .
<document name="file://C:\DOCUME~1\ilanit\LOCALS~1\Temp\p0129600584.htm">
<lineXY x="0" y="0" height="1656" width="2275" />
Is it something like Redmon you are looking for (used in conjunction with output to file and the launch an application)? If so you can use it or there are others out there too. Redmon is a little dated and depending on the OS you might have issues. If you can, add more detail and specifics to your question as it's a bit confusing.
UPDATE (based on comments): If the source is PDF or some other document (ie: Word) that has actual text and not just graphics (scan/image) type data you could use a Postscript driver (type 1 might work best) and then extract the text after you capture the print file. If you are not going to use the print file for actual output and just need the data, you can always try the Generic Text driver in Windows as it will ignore graphcis and just put the text in the output file. As long as the output is consistent and a little Regex should be able to pull out what you need.
If the data is graphical in nature such as a scanned image that you are printing, you will need to capture the print job, turn it into a graphic image (as it will be a print file with PCL or Postscript etc.) and then run it through an OCR engine to pull out what you need.
I am writing a small application that prints some stickers to a special printer.
When I use MS Word to print some text to that printer (and to an XPS file), the result looks excellent. When I print from C# code with the Graphics object, the text appears to be over-pixelized or over-smoothed.
I tried the following hints, but none produced the same result as MS Word:
System.Drawing.Drawing2D.SmoothingMode.AntiAlias
System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
System.Drawing.Text.TextRenderingHint.AntiAlias
System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
InterpolationMode.NearestNeighbor
CompositingQuality.HighQuality
And some others.
Can you advice which hints are applied by MS Word, so I could create it programatically?
I'm not familiar with the Graphics object, but I'm guessing you're sending a bitmap to the printer instead of text or vector graphics.
If so, increase the resolution/DPI of the image you're creating to approach that of the printer, or switch to a rich text (XPS) or vector-based format.
Windows GDI (on which Graphics is based) is a raster technology. You are generating (possibly low-res) bitmaps.
Options include: instantiate a larger graphics object and print bigger text (== increasing resolution of the print), or move to WPF, which has a vector model and lets you generate XPS files natively.
You'll need to be printing at least 300DPI for it to look any good. 600DPI would be better. You're probably printing at something around 96DPI by just drawing straight out to the printer.