Visio Pro 2013: Visio COM Object problem with Adobe Acrobat PDFMaker Add-In

Started by CraigPatCT, July 16, 2018, 05:31:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CraigPatCT

Hi All,

A brief background:
I am an Audiovisual Designer working for an AV Integration company which provides a variety of services for the corporate/education/government sectors.

I am currently working on a project with the in-house AV Design team of one of our primary customers to create a range of standard audiovisual system design schematics using Visio, their preferred platform. These standard system designs start of as masters with all optional components and cabling connections available in their own layers.

Our customer needs to be able to send out multi-page PDFs displaying various system configurations setup as pre-configured starting points for their own in-house customers to select and configure a system for their specific purposes, such as a meeting room, or teaching space, or...

The Visio master has multiple layered pages. The first page is the overall master with all available option layers visible as a reference.

The pages 2 and onwards are copies of the first page, but with the appropriate optional layers turned off to produce the pre-configured starting points for their customers.

For example, the first two pre-configured pages might simply be two versions of a videoconference room setup, but one is using a projector with ceiling mics, and the other has an LCD display with table mics. The customer can then choose the option they're after, and if needed add or remove optional components by turning layers on or off. The customers are not able to manipulate the design in any other way.

The problem:
The above sounds simple enough, but this is a significant customer of ours with their own significant number of in-house customers, which means a lot of options, lots of layers, and more importantly, must be available to the in-house customers as a multi-layered PDF so they can select sub-options themselves.

After the in-house customers have made their selection, the multi-layered PDF is then returned to the in-house AV Design team who approve and flatten the selection for forwarding on for budget allocation. Eventually this very document document becomes the "For Construction" schematic.

The Acrobat PDFMaker AddIn for Visio works fine for exporting the first layered Visio page, but not any of the subsequent pages which have exactly the same set of layers, but are using a different layer configuration where only the layers needed are visible, producing the pre-configured variety of standard systems. When exporting any of the pages after the first page, the layers in those subsequent pages are displayed as per the settings of the first page in the Visio document.

For example:
Visio page 1 has all 330 layers visible (yes 330!), page 2 has 100 layers visible, page 3 has 30 layers visible.
The exported PDF has all layers visible on all 3 exported pages.
The visible layer configuration of page 1 is copied to all following pages in the export; they all look identical.

Unfortunately, as far as I can figure out, this is the way the PDFMaker is supposed to work. It looks like my scenario where I need multiple individually 'layered' instead of flattened pages exported in one fell swoop was never considered.

The only way around this is to export each of the pre-configured Visio pages one at a time and then use Acrobat to combine the exported pages afterwards, retaining layers.

I could replicate this manual export process relatively easily programmatically if Visio and PDFMaker communicated via VBA, but for some reason I cannot get this to work.

This declaration in the code "Dim AcroApp As Acrobat.CAcroApp" causes the compile error "User-defined type not defined".

I am not the only one with this problem. I have read several similar forum entries dating back many years since Acrobat 10, but pre-Acrobat 10 all appears to be OK. It looks to me like the type library is not registered properly, even though PDFMaker works as expected when used manually.

I believe the VBA-PDFMaker COM works correctly for the regular MS Office applications like Word & Excel.

Any assistance would be greatly appreciated here as this is a show stopper for the current project if we can't find a suitable workaround.

I'd also like to mention I greatly appreciate everyone's questions and solutions on Visio Guy. This has been an excellent learning and resource forum (pun intended) for me over the years as a part time programmer. When I become confident with my skills I hope to be a worthwhile contributor as well.

Thank you,
Craig

Surrogate

Hi, Craig !
You sure that code
Quote from: CraigPatCT on July 16, 2018, 05:31:26 AM
Dim AcroApp As Acrobat.CAcroApp
works with PDFmaker add-in ? IMHO it code can work only with Adobe Professional (not Adobe Reader).

Do you have installed Adobe Professional ?

metuemre

It's possible to access pdf file from VBA and change its properties. In your case, you can access to Layers of pdf file from Visio and turn them on/off based on the visibility in Visio file.

I can try to write an example code if you send a sample visio and pdf file.

wapperdude

Couple thoughts....not tried any of them...
First, I would make a duplicate of the Visio file, perhaps call it Adobe print file,
1)  Vaguely recall option (on per page basis) to delete unused layers.
Or
2)  write code to go thru all pages and delete layers not visible.

You could test this out with simple file that has only  2 or 3 pages and only small number of layers. 

Then try converting to Adobe.

Wapperdude

Visio 2019 Pro

CraigPatCT

Thank you everyone for replying so promptly.

Hi Surrogate,
I should have stated that I have Acrobat Pro DC on my work laptop, alongside Visio Pro 2103.

The declaration, "Dim AcroApp As Acrobat.CAcroApp", is one I've copied from one of several identical declarations used where the programmer wants to use VBA to control the Acrobat Pro PDFMaker Add-In.

I have seen small variations in the name of the COM object for earlier versions of Acrobat and Visio, but the one above seems to be current from Acrobat 10 onwards, I think. If this is not the case, then finding out the correct name will probably fix my issue here.

