Convert Open word document to PDF failed - Using Custom Word

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Support Staff, moderators

Post Reply
karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

Convert Open word document to PDF failed - Using Custom Word

Post by karthiv » Thu Jun 28, 2007 4:37 pm

Hi

I am developing an application in Delphi, which adds a tool bar button in MS Word. From there, I need to call a method to convert the open word document to PDF. This does not seem to be working. I am calling a common routine, which works from one of my application. The problem is : when I click the convert to PDF in word tool bar button, it does not do anything. After a while, when I close the word mannually, it started to convert the file ask us to save.

would be greatful if we get a solution on this.

My code is :

procedure TPDFConvertBanner.ConvertToPDFFile;
var
exInfo: TShellExecuteInfo;
ExitCode: DWORD;
oldCursor: TCursor;
const
PRN_NAME_QUOTED = '"'+PRN_NAME+'"';
begin
if not PDFExchangeProPrinterExists then
raise Exception.Create(PRN_NAME + ' printer is not installed.');
{Set the values before messaging starts }
lFPrinting := False;
lFPrintAborted := False;
lFDocSaved := False;
lFMaxTimeReached := False;
HookHandleInRegistry(True);
FillChar(exInfo, SizeOf(exInfo), 0);
oldCursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
with exInfo do
begin
cbSize := SizeOf(exInfo);
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
Wnd := HWND(nil);
ExInfo.lpVerb := 'printto';
ExInfo.lpParameters := PRN_NAME_QUOTED;
lpFile := PChar(sFSourceFile);
nShow := SW_MINIMIZE;
end;
if ShellExecuteEx(@exInfo) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(exInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or (FileExists(sFTargetFile)); //Check for file exists for wordperfect
end
else
raise Exception.Create(SysErrorMessage(GetLastError));
{
After spooling is finished (when the message PDFXC3_EndDoc is received),
the Xchange Pro driver optimizes the data received from the application generating output and,
depending on the designated parameters, either save's the data for future use or creates
a PDF document. After saving the PDF document, the application receives
the PDFXC3_DocSaved message from the driver. The name of the
generated PDF document file will be saved to the registry
HKCU\Software\Tracker Software\PDF-XChange 3.0\Drivers\Control\XXXXXXXX in the key Result.FileName.
Hence the check as (lFDocSaved or lFPrintAborted)
At abnormal cases, the message will not be set due to the called application error eg - word licence expired etc.
then to avoid Infinite loop, the value of timer is taken which is
set to 30 seconds. generally this is enough for saving a document.
if required, this has to be increased...
}
DocumentSaveCheckTimer.Interval := 1000 * 30; //set for half a minute
DocumentSaveCheckTimer.Enabled := True;
repeat
Application.ProcessMessages;
if Application.Terminated then Exit;
until (lFDocSaved or lFPrintAborted or lFMaxTimeReached);
finally
Screen.Cursor := oldCursor;
end;
end;

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Fri Jun 29, 2007 2:53 pm

Hi,

Have discussed this here and we believe this has nothing to do with PDF-XChange as such.

It is hard to give any clear answer but it would appear there is some sort of 'clash' possibly because you are running Word from Word (via the ShellExecuteEx function)?
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
Tracker Support
http://www.tracker-software.com

karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

PDF Exchange : Delphi - Winword not working

Post by karthiv » Fri Jul 06, 2007 2:56 pm

Hi

We are using the WindowMessaging option, suggested by you, in the API programming approach.

'PDFXC3_StartDoc'
'PDFXC3_EndDoc'
'PDFXC3_DocSaved'

Hope this gives you some more details on the problem.

When this called from my application, it works fine. But while calling from MS Word it does not process the messages. Following is the method used in this regard.

procedure TPDFConvertBanner.WndProc(var Message: TMessage);
var
oReg: TRegistry;
begin
if (Message.Msg = pdfxcMsg_StartDoc) then
begin
if (lFPrinting = False) then Exit;
HookHandleInRegistry(False);
oReg := TRegistry.Create;
try
oReg.RootKey := HKEY_CURRENT_USER;
if oReg.OpenKey(sRegDriverControlPath + IntToHex(message.lParam, 8), True) then
begin
oReg.WriteString('Save.FullFileName', sFTargetFile);
oReg.WriteString('Save.ShowSaveDialog', 'No');
oReg.WriteString('Save.WhenExists', 'Overwrite');
oReg.WriteString('Compression.Graphics', 'No');
oReg.WriteString('Compression.ASCII', 'No');
oReg.WriteString('Compression.Text', 'No');
oReg.WriteString('Compression.Color.Method', 'None');
oReg.WriteString('Compression.Indexed.Method', 'None');
oReg.WriteString('Compression.Mono.Method', 'None');
{Embed all Fonts}
oReg.WriteString('Fonts.Embedd.All', '1');
{Donot open the PDF File after PDF conversion/Printing}
oReg.WriteString('Save.App.Run', 'None');
//Here we are passing registration key and developer code
oReg.WriteString('Reg.Key', sPDFxcKeyCode);
oReg.WriteString('Reg.DevCode', sPDFxcDevCode);
oReg.CloseKey;
end;
finally
oReg.Free;
end;
end
{To find out the status of operation - when the PDF is saved or aborted}
else if (Message.Msg = pdfxcMsg_EndDoc) then
lFPrintAborted := (Message.WParam = 0)
else if (Message.Msg = pdfxcMsg_DocSaved) then
lFDocSaved := True
else
inherited WndProc(Message);
//WndProc(Message);
end;


Regards
Karthi.

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

Post by Ivan - Tracker Software » Fri Jul 06, 2007 3:19 pm

As I understand, there is some addin for Word, which realize toolbar, and as a result of pressing button on this toolbar your code is executed.
This code is in VBA ?
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.

karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

Post by karthiv » Fri Jul 06, 2007 4:13 pm

Yes. There is an addin. The add-in code is written in Delphi 5.

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

Post by Ivan - Tracker Software » Fri Jul 06, 2007 4:31 pm

Can you execute separate thread which will receive messages? Looks like Word blocks its message queue during handling printing.
"Print in background" option is turned on into the Word's preferences ?
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.

karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

Post by karthiv » Sat Jul 07, 2007 7:39 am

I had tried "Print in background" option already. It has no impact.

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

Post by Ivan - Tracker Software » Sat Jul 07, 2007 8:47 am

Did you try to move message handler into separate thread ?
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.

karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

Post by karthiv » Mon Jul 09, 2007 2:22 pm

Thanks for your reply.

I am worried to handle the message in different thread as this might affect my other requirement of my main application(both shares the common code). Let me try and get back.

Is there anyother method to get this done, instead of window messaging?

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

Post by Ivan - Tracker Software » Mon Jul 09, 2007 2:50 pm

You can use driver's ActiveX (PXCComControl)
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.

karthiv
User
Posts: 11
Joined: Mon Feb 05, 2007 1:43 pm

Post by karthiv » Thu Jul 19, 2007 3:11 pm

But the active X control also uses the same Window Messaging methodology. Here in our case, our application does not receive the messages posted by the Printer Drivers.

Any help?

Post Reply