2021年9月27日 星期一

PDF檔轉換成純文字檔,並抽取出IP資訊

Regular expression IPv4 addresses cover the range 0.0.0.0 to 255.255.255.255
IPv4 アドレスにマッチする正規表現

步驟一:

備妥PDF轉換成TEXT環境套裝程式

依作業系統環境,選擇下載套裝程式
https://miktex.org/download

步驟二:
安裝執行basic-miktex
備妥PDF轉換純文字程式,PDFTOTEXT

步驟三:
下列為BATCH批次檔
rem  將PDF檔先轉換成暫存純文字檔案
pdftotext %1 txtTempPDF.txt

rem 將PDF轉換完成為TEXT文字檔後,經由grep工具取出IP資訊
grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' txtTempPDF.txt  -o > Tipip.txt

rem 開啟經由grep篩選出之IP資訊
explorer Tipip.txt



參考資訊:
grep 過濾篩選指令

Windows環境,直接執行UnixLike指令

Utility programs (e.g. "grep") in the cygwin bash environment 相關執行檔案


2020年9月16日 星期三

auto-py-to-exe 轉換PY程式成為EXE

Step1:

安裝執行auto-py-to-exe圖形GUI界面之PYTHON轉換EXE套件程式

Step2:

將前個PYTHON程式( PYTHON旋轉PDF之程式載入),即可產出EXE執行檔


參考資訊:

auto-py-to-exe PYTHON轉換成EXE執行檔套件


PYTHON提供旋轉rorate PDF

下面為PYTHON自訂旋轉PDF (將下列紅色部分,貼在Notepad記事本,另存成RoratePDF.py)

 # importing the required modules彙入相關必要之模組 

import PyPDF2 

import sys

#'開啟檔案總管 (開啟轉換後之檔案使用)'

import subprocess

#'開啟GUI 取得來源檔(找出欲旋轉之PDF檔案)

import tkinter as tk

from tkinter import filedialog


root = tk.Tk()

root.withdraw()


FilePathName = filedialog.askopenfilename(initialdir = "/",title = "Select file for rotate (選擇欲旋轉之PDF檔案)",filetypes = (("PDF files","*.pdf"),("all files","*.*")))


  

def PDFrotate(origFileName, newFileName, rotation): 

  

    # creating a pdf File object of original pdf 

    pdfFileObj = open(origFileName, 'rb') 

      

    # creating a pdf Reader object 

    pdfReader = PyPDF2.PdfFileReader(pdfFileObj) 

  

    # creating a pdf writer object for new pdf 

    pdfWriter = PyPDF2.PdfFileWriter() 

      

    # rotating each page 

    for page in range(pdfReader.numPages): 

  

        # creating rotated page object 

        pageObj = pdfReader.getPage(page) 

        pageObj.rotateClockwise(rotation) 

  

        # adding rotated page object to pdf writer 

        pdfWriter.addPage(pageObj) 

  

    # new pdf file object 

    newFile = open(newFileName, 'wb') 

      

    # writing rotated pages to new file 

    pdfWriter.write(newFile) 

  

    # closing the original pdf file object 

    pdfFileObj.close() 

      

    # closing the new pdf file object 

    newFile.close() 

      

  

def main(): 

  

    # original pdf file name 

    origFileName = FilePathName

     

    # new pdf file name 

    newFileName = 'rotated_example.pdf'

      

    # rotation angle 自訂旋轉角度

    rotation_data = int(input("Enter a rotation angle(90、180): "))

      

    # calling the PDFrotate function 

    PDFrotate(origFileName, newFileName, rotation_data) 

      

if __name__ == "__main__": 

    # calling the main function 

    main() 


ListALLCD_2_DISK 僅列出全數光碟之檔案,另獨立出各目錄

將下列紅色部分,另存新檔至桌面   ListALLCD_2_DISK.cmd  ,存檔後點選執行。


rem  將前次處理舊檔案予以清除d:\listcd.txt

SET MYFILE="d:\listcd.txt"

IF EXIST %MYFILE% DEL /F %MYFILE%


rem 假設光碟槽在E槽

dir e: /s/w/o/p/a:-d >>d:\listcd.txt


rem 利用EXCEL檔,去開啟光碟臚列出全數檔案(依各自目錄,僅列出檔案),但EXCEL檔路徑,可能要自行修改

"C:\Program Files\Microsoft Office\Office16\EXCEL.EXE" d:\listcd.txt


參考資訊:

DIR命令提示資訊

(日文)dir 命令提示 列出檔案


2018年10月26日 星期五

以命令提示方式,將OFFICE轉成ODF開放格式檔

LibreOfficeのコマンドライン変換機能を使ってODF、ODTを作成する。
命令提示列,無需開啟主程式,即可轉換OFFICE檔案,成 開放格式檔。



Step1:下載 ODF文件應用工具

Step2:安裝 NDC ODF Application Tools

Step3:將下面紅色部分,貼於記事本(Notepad.exe)中,並另存新檔名至桌面成ConvertOffice2ODF.cmd

@echo off
setlocal
cd /d %~dp0

rem 如附加檔為XLSX格式,則至XLSX_ODS1位置執行轉換
if %~x1 EQU .xlsx  goto XLSX_ODS
if %~x1 EQU .xls  goto  XLS_ODS
if %~x1 EQU .docx goto  DOCX_ODT
if %~x1 EQU .doc  goto  DOC_ODT
if %~x1 EQU .CSV  goto  DOCX_ODT

