質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
VBA

VBAはオブジェクト指向プログラミング言語のひとつで、マクロを作成によりExcelなどのOffice業務を自動化することができます。

Q&A

解決済

7回答

989閲覧

vbaでpdfのink annotationを作成、変更、移動したいです

snowmansnow

総合スコア9

VBA

VBAはオブジェクト指向プログラミング言語のひとつで、マクロを作成によりExcelなどのOffice業務を自動化することができます。

0グッド

0クリップ

投稿2022/08/07 05:02

前提

実現したいこと

gestureプロパティを新規設定したいです
2つのファイル間でgestureプロパティの受け渡しをしたいのでvbaでやりたいです

発生している問題・エラーメッセージ

設定の仕方がわかりません

該当のソースコード

javascriptでは、
var annot = this.addAnnot();
annot.type= "Ink";
annot.page= 0;
annot.name= "myLine";
annot.author= "Tester";
annot.contents= "Gestures Test";
annot.gestures= [[[10,40,150,200],[350,200]]];
annot.strokeColor= color.red;
annot.width= 1;

var a = this.getAnnot(0,"myLine");

var g = a.gestures;

var h = g;

for (var i = 0; i < g.length; i++) {

for (var j = 0; j < g[i].length; j++) { for (var k = 0; k < g[i][j].length; k++) { h[i][j][k] = h[i][j][k] + 100;

var g = a.gestures;

console.println( i + " : " + j+ " : " + k + ":" + g[i][j][k] + ":" +h[i][j][k]);

} } }

var annot = this.addAnnot();
annot.type= a.type;
annot.page= a.page +1;
annot.name= a.name + "2";
annot.author= a.author;
annot.contents= a.contents;
annot.gestures= h;
annot.strokeColor= color.blue;
annot.width= a.width +2;

試したこと

vbaのjsoでのgestureの設定方法がわかりません

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

daiki002

2022/08/07 05:37

ソースコード部分の訂正を求めます。もしあなたが回答者の立場なら見づらいと思いませんか?
guest

回答7

0

自己解決

VBAの設定状況や、JSとの異動を確認したのは、
リファレンスに載ってた、jsです
var a = this.getAnnots(0); // ページ 0 の注釈をすべて取得
if ( a != null ) {
var p = a[0].getProps();// 最初の注釈のプロパティを取得
for ( o in p ) console.println( o + " : " + p[o] );
}
これで、gestures: points,相当のタイプを確認できます

投稿2022/08/16 09:00

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

snowmansnow

2022/10/14 13:36

C#でクラスライブラリを作り、vbaからink annotationを作成し、 oleでプロパティを変更する形になりました。 vbaでのgesturesの設定は、諦めました。
guest

0

だめVBAの2です
Sub Text()
'http://pdf-file.nnn2.com/?p=758
Dim jso As Object
Dim objAcroAVDoc As New Acrobat.AcroAVDoc
Dim PDDoc As New Acrobat.AcroPDDoc
Dim lRet As Long
Dim PDPage As Acrobat.AcroPDPage

Dim sFilePath As String
Dim pointsg(5) As Integer
Dim a As Variant
Dim b As Variant
Dim c As Variant
Dim d As Variant
Dim e As Variant
Dim pointsh As Variant

sFilePath = "C:\ほげほげ\アノ無.pdf"
lRet = objAcroAVDoc.Open(sFilePath, "")
Set PDDoc = objAcroAVDoc.GetPDDoc()
Set PDPage = PDDoc.AcquirePage(0)

pointsg(0) = 40
pointsg(1) = 150
pointsg(2) = 100
pointsg(3) = 200
pointsg(4) = 300
pointsg(5) = 200

a = Array(40, 150)
b = Array(100, 200)
c = Array(300, 200)
d = Array(a, b, c)
e = Array(d, Null)

pointsh = Array(pointsg, null)

Call CreateAnnotation34(pointsg, pointsh, e, PDDoc, PDPage)

End Sub
'*********************************************************************
Sub CreateAnnotation34(ByRef pointsg As Variant, ByRef pointsh As Variant, ByVal d As Variant, PDDoc As Acrobat.CAcroPDDoc, page As Acrobat.CAcroPDPage)

Dim jso As Object
Dim popupRect(3) As Integer
Dim pageRect As Object
Dim annot As Variant
Dim props As Variant
Dim props2 As Variant
Dim props3 As Variant

Dim objAcroAVDoc_B As New Acrobat.AcroAVDoc
Dim jso_B As Object
Dim sFilePathR As String
Dim pdDoc_B As New Acrobat.AcroPDDoc
Dim lRet_B As Long
Dim pageannoTs_B As Variant
Dim p2 As Variant
Dim p As Variant

sFilePathR = "C:\ほげほげ\アノ有.pdf"
lRet_B = objAcroAVDoc_B.Open(sFilePathR, "")
Set pdDoc_B = objAcroAVDoc_B.GetPDDoc()
Set jso_B = pdDoc_B.GetJSObject
jso_B.syncAnnotScan
pageannoTs_B = jso_B.GetAnnots()

