Trying to Add Multiple PDF Files to Visio on Different Pages

Started by Quickflash, February 24, 2016, 05:05:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Quickflash

Okay so this is what I have. I have a PDF file of Diagrams (1000 pages or so) and I need to add them to a visio document 1 page per page on visio 2013.

I am currently using powershell to accomplish this and this is where I am stuck at the insertfromfile.

$application = New-Object -ComObject Visio.Application
# $application.visible = $false
$documents = $application.Documents
$document = $documents.Add("Audit Diagram.vst")
$application.ActiveWindow.Page.InsertFromFile()


This is the error I get when I try to add my test.pdf to the document.
PS C:\Users\jmessier> $application.ActiveWindow.Page.InsertFromFile("C:\test.pdf",visInsertAsEmbed)
At line:1 char:61
+ $application.ActiveWindow.Page.InsertFromFile("C:\test.pdf",visInsert ...
+                                                             ~
Missing expression after ','.
At line:1 char:61
+ ... tion.ActiveWindow.Page.InsertFromFile("C:\test.pdf",visInsertAsEmbed)
+                                                         ~~~~~~~~~~~~~~~~
Unexpected token 'visInsertAsEmbed' in expression or statement.
At line:1 char:77
+ ... tion.ActiveWindow.Page.InsertFromFile("C:\test.pdf",visInsertAsEmbed)
+                                                                         ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken


After I get this portion squared away I need to set the

(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = "8 in"
(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = "10.5 in"

Thoughts?

Yacine

could you try $application.activepage.insert... instead of $application.activewindow.page.insert... ?
Yacine

Quickflash

Still No Joy

PS C:\WINDOWS\system32> $application.activepage.insertfromfile("c:\test.pdf")
Cannot find an overload for "InsertFromFile" and the argument count: "1"
At line:1 char:1
+ $application.activepage.insertfromfile("c:\test.pdf")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : RuntimeException


Yacine

... :( .

Actually two ideas:
1) Saveen Reddy has a written a toolset to command Visio from Powershell.
https://github.com/saveenr/VisioAutomation
https://vimeo.com/94408016

You may either try using his tool as is, or browse the documentation of his project to check for the command causing the problem.
May be even contact Saveen himself.

2) Most of the members code in VBA, many in .NET. If you could consider switching to one of these solutions, the support would be much greater.

Rgds,
Y.
Yacine