Printing to the same folder the original Word doc is in

This Forum is for the use of End Users requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers only - Please do not post requests for older versions of PDF-XChange or the PDF-Tools/OFFice2PDF applications here

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Printing to the same folder the original Word doc is in

Post by evdbogaard » Thu Dec 23, 2010 10:40 am

I want to automate the printing to pdf of Word2007 files (docx). My problem is that I want the resulting pdf to be in the same folder as the original docx-file, which is for each document different.
I use the macro %[DocPath] in the file name, but the resulting pdf is saved in the path specified in the line above File Name (in the driver printer preferences).
How can I solve this?

Kind regards,
Ed

User avatar
Paul - Tracker Supp
Site Admin
Posts: 4936
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Paul - Tracker Supp » Thu Dec 23, 2010 5:10 pm

Hi evdbogaard

thanks for the report. The issue here is that we are printing to a virtual printer. The source path of the document is not relevent to a printer and so no such information is sent for it to use. This is a limitation of the Windows printing subsystem, you cannot automate the saving of the files using the path this way.

The good news is that there are 2 ways of achieving the desired result with our products:

1. Office Addin. This application ships with PDF-XChange 4 Standards and Pro and, in contrast to the Printer can make use of the file location information. If you open the Office Addin Options and look at the "Advanced" tab you will find a checkbox "Save Document to Original Document Folder" Please note that the Options here are stored independently of both the print driver and even other Office applications' addin. Word can have different options set from Excel etc.

2. Office2PDF This application also ships with PDF-XChange 4 Standards and Pro. It can be used to set up a "watched folder" that will automatically convert to PDF any MS Office compatible file saved in there. There are also options here for where to save the PDF files.

I hope this helps.
_________________
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Fri Dec 24, 2010 10:03 am

Hi Paul,

Thanks for your clear reply.

Because I want to automate the process of creating the pdf, is there a way to program this in VBA?

At this moment I use a macro to first convert the file to pdf (adding the date at the beginning of the pdf file name and using the pdf-conversion utility form Word) and then print to a "real" printer. This does not give me a possibility to add a letterhead overlay to the pdf. That's why I want to make the pdf using PDFXChange, but I can't figure out how to code this in VBA.

Kind regards,
Ed

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Tracker Supp-Stefan » Fri Dec 24, 2010 10:24 am

Hello Ed,

if you can set Environment variables in VBA, you might be able to grab the path to the original file, set it as an environment variable, and then use it for constructing the path for the newly created PDF.

I found this topic:
http://www.tracker-software.com/forum3/ ... =39&t=4602
And looking at the changelog:
http://www.tracker-software.com/PDFX_hi ... l#4.0.0152
I can see that the problem discussed in that topic was resolved:
Changed sequence for retrieving environment variables: now it is - user's variables, pdfSaver4 process variables, system variables.

Best,
Stefan

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Fri Dec 24, 2010 1:33 pm

Hi Stephan,

I solved my problem using the code described here:
http://www.pcreview.co.uk/forums/thread-2075062.php

This is my code in VBA:

Code: Select all

Option Explicit

Private Declare Function GetEnvironmentVariable Lib "kernel32" _
  Alias "GetEnvironmentVariableA" _
  (ByVal lpName As String, _
  ByVal lpBuffer As String, _
  ByVal nSize As Long) As Long

Private Declare Function SetEnvironmentVariable Lib "kernel32" _
  Alias "SetEnvironmentVariableA" _
  (ByVal lpName As String, _
  ByVal lpValue As String) As Long
  
Sub DocumentPath()
  SetEnvironmentVariable "DocPath", ActiveDocument.Path
End Sub
The file name in the Save preferences is:

Code: Select all

%[Env:DocPath]\%[Date:yyyy-MM-dd] %[DocName]
Thanks for helping me out.

Regards and Merry Xmas,
Ed

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Tracker Supp-Stefan » Fri Dec 24, 2010 1:55 pm

Glad I could help Ed!

I wish you and all your loved ones a really Joyful Christmas!

Stefan

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Wed May 16, 2012 6:22 pm

Hi Stefan,

I have to report back on this issue.
It all worked well using V4 on a Windows XP Pro SP3, but now I have V5 on a Windows 7 (64 bit) PC and V5 does not recognize the environment variable that is created in Word (now 2010).
I can check that in Word the environment variable is created, but V5 doesn't put the pdf in the correct folder.

Any ideas?

Regards,
Ed van den Bogaard

User avatar
Paul - Tracker Supp
Site Admin
Posts: 4936
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Paul - Tracker Supp » Wed May 16, 2012 8:52 pm

Hi evdbogaard,

since you are using
%[Env:DocPath]\%[Date:yyyy-MM-dd] %[DocName]
in the Save Dialogue and it is not saving into that folder:
V5 doesn't put the pdf in the correct folder.
where does it put it? Do you need to check the box to 'Strip the Path from Document Name'? I would want to compare the path it does save to, to the one defined to see what exactly is it doing incorrectly.

