Printing to the same folder the original Word doc is in
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Printing to the same folder the original Word doc is in
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
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
-
- Site Admin
- Posts: 6902
- Joined: Wed Mar 25, 2009 10:37 pm
- Location: Chemainus, Canada
Re: Printing to the same folder the original Word doc is in
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.
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.
Best regards
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Printing to the same folder the original Word doc is in
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:
https://forum.pdf-xchange.com/ ... =39&t=4602
And looking at the changelog:
https://www.pdf-xchange.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
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:
https://forum.pdf-xchange.com/ ... =39&t=4602
And looking at the changelog:
https://www.pdf-xchange.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
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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:
The file name in the Save preferences is:
Thanks for helping me out.
Regards and Merry Xmas,
Ed
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
Code: Select all
%[Env:DocPath]\%[Date:yyyy-MM-dd] %[DocName]
Regards and Merry Xmas,
Ed
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Printing to the same folder the original Word doc is in
Glad I could help Ed!
I wish you and all your loved ones a really Joyful Christmas!
Stefan
I wish you and all your loved ones a really Joyful Christmas!
Stefan
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 6902
- Joined: Wed Mar 25, 2009 10:37 pm
- Location: Chemainus, Canada
Re: Printing to the same folder the original Word doc is in
Hi evdbogaard,
since you are using
Paul
since you are using
in the Save Dialogue and it is not saving into that folder:%[Env:DocPath]\%[Date:yyyy-MM-dd] %[DocName]
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.V5 doesn't put the pdf in the correct folder.
Paul
Best regards
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Printing to the same folder the original Word doc is in
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
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
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Printing to the same folder the original Word doc is in
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
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
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Printing to the same folder the original Word doc is in
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.
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.
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.
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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:
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
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"
I also noticed that when I use the macro %[DocPath] the file is always saved in the folder C:\My documents\.
Ed
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Printing to the same folder the original Word doc is in
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:
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.
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.
-
- User
- Posts: 81
- Joined: Mon May 26, 2008 8:52 am
- Location: Amsterdam, The Netherlands
Re: Printing to the same folder the original Word doc is in
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
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
Ed van den Bogaard
Happy PDF-XChange PRO user since 2008 (version 4)
Happy PDF-XChange PRO user since 2008 (version 4)
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Printing to the same folder the original Word doc is in
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
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