For Each p In pageannoTs_B
If p.name = "myLine" Then
Set p2 = p.getProps()
Else
End If
Next

Set jso = PDDoc.GetJSObject
Set pageRect = page.GetSize

popupRect(0) = 0
popupRect(1) = pageRect.y / 2
popupRect(2) = 100
popupRect(3) = pageRect.y / 2 + 100

Set annot = jso.AddAnnot
Set props = annot.getProps
props.Type = "Ink"
props.Rect = popupRect
annot.setProps props

Set props2 = annot.getProps
props2.page = 0
props2.name = "myLine2"

'オートメーションエラーのタイプ
'props2.Gestures = p2.Gestures
'props2.Gestures = pointsh
'props2.Gestures = d

props2.author = "snowmansnow"
props2.strokeColor = jso.Color.blue
props2.contents = "test"
props2.Width = 3
annot.setProps props2

Set props3 = annot.getProps
props3.Gestures = pointsg
’gestures: points,相当のタイプ
annot.setProps props3

End Sub
なにかブレークスルーが欲しいです。i

投稿2022/08/16 08:17

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

まちがいました
①gestures: [points] のところですが、
②gestures: [points,3,5,null] などでも、”3,5,nullは無視されて”同じ描画になります
③gestures: points にすると、uboundとカンマは同じになりますが、値は代入されません。
③と同様にはVBAで設定できますが
①や②にはなりません・・・
”①や②”にしようと、array(points,null)などにすると、オートメーションエラーになります。
どうなってるんでしょう?
inkpictureのstrokeに似ていると思いますが、CreateStrokeみたいな命令があるのでしょうか?

投稿2022/08/16 05:06

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

①gestures: [points] のところですが、
②gestures: [points,3,5,null] などでも同じ描画になります
③gestures: points にすると、uboundとカンマは同じになりますが、値は代入されません。
③と同様にはVBAで設定できますが
①や②にはなりません・・・
③にしようと、array(points,null)などにすると、オートメーションエラーになります。
どうなってるんでしょう?

投稿2022/08/16 05:01

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

こんなjavascriptの習作も動きます
var points = new Array();
points[0] = [100,0];
points[1] = [130,30];
points[2] = [50,50];
points[3] = [70,70];
points[4] = [100,100];
points[5] = [240,200];
points[6] = [70,200];
points[7] = [100,0];

var annot = this.addAnnot({
type: "Ink",
page: 0,
name: "myLine",
author: "A. C. Robat",
contents: "Three leaf rose",
gestures: [points],
strokeColor: color.red,
width: 1
});

var a = this.getAnnot(0,"myLine");

var copy_props = a.getProps();

var g = copy_props.gestures;

var h = g;

for (var i = 0; i < g.length; i++) {

for (var j = 0; j < g[i].length; j++) {

for (var k = 0; k < g[i][j].length; k++) {

h[i][j][k] = h[i][j][k] + 100;

var g = a.gestures;

console.println( i + " : " + j+ " : " + k + ":" + g[i][j][k] + ":" +h[i][j][k]);

}
}
}

var annot = this.addAnnot();
var copy_props2 = annot.setProps({
type: copy_props.type,
page: copy_props.page +1,
name: copy_props.name + "2",
author: copy_props.author,
contents: copy_props.contents,
gestures: h,
strokeColor: color.blue,
width: copy_props.width +2});
でもVBAが動きません。
なぜでしょうか?

投稿2022/08/15 07:46

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

これがダメvbaです
改訂を繰り返してるので、さらに変かもしれません・・・

Sub AFormApp_Field_Add_05B作成読書()

'http://pdf-file.nnn2.com/?p=758
'On Error GoTo Err_AFormApp_Field_Add_01:

Dim bRet As Boolean
Dim bEnd As Boolean
Dim sFilePath_new As String

Dim jso As Object

Dim objAcroAVDoc As New Acrobat.AcroAVDoc
Dim lRet As Long
Dim PDDoc As Acrobat.AcroPDDoc

Dim page As Acrobat.AcroPDPage
Dim objAcroAVDoc_B As New Acrobat.AcroAVDoc
Dim objAcroPDDoc As New Acrobat.AcroPDDoc
Dim lRet_B As Long
Dim pdDoc_B As Acrobat.AcroPDDoc
Dim ipage_BNum_B As Variant

Dim pageannoTs As Variant
Dim pageannot_B As Variant
Dim pageannoTs_B As Variant
Dim page_B As Acrobat.AcroPDPage
Dim jso_B As Object

Dim props As Variant

Dim point4 As Variant
Dim point4c As Variant
Dim point4cc As Variant

Dim i1 As Long
Dim p As Variant
Dim p2 As Variant
Dim g As Variant

