Dhomson

PDF creating not working on win7

26 posts in this topic

Hi everybody,

I have script that already work on windows xp + corel X5 , but not work on windows 7 + corel x7. 

Here is a piece of code : 

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OŚ"
If $CmdLine[0] == 0 Then
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        EndIf
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        Exit MsgBox(64, Default, "Done", 1)
    EndIf
EndIf

..

 

Share this post


Link to post
Share on other sites



"not work" is hard to diagnosis.  Can you explain what is not working?   Do you get an error?  Also, Word.Au3 is a standard include so you can just do this:

#include <Word.au3>

No path required ... 

If you don't see an error you could add some com error handling (see help file for details).


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
31 minutes ago, Dhomson said:
If FileExists(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\2.pdf")

I have error "No file and path.."

I can't find such a line in your opening Post. Only one MsgBox after a Exit:

If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)

but this isn't the same.

Share this post


Link to post
Share on other sites

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OŚ"
If $CmdLine[0] == 0 Then
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        EndIf
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        Exit MsgBox(64, Default, "Done", 1)
    EndIf
EndIf

If FileExists(@ScriptDir & "\1.pdf") Then
    If FileDelete(@ScriptDir & "\1.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 1.pdf w " & @ScriptDir)
EndIf
If FileExists(@ScriptDir & "\document.doc") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\document.doc")
If FileExists(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\2.pdf")
$oWordApp = _WordCreate(@ScriptDir & "\document.doc", 0, 0, 0)
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oDoc.Range.Font.Color = 0
For $i=1 To $oDoc.Sections.Count()
    $oDoc.Sections($i).Headers(1).Range.Font.Color = 0
    $oDoc.Sections($i).Footers(1).Range.Font.Color = 0
Next
$path = @ScriptDir

If StringRight(@ScriptDir, StringLen($type)+1) == "\" & $type Then $path = StringTrimRight(@ScriptDir, StringLen($type)+1)

$SiteName = StringTrimLeft($path, StringInStr($path, "\", 0, -1))

If $CmdLine[0] == 1 AND $CmdLine[1] == "DRUK" Then
    If $oDoc.Shapes.Count() <> 2 Then
        _WordDocClose($oDoc, 0)
        _WordQuit($oWordApp)
        Exit MsgBox(16, Default, "not enaught " & $PathDoc)
    EndIf
    $oDoc.Shapes(2).Delete
    $range = $oDoc.Content
    $range.Find.Execute("Egzemplarz nr    1 / 1", False, False, True)
    If $range.Find.Found = False Then _WordDocFindReplace($oDoc, "Egzemplarz nr    1 / ", "Egzemplarz nr      / ")
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & " DRUK.pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                        @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & ' DRUK.pdf" -overwrite concat'
                If RunWait($line, "", @SW_HIDE) == 1 Then Exit MsgBox(16, Default, "error while compare " & @ScriptDir)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
Else
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & ".pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                    @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & '.pdf" -overwrite concat'
                Run($line, "", @SW_HIDE)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
EndIf
 

Share this post


Link to post
Share on other sites

I think you need to add the com error handling and look at the exact error message to see why the document is not getting published as 2.pdf from the Corel object.  You changed versions of Corel.  Maybe the COM api changed too. 


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This script couldn't throw the error, as it is exiting before this line (72) can be executed line 64: Exit MsgBox(64, Default, "Done", 1).

  • Are you sure the title for WinExits is correct?
  • Are you also sure Corel is active?
Edited by AutoBert

Share this post


Link to post
Share on other sites

@AutoBert - I would go one step further and check if the block of code in the outermost IF statement is being executed.  He said the script exit message is consistent with line 72.  That makes me think the outermost IF is skipped, that entire block is skipped and there are no objects, and therefore no PDF created (which causes exit on 72).  Also, why is this condition necessary to test for no command line parameters (I am assuming that is what this is doing)?  

If $CmdLine[0] == 0 Then

You could eliminate that condition.  Alternatively, one quick way to test to see if the outermost IF is working could be to add this on the line following the if statement:

msgbox(0,"Hello","I am talking to you from the IF statement")

Then you could add a similar message after this to test your theory:

If WinExists($WindowName) Then
msgbox(0,"Hello again","The window exists")

 


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

WinExits is correct  and  Corel is active . 

Maybe Win 7 ban some action between programs ? 

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

22 hours ago, Dhomson said:

I have script that already work on windows xp + corel X5 ,

This script never runs as already mentioned it exit in line 64, try this one:

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OS"
$iErr=1
If $CmdLine[0] == 0 Then
    $iErr=0
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        ;Exit MsgBox(64, Default, "Done", 1)
        MsgBox(64, Default, "Done", 1)
    Else
        $iErr=2
    EndIf
    If $iErr Then MsgBox(64, "Error", $iErr, 10)
EndIf
If $iErr=0 Then ConsoleWrite('corel seems to work'&@CRLF)

If FileExists(@ScriptDir & "\1.pdf") Then
    If FileDelete(@ScriptDir & "\1.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 1.pdf w " & @ScriptDir)
EndIf
If FileExists(@ScriptDir & "\document.doc") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\document.doc")
If FileExists(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\2.pdf")
ConsoleWrite('creating word document'&@CRLF)
$oWordApp = _WordCreate(@ScriptDir & "\document.doc", 0, 0, 0)
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oDoc.Range.Font.Color = 0
For $i=1 To $oDoc.Sections.Count()
    $oDoc.Sections($i).Headers(1).Range.Font.Color = 0
    $oDoc.Sections($i).Footers(1).Range.Font.Color = 0
Next
$path = @ScriptDir

If StringRight(@ScriptDir, StringLen($type)+1) == "\" & $type Then $path = StringTrimRight(@ScriptDir, StringLen($type)+1)

$SiteName = StringTrimLeft($path, StringInStr($path, "\", 0, -1))

If $CmdLine[0] == 1 AND $CmdLine[1] == "DRUK" Then
    If $oDoc.Shapes.Count() <> 2 Then
        _WordDocClose($oDoc, 0)
        _WordQuit($oWordApp)
        Exit MsgBox(16, Default, "not enaught " & $PathDoc)
    EndIf
    $oDoc.Shapes(2).Delete
    $range = $oDoc.Content
    $range.Find.Execute("Egzemplarz nr    1 / 1", False, False, True)
    If $range.Find.Found = False Then _WordDocFindReplace($oDoc, "Egzemplarz nr    1 / ", "Egzemplarz nr      / ")
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & " DRUK.pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                        @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & ' DRUK.pdf" -overwrite concat'
                If RunWait($line, "", @SW_HIDE) == 1 Then Exit MsgBox(16, Default, "error while compare " & @ScriptDir)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
Else
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & ".pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                    @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & '.pdf" -overwrite concat'
                Run($line, "", @SW_HIDE)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
EndIf

Post output of sciteconsole after tested.

Edited by AutoBert

Share this post


Link to post
Share on other sites
1 minute ago, Jfish said:

@AutoBert then how does he see this message that only shows on line 72?

He didn't post script he realy runs, in his posted script it isn't possible, in mine maybe, i have no Corel.

Share this post


Link to post
Share on other sites

The first time he didn't post that script which is why you raised the very good point that the error message was not in the code.  The second time it looks like he posted the whole script and that error he referenced is on line 72.  Maybe I am missing something on my end but that is how I read it.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
3 minutes ago, Jfish said:

The second time it looks like he posted the whole script and that error he referenced is on line 72.

In line 64 is a exit

$oDoc.PublishToPDF(@ScriptDir & "\2.pdf") ;line63
        Exit MsgBox(64, Default, "Done", 1)

so line 72 can never reached and if he realy run posted script he never see this error.

Share this post


Link to post
Share on other sites

OK. I add :

If WinExists($WindowName) Then
msgbox(0,"Hello again","The window exists")

and only message is "done" and empty pdf is creating. I past the name of window and code. What can be wrong ?  

Bez tytułu.jpg

Share this post


Link to post
Share on other sites

You are right one $CmdLine arg is needed and script will not try to create a PDF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now