« [PDF]WEBページを1枚のPDFに変換する。【用紙設定】 | トップページ | [ERROR]:/b/slave/chrome-official-mac/build/src/base/platform_thread_mac.mm(66)] pthread_setname_np: Operation not permitted »

[AppleScript]WEBページURLからPDFを生成する

ダイアログに入力されたURLのWEBページを
PDFに変換します。

もちろんAppleScriptだけでは無理なので
(プリントすれば可能ですが)
今回のAppleScriptは

wkhtmltopdf
wkhtmltopdf - Project Hosting on Google Code[LINK]新しいウィンドで開きます
を使います。

ダウンロード用に用意したAppleScriptの内部に
wkhtmltopdfを内包してあります。

Force4u00220919_153633

 

wkhtmltopdfを内包しているので
容量が13MBとかあります。...汗
ダウンロードはsites.google.comから
wkhtmltopdf.app.zip[Download]新しいウィンドで開きます
にアクセスしてもらって
wkhtmltopdf.app.zip
をダウンロードしてください
Force4u00220919_161305


 

実行すると
ダイアログが表示されますので
Force4u00220919_155748


PDF化したいURLを入力します
(まぁコピー&ペーストですね)
Force4u00220919_155753

正常に終了したら
デスクトップに
日付+時刻のPDFが生成されます。

Force4u00220919_155806


 

set OriginalURL to "" as Unicode text
set thePath to "" as Unicode text
set pathAns to "" as Unicode text
set binPath to "" as Unicode text
set CombinPath to "" as Unicode text
set OriginalURL to "" as Unicode text
set UserDesktop to "" as Unicode text
set Savepath to "" as Unicode text

----日付の取得
set nowTime to my DateAndTIme(current date)
----PDFファイル名を定義日付時間+PDF
set PdfFileName to nowTime & ".pdf" as Unicode text

tell application "Finder"
activate
---ダイアログを出して
display dialog "PDFを作りたいURLをペーストしてください" default answer the OriginalURL buttons {"PDFを作成する", " 終了 "} with icon 1 with title "PDFをペーストしてください" default button 1
copy the result as list to {the OriginalURL, BottPressNo}
set ReplaceText to the OriginalURL as text

end tell

----実行したwkhtmltopdf.appのパスを求めて
set thePath to path to current application as string
----テキストに変換
set pathAns to thePath as Unicode text
----wkhtmltopdfのパスを加えて
set binPath to pathAns & "Contents:bin:wkhtmltopdf" as Unicode text
----UNIXパス形式に変更
set CombinPath to POSIX path of binPath
----PDFの保存先はログインユーザーのデスクトップ
set UserDesktop to the path to desktop from user domain as Unicode text
----UNIXパス形式に変更
set Savepath to the POSIX path of (POSIX path of UserDesktop)
----コマンドを整形
set ComLine to CombinPath & " " & ReplaceText & " " & Savepath & PdfFileName


with timeout of 60 seconds
----コマンド実行
do shell script ComLine

end timeout








--------------------------------------------------#ここからサブルーチン
to DateAndTIme(theDate)
set y to (year of theDate)
set m to my monthNumStr(month of theDate)
set d to day of theDate
set hms to time of theDate
set hh to h of sec2hms(hms)
set mm to m of sec2hms(hms)
set ss to s of sec2hms(hms)
return (y as text) & my zero1(m) & my zero1(d) & "_" & zero1(hh) & zero1(mm) & zero1(ss)
end DateAndTIme
--------------------------------------------------#ここからサブルーチン
to monthNumStr(theMonth)
set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of monList is theMonth then exit repeat
end repeat
return i
end monthNumStr
--------------------------------------------------#ここからサブルーチン
to zero1(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end zero1

--------------------------------------------------#ここからサブルーチン
to sec2hms(sec)
set ret to {h:0, m:0, s:0}
set h of ret to sec div hours
set m of ret to (sec - (h of ret) * hours) div minutes
set s of ret to sec mod minutes
return ret
end sec2hms


 

コマンド実行部に修正しました。

set ComLine to CombinPath & " " & ReplaceText & " " & Savepath & PdfFileName & " >/dev/null 2>&1"




最後の超でかいダイアログを出さないようにしました。

そのかわりに
こんなメッセージが出ます
Force4u00220919_194611

 

Safariと同じくWebKi系ですので
結構奇麗なPDFが出来上がります。


お試しを

 

wkhtmltopdfを内包しているので
容量が13MBとかあります。...汗
ダウンロードはsites.google.comから
wkhtmltopdf.app.zip[Download]新しいウィンドで開きます
にアクセスしてもらって
wkhtmltopdf.app.zip
をダウンロードしてください
Force4u00220919_161305

 

yahooで作るとこんな感じになります。

 
Force4u00220919_160356


実行後に
こんな感じのでメッセージが出ますが

Force4u00220919_162043

『リターンキー』を押せば元に戻ります。


   


|

« [PDF]WEBページを1枚のPDFに変換する。【用紙設定】 | トップページ | [ERROR]:/b/slave/chrome-official-mac/build/src/base/platform_thread_mac.mm(66)] pthread_setname_np: Operation not permitted »

AcrobatPDF」カテゴリの記事

コメント

この記事へのコメントは終了しました。