Python 3.6 and 2.7 side by side

In order to use two versions of Python on one Windows 10 machine while keeping the 3.6 as the default environment we can use a simple trick. The final solution gives us following effect:

>  python --version
Python 3.6.1
>  py2
>  python --version
Python 2.7.13
>  py3
>  python --version
Python 3.6.1

The procedure is fairly easy and involves two simple one-line scripts. During Python 3.6 installation you should add the executable folder to environmental variables. Note the selected installation path as we’ll use it later.

Continue reading

Skrypt Powershell eksportuj膮cy dokumenty Word do PDF

Skrypt pozwala na masowe wyeksportowanie plik贸w .doc i docx z katalogu podanego jako parametr -i do podkatalogu /PDF. Nie zapisuje pliku Word po eksporcie oraz generuje zak艂adki na podstawie nag艂贸wk贸w (zob. linie 28 i 32).

Spos贸b u偶ycia:

printpdf.ps1 -i C:\directory\to\export

Nie jestem autorem ca艂ego skryptu, bowiem wi臋kszo艣膰 zosta艂a zebrana z r贸偶nych odpowiedzi na Stackoverflow na zapytanie “batch pdf printing”. Szczeg贸lnie nale偶y podzi臋kowa膰:

Param(
    [string]$i
 )
$input_dir = $i
$output_dir = "$($input_dir)\PDF"
# Create output directory if not exist
If(!(test-path $output_dir))
{
New-Item -ItemType Directory -Path $output_dir -Force 
}
Add-type -AssemblyName Microsoft.Office.Interop.Word
# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $input_dir -Filter *.doc? | ForEach-Object {
    
  $wdSourceFile = $_.FullName
  $wdExportFile = "$($input_dir)\PDF\$($_.BaseName).pdf"
  "Opening " + $_

  $wdExportFormat = [Microsoft.Office.Interop.Word.WdExportFormat]::wdExportFormatPDF
  $wdOpenAfterExport = $false
  $wdExportOptimizeFor = [Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForPrint
  $wdExportRange = [Microsoft.Office.Interop.Word.WdExportRange]::wdExportAllDocument
  $wdStartPage = 0
  $wdEndPage = 0
  $wdExportItem = [Microsoft.Office.Interop.Word.WdExportItem]::wdExportDocumentContent
  $wdIncludeDocProps = $true
  $wdKeepIRM = $true
  $wdCreateBookmarks = [Microsoft.Office.Interop.Word.WdExportCreateBookmarks]::wdExportCreateHeadingBookmarks
  $wdDocStructureTags = $true
  $wdBitmapMissingFonts = $true
  $wdUseISO19005_1 = $false
  $wdSaveOpt = [Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges

  $wdApplication = $null;
  $wdDocument = $null;

  try
  {
       $wdApplication = New-Object -ComObject "Word.Application"
       $wdDocument = $wdApplication.Documents.Open($wdSourceFile)
       $wdDocument.ExportAsFixedFormat(
       $wdExportFile,
       $wdExportFormat,
       $wdOpenAfterExport,
       $wdExportOptimizeFor,
       $wdExportRange,
       $wdStartPage,
       $wdEndPage,
       $wdExportItem,
       $wdIncludeDocProps,
       $wdKeepIRM,
       $wdCreateBookmarks,
       $wdDocStructureTags,
       $wdBitmapMissingFonts,
       $wdUseISO19005_1
       )
  }
  catch
  {
       $wshShell = New-Object -ComObject WScript.Shell
       $wshShell.Popup($_.Exception.ToString(), 0, "Error", 0)
       $wshShell = $null
  }
  finally
  {
       if ($wdDocument)
       {
          $wdDocument.Close($wdSaveOpt)
          $wdDocument = $null
       }
       if ($wdApplication)
       {
          $wdApplication.Quit()
          $wdApplication = $null
       }
       [GC]::Collect()
       [GC]::WaitForPendingFinalizers()
  }
    "Document printed to \PDF\$($_.BaseName).pdf"
}