:non_Office
echo "本批次檔,僅供轉換WORD及EXCEL "
pause
goto end

:DOCX_ODT
start /wait soffice --headless --convert-to odt %1 --outdir %userprofile%\desktop
goto end

:DOC_ODT
start /wait soffice --headless --convert-to odt %1 --outdir %userprofile%\desktop
goto end

rem 執行轉換成ODS格式
:XLSX_ODS
start /wait soffice --headless --convert-to ods %1 --outdir %userprofile%\desktop
goto end

:XLS_ODS
start /wait soffice --headless --convert-to ods %1 --outdir %userprofile%\desktop
goto end

:end
REM 以檔案總管,開啟 桌面,並查詢剛產出之ODF、ODS檔
explorer %userprofile%\desktop



Step4:
將欲合併之檔案,Drag and drop拖放至桌面 ConvertOffice2ODF.cmd上方,即可自動合併成單一ODF/ODS檔




新增右鍵開啟(),將下列紫色部分
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\2_OpenDocument]
@="Convert Office to OpenDocument(ODF/ODS)"

[HKEY_CLASSES_ROOT\*\shell\2_OpenDocument\command]
@="d:\\ODF\\ConvertOffice2ODF.cmd \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\2_OpenDocument]
@="Convert Office to OpenDocument(ODF/ODS)"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\2_OpenDocument\command]
@="d:\\ODF\\ConvertOffice2ODF.cmd \"%1\""



相關檔案下載:

2018年1月4日 星期四

Merge Multiple PDF in one

如何快速將所有之PDF檔案,轉換成單一PDF檔?
複数のWORDのファイルをひと一つのPDFにまとめる方法

Step1:下載GhostScript合併PDF工具

Step2:解壓縮 將其bin路徑下之檔案(如:gswin32c.exe及相關dll檔),拷貝至c:\windows\system32(或PATH路徑下指定相關執行目錄)

Step3:將下面紅色部分,貼於記事本(Notepad.exe)中,並另存新檔名至桌面成MergeAllPDFinOne.cmd
setlocal
gswin32c -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -sOutputFile="%1"MergedALL.PDF %1 %2 %3 %4 %5 %6 %7 %8  %9 

Step4:
將欲合併之檔案,Drag and drop拖放至桌面 MergeAllPDFinOne.cmd上方,即可自動合併成單一PDF檔

相關查詢:
將目錄(含全數之子目錄)中 ,所有Office檔案,自動轉換成PDF檔案
檔案參數傳送超過10個以上查詢,
自訂滑鼠右鍵(將MergeAllPDFinOne.cmd,拷貝至shell:sendto)新增合併PDF成單一檔,只要一次將全數PDF選好後,按下右鍵 合併PDF成單一檔,即可快速完成所有PDF轉換成單一PDF檔

缺點:拖拉方式不方便控制PDF檔案合併順序,
備註:可以命令提示列方式 MergeAllPDFinOne.cmd Page2.pdf Page1.pdf Page3.pdf 手動指定合併順序 

2018年1月1日 星期一

Batch Convert PDF大批OFFICE檔轉PDF檔

自動將目錄中(含其子目錄)所有OFFICE檔案,自動轉換成PDF檔案?

Scenario(シナリオ):家中小孩考試前列印學校之歷屆考題,有WORD檔,也有是PDF檔,但處理列印工作時,PDF檔案列印(SumatraPdfReader)與WORD檔列印相較,個人傾向使用PDF列印。
問題來了,每年級(3個年級)有上下學期,每學期又分成3次段考,又細分國/英/數/社/自(理化/地科)等解開壓縮檔後,從100年~106年WORD檔要轉換成PDF檔就是相當可觀的轉換工作。

Office文書(複数のWordファイルに)を一括でPDFにする
Solution辦法:以Batch File大批處理Office轉換成PDF
步驟ステップ1:
下載OfficeToPDF並解壓縮至c:\windows\system32   (讓該檔變全域,即可在電腦任何目錄均可叫的到OfficeToPDF)

步驟ステップ2:
將下面程式(如紅色部分),貼至 記事本(notepad.exe) ,另存成 Doc2PDF.bat 
setlocal
cd /d %~dp0
For /R %%X in (*.doc) do OfficeToPDF "%%X" "%%~nX.pdf"


步驟ステップ3:
Doc2PDF.bat 拷貝(COPY)至歷屆試題目錄下執行,它即可自動將所有子目錄中之WORD檔轉換成PDF檔案(包含所有的子目錄,即國/英/數/社/自等目錄)

註:
1. 因OfficeToPDF不限處理DOC,故亦可轉換XLS 、PPT等,只要將步驟2  (*.doc),改成 (*.xls)等,就可轉換其他類型之OFFICE檔案成PDF檔
2.有時轉換可能會因WORD開啟卡住,建議採一次段考為範圍之目錄進行轉換(即步驟3動作,將批次檔COPY至該目錄執行)。

相關查詢:
如何將多數PDF檔合併成單一PDF檔,
(GNU GPL)HTTRack歷屆試題下載工具(輸入學校歷屆試題網址後,即可一次全數下載下來),