pythonpdfnotepad

Python - Notepad to PDF, without use of FPDF library


Does somebody know any other method other then using FPDF lib while trying to convert notepad to pdf format? I have some problems with it, so I am trying to find alternative.


Solution

  • It can be done as a one line python shell command using NotePad (and improved by poking registry values for fonts etc) you can see a discussion here https://stackoverflow.com/a/67696473/10802527 In Windows 7 there are two prime exes to chose from (8 in total !!)

    c:\Windows\notepad.exe
    c:\Windows\System32\notepad.exe
    

    basically using an OS call

    notepad /pt "file from loop.txt" "PDF printer" "PDF Driver" "filename to save.pdf"

    Currently on a machine without the PDF driver so here is the out.xps

    enter image description here

    You will need to write your code to loop through files names and use the exact printer and driver name (see below) However it is much easier to configure WordPads default settings and use it along these lines, Input could be %1 with %2 for Output.

    There are 2 WordPad.exe's to try :-) This is a default American English one:-

    %comspec% "C:\Windows\System32\wordpad.exe" /pt "%Input%"  "Microsoft Print to PDF" "Microsoft Print to PDF" "%Output%"
    

    OR my Locale British English one, which I target !

    "%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" /pt %1  "Microsoft Print to PDF" "Microsoft Print to PDF" %2 
    

    For a drag and drop wrapper see:-

    Doc2PDF.cmd - Convert .Doc(x), .ODT, .RTF or .Txt to PDF & open them in SumatraPDF

    enter image description here