Dim ar(0, 2, 1) As Variant
ar(0, 0, 0) = 10
ar(0, 0, 1) = 40
ar(0, 1, 0) = 150
ar(0, 1, 1) = 200
ar(0, 2, 0) = 300
ar(0, 2, 1) = 200

lRet_B = objAcroAVDoc_B.Open("C:\ほげほげ\PDFジェスチャー読み.pdf", "")

Set pdDoc_B = objAcroAVDoc_B.GetPDDoc()

ipage_BNum_B = pdDoc_B.GetNumPages

Set jso_B = pdDoc_B.GetJSObject

jso_B.syncAnnotScan

pageannoTs_B = jso_B.GetAnnots()

For Each p In pageannoTs_B

i1 = i1 + 1

If p.name = "myLine" Then

Set p2 = p.getProps()

point4 = p2.gestures

Dim sFilePath As String

sFilePath = "C:\ほげほげ\PDFジェスチャー書き.pdf"

lRet = objAcroAVDoc.Open(sFilePath, "")

Set PDDoc = objAcroAVDoc.GetPDDoc()

Set jso = PDDoc.GetJSObject

jso.syncAnnotScan

Set pageannoTs = jso.AddAnnot()

Set props = pageannoTs.getProps

props.Type = p2.Type
props.page = 1
props.name = p2.name

Dim a As Variant
Dim a2 As Variant
Dim a3 As Variant
Dim b As Variant
Dim c As Variant

a = Array(10, 40)
a2 = Array(150, 200)
a3 = Array(300, 200)

b = Array(a, a2, a3)
c = Array(b)

props.Author = "A. C. Robat"
props.Contents = "Three leaf rose"
props.strokeColor = p2.strokeColor
props.width = 1

Dim coords As String
Dim i As Long

point4 = p2.gestures

For Each point4c In point4

coords = coords & "["

For Each point4cc In point4c

coords = coords & "["
For i = 0 To UBound(point4cc)
coords = coords & "," & point4cc(i)
Next
coords = coords & "]"
Next
coords = coords & "]"
Next

coords = Replace(Replace(coords, "(,", "("), "[,", "[")

MsgBox coords

props.gestures = p2.gestures

'PDFファイルを別名で保存
sFilePath_new = Replace(sFilePath, ".pdf", "_new.pdf")
bRet = PDDoc.Save(1, sFilePath_new)
If bRet = False Then
MsgBox "PDFファイルへ保存出来ませんでした", _
vbOKOnly + vbCritical, "エラー"
bEnd = False
End If

'PDFファイルを閉じる
bRet = objAcroAVDoc.Close(False)
If bRet = False Then
MsgBox "AVDocオブジェクトはClose出来ませんでした", _
vbOKOnly + vbCritical, "処理エラー"
bEnd = False
End If

Else
End If
Next

Skip_AFormApp_Field_Add_01:
On Error Resume Next

bRet = objAcroAVDoc.Close(False)

Set objAcroPDDoc = Nothing
Set objAcroAVDoc = Nothing
'Set objAcroApp = Nothing

If bEnd = True Then
MsgBox "処理は正常に終了しました。", _
vbOKOnly + vbInformation, "正常終了"
End If
Exit Sub

Err_AFormApp_Field_Add_01:

MsgBox Err.Number & vbCrLf & Err.Description, _
vbOKOnly + vbCritical, "実行時のエラー"
bEnd = False
GoTo Skip_AFormApp_Field_Add_01:

End Sub
御回答の足しになりますでしょうか?

投稿2022/08/08 11:49

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

こんばんは、daiki002さん
なぜこんな表示になるのかがわかりません。
とりあえず、左詰にしてみました。
var annot = this.addAnnot();
annot.type= "Ink";
annot.page= 0;
annot.name= "myLine";
annot.author= "Tester";
annot.contents= "Gestures Test";
annot.gestures= [[[10,40,150,200],[350,200]]];
annot.strokeColor= color.red;
annot.width= 1;

var a = this.getAnnot(0,"myLine");

var g = a.gestures;

var h = g;

for (var i = 0; i < g.length; i++) {

for (var j = 0; j < g[i].length; j++) {

for (var k = 0; k < g[i][j].length; k++) {

h[i][j][k] = h[i][j][k] + 100;

var g = a.gestures;

console.println( i + " : " + j+ " : " + k + ":" + g[i][j][k] + ":" +h[i][j][k]);

}
}
}

var annot = this.addAnnot();
annot.type= a.type;
annot.page= a.page +1;
annot.name= a.name + "2";
annot.author= a.author;
annot.contents= a.contents;
annot.gestures= h;
annot.strokeColor= color.blue;
annot.width= a.width +2;

これで良いでしょうか?
次で、もともと作ったダメvbaを投稿します。
これがダメで、javascriptで習作を試してみました。
javascriptが動くのでvbaでも動くと思うのですが、
いっぱい試しすぎて、こんがらがってます・・・

投稿2022/08/08 11:46

snowmansnow

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問