bdl20042000
Messages postés63Date d'inscriptionmercredi 18 août 2004StatutMembreDernière intervention19 mai 2009
-
29 mars 2007 à 11:57
kad68
Messages postés1Date d'inscriptionmardi 18 mai 2004StatutMembreDernière intervention11 septembre 2008
-
11 sept. 2008 à 11:54
Bonjour,
j'essaie depuis 2 jours à faire un petit programme en VB6 + PDFCreator 0.9.3 pour transformer une liste de fichiers Word en fichiers PDF.
Le problème, c'est que à chaque fois PDFCreator m'ouvre un fenêtre me demandant d'enregistrer le fichier.
Dans Word, via un macro en VBA, j'ai trouvé la solution via les exemples de PDFCreator.
Mais sous VB , cela ne marche pas.
voici le code :
Dim oWord As Object
Dim PDFCreator1 As PDFCreator.clsPDFCreator
Dim opt As clsPDFCreatorOptions
Dim DefaultPrinter As String
Dim sRep, sNomFic As String
Dim sDoc As Variant
Set PDFCreator1 = New clsPDFCreator
Set oWord = CreateObject("Word.Application")
Set sDoc = oWord.Documents.Add(fichier, False)
oWord.Visible = False
DefaultPrinter = oWord.ActivePrinter ' On sauvegarde l'imprimante par défaut
oWord.ActivePrinter = "PDFCreator" ' pour le remplacer par l'imprimante PDF Creator
PDFCreator1.cVisible = False
Set opt = New clsPDFCreatorOptions
With opt
.UseAutosave = 1
.UseAutosaveDirectory = 1
.AutosaveDirectory = sRep ' Répertoire
.AutosaveFormat = 0 ' PDF
.AutosaveFilename = sNomFic ' Nom du fichier
End With
With PDFCreator1
Set .cOptions = opt
.cClearCache
.cPrinterStop = False
End With
oWord.PrintOut Background:=False ' Imprimer sur PDFCreator
'Sleep 1500 ' Sinon fenêtre de sauvegarde de PDFCreator
oWord.ActivePrinter = DefaultPrinter
sDoc.Close SaveChanges:=False ' Fermer le doc sans faire de sauvegarde
Set opt = Nothing
PDFCreator1.cClose
Set PDFCreator1 = Nothing
oWord.Application.Quit ' Fermer Word
Set oWord = Nothing
Si quelque peut me dire pourquoi cela ne marche pas car il me demande toujours le nom du fichier pour l'enregistrer.
drikce06
Messages postés2236Date d'inscriptionlundi 29 mai 2006StatutMembreDernière intervention29 mai 200810 29 mars 2007 à 15:18
Salut regarde bien les exemples car avec eux normalement tu n'as pas ces boites de dialogues! En tout cas amuse toi bien parce que c'est un peu la misère!
Drikce 06
Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
drikce06
Messages postés2236Date d'inscriptionlundi 29 mai 2006StatutMembreDernière intervention29 mai 200810 29 mars 2007 à 15:23
Si cela peut t'aider voilà le bout code que j'avais fait sur l'utilisation de PDF creator, en tout cas une fois que ça fonctionnera poet la solution stp car ça m'interesse:
opt = _PDFCreator.cOptions
With
opt
'.PDFOptimize'.UseCustomPaperSize str
.PDFGeneralAutorotate = 2
.UseFixPapersize = 1
.Papersize = format
.UseAutosave = 1
.UseAutosaveDirectory = 1
.AutosaveDirectory = doc.Path
.AutosaveFormat = 0
.AutosaveFilename = doc.Name
End
With
With
_PDFCreator.cOptions = opt
.cClearCache()
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter =
"PDFCreator"
.cPrintFile(doc.FullName)
.cPrinterStop =
False
End
With
doc.PrintOut()
ReadyState =
False
With
Timer1.Interval = maxTime * 1000
.Enabled =
True
Do
While
Not
ReadyState
And
.EnabledApplication.DoEvents()
Loop
.Enabled =
False
End
With
'If Not ReadyState Then
'MsgBox("Creating printer test page as pdf." & vbCrLf & vbCrLf & _
'"An error is occured: Time is up!", MsgBoxStyle.Exclamation, Me.Text)
'End If
_PDFCreator.cPrinterStop =
True
_PDFCreator.cDefaultPrinter = DefaultPrinter
topapp.CurrentDocument.Close(
False
,
False
)doc =
Nothing
opt =
Nothing
Drikce 06
Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
bdl20042000
Messages postés63Date d'inscriptionmercredi 18 août 2004StatutMembreDernière intervention19 mai 2009 29 mars 2007 à 16:54
Au lieu de partir de mon projet, j'ai repris d'exemple1 et je l'ai modifié à ma sauce, et maintenant cela fonctionne!
En plus, cela a l'avantage de n'avoir pas besoin de créer d'objet Word, mais l'inconvénient cela affiche Word à chaque document à convertir et je ne réussis pas à le masquer.
CODE :
Option Explicit
Dim sFichier() As String ' liste des fichiers DOC à convertir
Dim sPathRacine As String, sFiles() As String
Private WithEvents PDFCreator1 As PDFCreator.clsPDFCreator
Private pErr As clsPDFCreatorError, opt As clsPDFCreatorOptions
Private noStart As Boolean, fac As Double, StartTime As Date
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Sub Enlever_Click()
If List1.ListCount <= 0 Then Exit Sub
List1.RemoveItem List1.ListIndex ' supprime
End Sub
Private Sub Ajouter_Click()
Dim i As Integer
With Dialog1
' Personnalisation
.DialogTitle = "Choisissez le(s) fichier(s) DOC"
.Filter = "Fichiers Word (*.DOC)| *.DOC"
.ShowOpen
End With
sFiles = Split(Dialog1.FileName, vbNullChar)
' Mettre dans une liste grâce à la fonction Split sur le caractère Null
If Len(Dialog1.FileName) <> 0 Then
'Un ou plusieurs fichiers
If sFiles(0) = Dialog1.FileName Then
List1.AddItem (sFiles(0))
Else
sPathRacine = sFiles(0) & ""
i = 1
Do
On Error GoTo Fin
List1.AddItem (sPathRacine & "" & sFiles(i))
i = i + 1
Loop
End If
End If
Fin:
End Sub
Private Sub Form_Load()
noStart = True
'Initialisation du commondialog
Dialog1.Flags = &H200 Or &H80000
'Permet le multiselect (200)
'et la boite de dialogue est de type explorateur (80000)
Dialog1.MaxFileSize = 32767
'Nombre de caractères maximum du multiselect (Valeur par défaut=256)
Set PDFCreator1 = New clsPDFCreator
Set pErr = New clsPDFCreatorError
With PDFCreator1
.cVisible = True
If .cStart("/NoProcessingAtStartup") = False Then
If .cStart("/NoProcessingAtStartup", True) = False Then
Traitement.Enabled = False
Exit Sub
End If
AddStatus "Une instance de PDFCreator existe déjà, il faut le fermer!"
.cVisible = True
End If
' Get the options
Set opt = .cOptions
.cClearCache
noStart = False
End With
AddStatus "Le programme vient de démarrer"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If noStart = False Then
DoEvents
PDFCreator1.cClose
End If
DoEvents
Set PDFCreator1 = Nothing
Set pErr = Nothing
Set opt = Nothing
End Sub
Private Sub quitter_Click()
Unload Me
End Sub
Private Sub Traitement_Click()
Dim DefaultPrinter As String
Dim i As Integer
Private Sub ImprimePDF(ByVal fichier As String)
Dim sRep, sNomFic As String
Dim i As Integer
'Séparer le chemin du nom de fichier
If InStr(fichier, "") Then
For i = Len(fichier) To 0 Step -1
If Mid(fichier, i, 1) = "" Then
Exit For
End If
Next i
sRep = Left(fichier, i)
sNomFic = Mid(fichier, i + 1)
sNomFic = Left(sNomFic, Len(sNomFic) - 4)
Else
sRep = ""
sNomFic = Left(fichier, Len(fichier) - 4)
End If
AddStatus "Début de la création du fichier PDF ..."
With opt
.AutosaveDirectory = sRep
.AutosaveFilename = sNomFic
.UseAutosave = 1
.UseAutosaveDirectory = 1
.AutosaveFormat = 0 ' PDF
End With
With PDFCreator1
Set .cOptions = opt
.cClearCache
.cDefaultPrinter = "PDFCreator"
.cPrintFile (fichier)
.cPrinterStop = False
End With
PDFCreator1.cPrinterStop = False
StartTime = Now
End Sub
Private Sub AddStatus(Str1 As String)
With txtStatus
If LenB(.Text) = 0 Then
.Text = Time & ": " & Str1
Else
.Text = .Text & vbCrLf & Time & ": " & Str1
End If
.SelStart = Len(.Text)
End With
End Sub
Private Sub PDFCreator1_eReady()
AddStatus """" & PDFCreator1.cOutputFilename & """ a été créé! (" & _
DateDiff("s", StartTime, Now) & " secondes)"
PDFCreator1.cPrinterStop = True
Screen.MousePointer = vbNormal
End Sub
Private Sub PDFCreator1_eError()
Set pErr = PDFCreator1.cError
AddStatus "Error[" & pErr.Number & "]: " & pErr.Description
Screen.MousePointer = vbNormal
End Sub
Si cela peut interresser des personnes, je peux mettre le projet dans la partie Code du site.
bdl20042000
Messages postés63Date d'inscriptionmercredi 18 août 2004StatutMembreDernière intervention19 mai 2009 29 mars 2007 à 17:30
Salut,
c'est ce que j'avais fait que le premier cas.
Mais dans le second cas , c'est PDFCreator qui lance Word automatiquement, aussi à aucun moment, je n'ai accès à l'objet Word pour le manipuler.
axilysl
Messages postés1Date d'inscriptionmercredi 5 décembre 2007StatutMembreDernière intervention10 septembre 2008 10 sept. 2008 à 17:19
Bonjour bd20042000,
je ne sais pas si quelqu'un pourrai m'aider, je suis super débutante et il m'a été demandé de génrer un pdf à partir d'un dataset ou même d'un HTML si possible.
je vous serai trs reconnaissant. je galère fort
Merci d'avance
kad68
Messages postés1Date d'inscriptionmardi 18 mai 2004StatutMembreDernière intervention11 septembre 2008 11 sept. 2008 à 11:54
salut,
c'est une application web ou locale qui doit générer ce fameux pdf ?
si c'est web, si tu veux générer un nouveau document pdf à parti d'un DataSet, essaye itextsharp ou équivalent, ça te permettra de le générer en temps réel sans écrire sur le disque
sinon tu peux tout a fait générer un fichier HTML sur le disque puis te baser sur le programme de bdl20042000 pour demander l'impression en PDF de ce fichier généré.