1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Blue Prism] PDFのページ数を取得する #blueprism

1
Last updated at Posted at 2025-12-12

やりたいこと

PDFの総ページ数を取得したい。
ループとかは無しで。だってページ数がめちゃくちゃ多かったら超時間かかるかもしれないじゃん?

ページ数はどこに書いてあるのか

ありがたきは先人の足跡。Qiitaは探すとけっこうなんでも見つかるから大好き。
ExcelVBAのみでPDFファイルのページ数を取得する
この記事によると、「/Count 99」と書いてある箇所がページ数であるらしい。

DXでアセットをゲット

DXに、Extracting Data from Text というアセットがあります。
この中に、サンプルプロセスと、「Utility - Strings(Extended)」VBOが入っています。
このアセットが欲しい主目的は、むしろこのVBOのほうです。

アクションを作る

中身はこうです。
入力引数 PDFFilePath データ形式はテキスト
出力引数 num_Page データ形式は数値
image.png

  1. Read All Text from Fileで、PDFファイルをテキストとして読み込みます。
  2. DXからダウンロードしてきた「Utility - Strings(Extended)」の中にある「Regex V2」で、「/Count 99」の箇所を抜いてきます。
    ステージの中身はこう。
    「Regex」に設定する正規表現はこうです。
"/Count (.*?)(?=[\n /])"

image.png

抽出した内容はCollectionに出力されます。こんなかんじ。
image.png

あとはこの抽出文字列から「/Count 」を抜いて数値にキャストしたらできあがりです。

終わりです

こんな単純な機能のものは標準VBOにあるでしょと思ったら意外にも無かったので、久しぶりに自作しました。
いずれ出てくるような気もしますけどね。DXをマメにチェックしておきましょう。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?