Paul
_________________
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Fri May 18, 2012 11:26 am

Hi Paul,

My settings are this:

Path = F:\WB\USER\ED
File Name = %[Env:DocPath]\%[Date:yyyy-MM-dd] %[DocName]

The environment variable DocPath reads 'F:\WB\USER\ED\Zaken\Name',
so the file should be saved to 'F:\WB\USER\ED\Zaken\Name\Date DocName.pdf'.
But instead it is saved as 'F:\Date DocName.pdf'.

It makes no difference if the box to 'Strip the Path from Document Name' is checked or not.

Ed

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Tracker Supp-Stefan » Fri May 18, 2012 1:45 pm

Hi Ed,

I am discussing this with my colleagues from the dev team now -and we will post back here as soon as we have any update!

Best,
Stefan

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Sat May 19, 2012 7:14 pm

I wonder why the macro 'document path' changes the colon after the drive letter into an underscore.
If it would keep the colon I guess I wouldn't have the issue I have now.
Can I modify the 'document path' macro to keep the colon?

Regards,
Ed

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Tracker Supp-Stefan » Mon May 21, 2012 10:00 am

Hi Ed,

Please check the titrules.js file that's inside the driver's installation folder - you will need some JS knowledge, but you should be able to handle the doc name this way. It will also depend on what your V4 application is actually sending as the document path.

Best,
Stefan

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Mon May 21, 2012 12:37 pm

Hi Stefan,

Unfortunately I have no JS knowledge whatsoever.
I did look into tirules.js, however, but I didn't see which part of the code creates the %[DocPath] macro.

The application sending the file to be printed to pdf is MS Word 2010.

Ed

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Ivan - Tracker Software » Mon May 21, 2012 5:12 pm

When PDF-XChange resolves the %[Env:EvnName] macro, it is looking for EvnName in three places:
1) pdfSaver's application environment
2) user's environments (registry HKEY_CURRENT_USER\Environment)
3) per machine environment variables (registry HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment)

the order, in which these places are checked, is defined by the value EnvOrder located in the registry by a path HKEY_CURRENT_USER\Software\Tracker Software\PDF-XChange 5\pdfSaver.
This value contains a three letter string, each character representing the place where to look for the environment variable.
The characters are: A - for application environment; U - user's and M - per machine environment. The default value is UAM, that means environment variable will be checked in the order: user's, application's, and per-machine.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Tue May 22, 2012 3:35 pm

Hi Ivan,

There was no value EnvOrder, not even a key pdfSaver (that is not untill I used the pdfsaver for the first time), so I created it:

Code: Select all

[HKEY_CURRENT_USER\Software\Tracker Software\PDF-XChange 5\pdfSaver]
"Flags"=dword:00000000
"HideProgressWindow"=dword:00000000
"EnvOrder"="UAM"
But my problem still exists: the file is not saved to the correct path.

I also noticed that when I use the macro %[DocPath] the file is always saved in the folder C:\My documents\.

Ed

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Ivan - Tracker Software » Tue May 22, 2012 5:55 pm

The function SetEnvironmentVariable changes the environment variable for the process where it was called and processes derived from this process after this function call (see MSDN: http://msdn.microsoft.com/en-us/library ... 85%29.aspx).

The PDF file is generated by pdfSaver process (the component of PDF-XChange driver) and it has no access to any Word's environment variables.
To set environment variable where the driver can reach it, you have to save it to the registry in HKEY_CURRENT_USER\Environment. Here is the code that does it:

Code: Select all

Option Explicit

Private Declare Function SHSetValue Lib "Shlwapi.dll" _
  Alias "SHSetValueA" _
  (ByVal hKey As Long, _
   ByVal sSubKey As String, _
   ByVal sValue As String, _
   ByVal dwType As Long, _
   ByVal sValue As String, _
   ByVal cbData As Long) As Long
   
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
 
Sub DocumentPath()
  Dim S As String
  S = ActiveDocument.Path
  SHSetValue HKEY_CURRENT_USER, "Environment", "DocPath", REG_SZ, S, Len(S) + 1
End Sub
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

evdbogaard
User
Posts: 36
Joined: Mon May 26, 2008 8:52 am
Location: Amsterdam, The Netherlands

Re: Printing to the same folder the original Word doc is in

Post by evdbogaard » Wed May 23, 2012 10:03 am

Hi Ivan,

Your code does the trick.
By the way, this morning I tried my old code with V5 on a Windows XP machine and Word 2007. On that machine my old code worked without any problem! So I guess the problem is not V5 but has some thing to do with Windows XP vs 7 or with Word 2010 vs 2007.

Anyway, I'm very happy with your solution. So thanks a million!

Regars,
Ed

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13439
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Printing to the same folder the original Word doc is in

Post by Tracker Supp-Stefan » Wed May 23, 2012 11:23 am

Glad to hear it's working Ed,

Yep - it might be a difference between XP and WIn7 or between Office versions - but in any case - it's good to have an universal solution :)

Best,
Stefan

Post Reply