Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6216241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:12:00+00:00 2026-05-24T07:12:00+00:00

I am stuck here when printing directly to text files using this code win32api.ShellExecute

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:12:01+00:00Added an answer on May 24, 2026 at 7:12 am

    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():
                oldset[key] = winreg.QueryValueEx(notepad, key)
                winreg.SetValueEx(notepad, key, None, item[1], item[0])
    
        #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 <enter> to continue')
    
        if newset is not None:
            for key, item in oldset.items():
                winreg.SetValueEx(notepad, key, None, item[1], item[0])
    

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help, I am stuck here --- irb> a = line of text\n line
I'm kind of like stuck trying to implement YUI autocomplete textbox. here's the code:
I hate to have to ask, but I'm pretty stuck here. I need to
Programming Student here...trying to work on a project but I'm stuck. The project is
Really stuck on trying to write code to unzip a file or directory on
I'm fighting here with System.Printing namespace of .net framework. And what i always saw
I have some code that grabs the between of some text; specifically, between a
Here is my code float cpuLoad = 0; try{ MessageBox.Show(Running); //CPU Load PerformanceCounter cpuCounter
While doing filing im stuck here.The condition of the while loop is not working.The
I can't believe I'm stuck here, but I can't seem to make a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.