Is there any way to make a tRichEdit print to file without the user being prompted for a filename? I need to load an RTF file into a tRichEdit and have the tRichEdit print the RTF file to file without having the user select a printer or filename.
RichEdit.Print does not direct the printjob to file. I need the print job to print to file not the printer. However, i need to use the default printer driver to print to file.
Do you mean you simply want the ASCII text output to the file? Or do you want a file in Adobe PDF format? Or do you want a file in HP PCL 6 format? Or do you want a Windows Metafile format file?
I think you need to be more specific about what you want (or what you want the resultant file to be used for).
That's correct if the printer is a PCL printer, the file will be converted to PCL. I got it working for PCL and everything looks good. Now when the printer is a windows printer, the file created is some sort of GDI/EMF file but windows can not view the file. If you open WinWord, create an RTF file and send the file to the printer, at the print dialog, choose a Windows printer and select print to file. How can you send the resulting file to a printer at a later date? I.e. if you select print to file through a windows printer, what format is the file saved as? Is it EMF? I have had no luck getting the file to actually print once it is created. I have even tried copy <filename> lpt1 from a dos prompt but i just get garbage from the printer.
It sounds like you don't want to print at all but just save the contents to a file for future printing on whatever printer the user (in the future) wants to use. If this is the case, use the RichEdit.Lines.SaveToFile function and pass a .rtf file name as the parameter.
I have a bit of code that opens a rich-text file into a TRichEdit control, then replaces certain designated "template" text with values from a database, then lets the user print or save the result. It operates just like the mail-merge function available in most word-processors. Is this what you want to do?
Thanks for the response. Let me take a moment to further explain the big picture (I should have done this from the start). I am writing a print job manager to allow users the ability to submit a batch of forms to print in 1 print job. Approximately 95% of the forms submitted are in PCL format and the other 5% are RTF. If printing to a PCL printer, I spool all PCL pages to a spooler directory. When I encounter an RTF page, I load the file into a richedit and tell the richedit to print to a file using the PCL printer driver; this creates a PCL version of the RTF file which I save to the spooler directory with the other PCL pages. After all pages have been spooled, I then send them as ‘RAW’ data to the printer. I’m using windows API functions to perform the printing for PCL (startdocprinter, startdocpage, etc…).
When printing to a non-PCL printer I am using TPrinter from the VCL. This allows me to draw the EMF image (I have a tool that converts PCL to EMF) to the printer canvas. Now, I would like to use the same method of RTF printing for windows printer as I use for PCL. When I encounter an RTF file to be printed, I do the same as with a PCL print job. I load the RTF into a richedit and tell the rich edit to print to file using the Windows printer driver which creates a .PRN file. I then spool the PRN file to the print spooler along with all the EMF pages. After all pages are spooled, I loop through all spooled pages and call printer.canvas.draw(…). However, the draw method does not work for PRN files. Is there a printer.<SOME METHOD> I can call that will send a PRN file? My code would look something like:
If isEMF then
Printer.canvas.draw(…);
Else //isPRN
Printer.<SEND PRN DATA>;
I can not use the richedit’s print method because this creates its own print job which can allow other print jobs to be printed between my EMF print job and the RTF print job.
What I would probably do is extract the code from ComCtrls.pas that performs the TCustomRichEdit.Print function and see if you can tailor it to direct the output (via the SendMessage commands) to a handle that is defined for an EMF file instead of the printer's handle.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.