Hi Metuemre,

I like your suggestions as an alternative to the method I have been thinking about.

Up until now the following is an outline of what I was planning as a workaround to the Acrobat issue where exported layered pages will all follow the layer configuration of the first Visio page.

1.   Within Visio, move the Master page with all layers visible to the end, leaving the first pre-configured page in the Page 1 position. (easy)
2.   From Visio, tell the Acrobat PDFMaker Add-In to export Page 1 only, preserving layers and save to a predetermined folder. (stuck here)
3.   Within Visio, move the page just exported to the end and repeat with the next configured page. (easy)
4.   Within Visio, iterate through all pre-configured pages. (easy, except for the step 2 part)
5.   From Visio, still using VBA, tell Acrobat to combine those exported PDF documents into a single document and name accordingly. (haven't tried yet)

I have pretty much zero experience coding Visio to talk directly to an external application. I have researched this a bit and found some examples, but the majority are between Visio and Excel or Word. I'm planning on studying those along with the Acrobat SDK and whatever I can find on MSDN and see what I can come up with.

One discussion I'm reading through is a 2009 tute describing interaction between Visio and Excel from the KHKonsulting LLC website titled "Adobe Acrobat and VBA – An Introduction".
http://khkonsulting.com/2009/03/adobe-acrobat-and-vba-an-introduction/

Another more relevant 2015 Visio-PDFMaker discussion comes from an Experts Exchange post.
https://www.experts-exchange.com/questions/28631472/running-AdobePDFMakerForOffice-from-VBA-in-Visio.html

In this someone mentions a 2007 article that Acrobat XI no longer supports Visio and Publisher, which may be relevant now, but as the PDFMaker works as expected when used manually I'm not sure this is correct nowadays.

In any case, I would certainly appreciate any pointers or sample code snippets if you have the time and inclination to send me something.

With regard to sending sample files, I cannot send anything which originated from our customer; plus their Visio master docs are quite big and contain a lot of old and useless code (one of my tasks is to clean them up).

For testing relevant code I created a simple drawing with three visible shapes labelled Layer 1-3 respectively on Page 1.
I then duplicated Page 1 twice.
On Page 2 I then hid layer 1, and on Page 3 I hid layers 1 & 2.
Then I started experimenting with the PDFMaker settings for manual export to see if I could get it to export three different layered pages with just a couple of clicks.
I couldn't get this to work manually due to the PDFMaker limitation described in my first post, and therefore headed down the VBA path as our customer wants this to be as automated as possible.

Hi Wapperdude,
Thanks, but for now we need to retain all layers on all pages of the pdf export. This is so our customer's customers can hide or unhide relevant layers to make changes to available options.

When this process is working, then we'll look at restricting what options are available on each of the pre-configured system designs so the end customer doesn't select an incompatible option.

But thinking about your suggestion further, I can see that we could skip the first step where all exported pages have all layers available and just export preconfigured pages which include only those options allowed for that particular system design.

This would be setup by first creating a Visio 'print file' as you suggested.
Then run the PDFMaker manually and let it export all pages with all layers turned on. This will then present the end customer with pre-configured pages and all available options enabled, but only those options, it won't show options intended for other system standards.

I like this scenario, it's a good starting point and our customer might accept this.

If, however, our customer's AV Design manager insists that all options be switched off for their in-house customers, then I can still do the same, but follow it with Metuemre's suggestion of having Visio tell Acrobat to mimic the current layer configuration on each of the Visio pages.

Thanks again All, and I will post any successes or new information.

A side note:
I'm in Australia, so my responses will take a little while for those who are living elsewhere on our planet.

I am also required to do several other slightly less interesting tasks for my employer and customers, and this will add to the delay in my responses, even though this project has escalated somewhat.

I'm only mentioning this because I will never ignore new posts, it just might take me a day or so before I get to them.

CraigPatCT

Hi again.

After some reading through the Acrobat SDK for references to this OLE string "Acrobat.CAcroApp", and then following up on clues from the SDK using Google, I didn't find a clear answer about why I was receiving the type library error, but I did begin to think I may have been heading in the right direction regarding the Acrobat type library not being properly referenced in my version of Visio.

Until now I have been looking for a type library with a name similar to this "Adobe Acrobat 10.0 Type Library".

For Acrobat Pro DC, I assumed it would be this "Adobe Acrobat 11.x Type Library", because this is what some have said is what's required for Acrobat DC. But then again, I have also read that Adobe didn't produce an "Adobe Acrobat 11.x Type Library" and for Acrobat DC I should be using "Adobe Acrobat 10.1 Type Library".

I have none of these in my Tools | References list.

So I have been trying all the other Acrobat and Adobe items which are listed, including two type libraries specifically naming PDFMaker; all without success.

Until...
For some reason whilst scrolling through the list I kept missing an obvious one, "Acrobat". This is all it has in its name.
I tick it, save and restart Visio, and what do you know, the declaration "Dim AcroApp As Acrobat.CAcroApp" now works!

What's odd though is when I now open the Tools | References list, "Acrobat" is no longer there, but it has been replaced with "Adobe Acrobat 10.0 Type Library". ?!?!

I close Visio and reopen several times and it just keeps on working, and the type library remains listed correctly.

As I've mentioned I've got close to zero experience with this part of VBA, so it's been a learning experience fiddling with the Tools | References list and seeing the outcomes of rearranging priority order, and selecting too many references at once (hint: only select what you need).

And it took me a while to also realise the checked items in the Tools | References list are not global, but specific to each Project Document. This caused me to chase my tail for a little while.

I haven't gone any further yet with my PDF export project, but things are looking promising.

Whilst I appear to have answered my own problem here, and therefore this thread should close now (I assume), I would still appreciate your offer, Metuemre, to send through a code snippet showing me how to match the layer configuration of Visio pages to Acrobat pages.

Thanks All.
Craig

metuemre

Hi Craig,

I have bad news for you. It seems that that there is a problem with Visio PdfMaker addin. It works on Excel and Word but I couldn't make it work on Visio VBA. Please see the link that describes the problem. https://www.experts-exchange.com/questions/28631472/running-AdobePDFMakerForOffice-from-VBA-in-Visio.html. So you need to print each page to pdf manually.

Adobe Acrobat 10.0 Type Library has nothing to do with PdfMaker addin. You need to set a reference to AcrobatPDFMakerForOffice.tlb in "C:\Program Files (x86)\Adobe\Acrobat 10.0\PDFMaker\Office\AcrobatPDFMakerForOffice.tlb". Adobe Acrobat 10.0 Type Library is used to access a pdf which is already created.



metuemre

It works if you run it from the Ribbon menu but it doesn't work if you call it from VBA. I tried in Excel and Word VBA and they are both ok but there is a problem with setting COM object in Visio VBA.

CraigPatCT

Hi metuemre,

Yes, I realised after some experimenting after my last post that I was wrong and had confused myself by thinking I had PDFMaker conquered.

I am now comfortable with manipulating the external Acrobat application, with the exception of PDF layer control; I can't quite figure that out, and there's no reference to PDF layers in the Acrobat SDK.

I have the AcrobatPDFMakerForOffice.tlb reference enabled and working, sort of. I can set references to instances of PDFmaker object and settings, but they always return null when testing for their existance.

Thanks AndyW, the list looks like it should work, but as metuemre states in the next post it doesn't appear to work through the COM object in VBA.

It's very disappointing that I now seem to be able to everything I want with Acrobat, except export to layered PDFs, and manipulate layers within the PDFs from Visio.

Thanks for your help, I'll keep trying.

And I guess this also means the thread is not actually closed yet.

Craig

metuemre

Acrobat uses Optional Content Groups (OCGs) term instead of Layers. It is relatively easy to access a Layer in a specific page of a pdf file and change its visibility. Below is a sample code for your information;

Sub AttachToPdf()

    Dim AcroApp As Acrobat.CAcroApp
    Dim pdDoc As Acrobat.CAcroPDDoc
    Dim PdfPath As String
    Dim jso As Object
    Dim i As Integer
    Dim pdfLayers() As Variant
    Dim nPage As Variant
   
    PdfPath = "C:\Users\pc\Desktop\Sample.pdf" 'Path to the pdf file
    nPage = 0 'Page no in the pdf file starting with zero.

    Set AcroApp = CreateObject("AcroExch.App")
    Set pdDoc = CreateObject("AcroExch.PDDoc")

    If pdDoc.Open(PdfPath) Then
        Set jso = pdDoc.GetJSObject
          If Not jso Is Nothing Then
                pdfLayers = jso.getOCGs(nPage)
                For i = 0 To UBound(pdfLayers)
                    Debug.Print i, pdfLayers(i).Name
                    pdfLayers(i).State = True 'Toggle On/Off (Visible/Hidden) value of the Layer
                Next
        End If
    End If
    pdDoc.Save PDSaveFull, PdfPath
    pdDoc.Close

    AcroApp.Exit
    Set AcroApp = Nothing
    Set pdDoc = Nothing

End Sub

CraigPatCT

Thanks very much, metuemre, this is very helpful, and very much appreciated.

I've never come across the term "Optional Content Groups". You'd think I might have spotted this when searching the internet using the keywords layers, acrobat, SDK...

If this is explained in the Acrobat SDK then I missed it because I didn't think to look at using JavaScript through VB. You have opened my eyes to the possibilities  :)

I will now experiment with your snippet so I understand what's going on, and then use it (or parts of it) as a basis for combining automation and manual operation into a reasonably easy to follow procedure for our customers.

I'll set it up so that if Adobe ever come to the party and allow Visio VBA to control PDFMaker I can remove the manual part of the process.

Once I have a working solution put together I'll post it for review.

I won't close this thread just yet as I still have an avenue or two I haven't tried yet regarding PDFMaker (I'm very persistent with things like this), and will post any further info I come across.

Thanks again,
Craig








CraigPatCT

Hi All,
Just a quick note to say that in between my other work commitments I am making some progress and will be back with a viable workaround.
Craig