I'm sure you're just a simple search away from finding a module that will handle this problem much better than this hack (e.g. Use Reportlab and ShellExecute the PDF). Also, the default application for printing text files on Windows is Notepad. If you wish to configure the header/footer setting permanently, just change it in File->Page Setup.
Up vote 1 down vote favorite share g+ share fb share tw.
I am stuck here when printing directly to text files using this code win32api. ShellExecute (0, "print", "datafile. Txt", None, ".
", 0) it always print the header "datafile. Txt" and footer "Page1". I want to hide or remove this when printing on continous form paper.
I do not want to install another third party software. Please help me. Thanks.
Python textfiles pywin32 system. Printing link|improve this question asked Aug 2 '11 at 2:00kuslahne455 86% accept rate.
– kuslahne Aug 2 '11 at 2:20 first you'll have to explain exactly what are you trying to accomplish. – BrainStorm Aug 2 '11 at 2:34 Thanks for reply @ BrainStorm. I have filename.
Txt with " Then I need to print this file using python. But the ouput from printer comes with header with filename. Txt and Page1 on footer.
How to remove this output? – kuslahne Aug 2 '11 at 4:05 The default printing app for text files is Notepad. Just open Notepad and modify File->Page Setup.
The setting is stored in the registry, so it will be remembered after you close Notepad. – eryksun Aug 2 '11 at 4:40.
I'm sure you're just a simple search away from finding a module that will handle this problem much better than this hack (e.g. Use Reportlab and ShellExecute the PDF). Also, the default application for printing text files on Windows is Notepad. If you wish to configure the header/footer setting permanently, just change it in File->Page Setup.
If you wish to change Notepad's settings in your program, you can use the winreg module (_winreg in Python 2). However, there's a timing issue since ShellExecute doesn't wait for the job to be queued. Before restoring the old setting, you can either sleep for a little while or just wait for user input to continue.
Here's a quick function that demonstrates the process: try: import winreg except: import _winreg as winreg import win32api def notepad_print(textfile, newset=None): if newset is not None: oldset = {} hkcu = winreg. ConnectRegistry(None, winreg. HKEY_CURRENT_USER) notepad = winreg.
OpenKey(hkcu, r'Software\Microsoft\Notepad', 0, winreg. KEY_ALL_ACCESS) for key, item in newset.items(): oldsetkey = winreg. QueryValueEx(notepad, key) winreg.
SetValueEx(notepad, key, None, item1, item0) #force printing with notepad, instead of using the 'print' verb win32api. ShellExecute(0, 'open', 'notepad. Exe', '/p ' + textfile, '.
', 0) input('once the job is queued, hit to continue') if newset is not None: for key, item in oldset.items(): winreg. SetValueEx(notepad, key, None, item1, item0) You can temporarily delete the header/footer settings with the following call: notepad_print('datafile. Txt', {'szHeader' : ('', 1), 'szTrailer': ('', 1)}) You can change as many of its registry settings as you want: newset = { #name : (value, type) 'lfFaceName': ('Courier New', 1), 'lfWeight': (700, 4), #400=normal, 700=bold 'lfUnderline': (0, 4), 'lfItalic': (1, 4), #0=disabled, 1=enabled 'lfStrikeOut': (0, 4), 'iPointSize': (160, 4), #160 = 16pt 'iMarginBottom': (1000, 4), #1 inch 'iMarginTop': (1000, 4), 'iMarginLeft': (750, 4), 'iMarginRight': (750, 4), 'szHeader': ('&f', 1), #header '&f'=filename 'szTrailer': ('Page &p', 1), #footer '&p'=page number } notepad_print('datafile.
Txt', newset).
Thanks a lot @eryksun. It works. – kuslahne Aug 2 '11 at 6:25.
Using this method seems to give more control to the programmer and certainly doesn't insert headers and foots without explicit statements.
It only prints one page, and cuts off text at the bottom mid line. – eryksun Aug 2 '11 at 4:37 @BrainStorm I mean like this one computertipaday.blogspot.com/2009/03/rem... but in python way. – kuslahne Aug 2 '11 at 4:41.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.