9
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PDFに関するPowerShellいろいろ

Posted at

メモです

ExcelファイルをPDFに変換する

convertExcel2Pdf.ps1
# エクセルオブジェクト取得
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false

# 引数からファイル名を取得
$fileName = $args[0]
$absolutePath = Convert-Path($fileName)

# Excelファイルを開き、1シート目を選択
$book = $excel.Workbooks.Open($absolutePath)
$sheet = $book.Worksheets.Item(1)

# PDFに変換
$pdfName = $absolutePath + ".pdf"
$sheet.ExportAsFixedFormat(0, $pdfName)

# エクセルを閉じる
$book.Close($false)
$excel.Quit()
$excel = $null
$book = $null
$sheet = $null

ページ数が1ページより大きいPDFファイルを表示(ワンライナー)

# pdftk.exeを使用
Get-ChildItem | %{ $pdf = pdftk $_.FullName dump_data; $NumOfPages = [rege
x]::match($pdf, 'NumberOfPages: (\d)').Groups[1].Value; If ($NumOfPages -gt 1) { Write-Host $_.Name" "$NumOfPages"ページ
" } }
9
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?