Bonjour,
L’interface COM a été totalement refondue.
Voici en VB6 un exemple (A retrouver ici : http://grandzebu.net/informatique/vb/printPDF-2.zip :
Option Explicit
Private PDF As New PdfCreatorObj
’Avec PDFcreator V 2.1 / With PDFcreator V 2.1
Private Sub Command1_Click()
Dim OldPrinterName$, Prt As Printer, PDFQueue As New Queue, MyJob As PrintJob, PDFdevices As Printers, PDFprinterName$, Chaine$
Screen.MousePointer = vbHourglass
Command1.Enabled = False
'Garder l’imprimante actuelle
'Keep the current printer
OldPrinterName$ = Printer.DeviceName
'Obtenir le nom de l’imprimante PDF
'Get the name of the PDF printer
Set PDFdevices = PDF.GetPDFCreatorPrinters
PDFprinterName$ = PDFdevices.GetPrinterByIndex(0)
'Diriger Printer vers PDFcreator
'Direct Printer to PDFcreator
For Each Prt In Printers
If Prt.DeviceName = PDFprinterName$ Then
Set Printer = Prt
Exit For
End If
Next
'Initialiser
'Initialize
PDFQueue.Initialize
'Maintenant on imprime
'Now we print
Chaine$ = “Hello World”
Printer.Line (500, 500)-(Printer.ScaleWidth - 500, Printer.ScaleHeight - 500), , B
Printer.Line (3500, 3500)-(Printer.ScaleWidth - 3500, Printer.ScaleHeight - 3500), , B
Printer.Font.Size = 30
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Chaine$)) / 2
Printer.CurrentY = (Printer.ScaleHeight - Printer.TextHeight(Chaine$)) / 2
Printer.Print Chaine$
Printer.EndDoc
'Attendre que le document arrive dans la file d’impression
'Wait until the document arrives in the queue
Do Until PDFQueue.Count > 0
DoEvents
Loop
'Définir les paramètres et lancer la création
'Set the parameters and start creating
Set MyJob = PDFQueue.NextJob
Call MyJob.SetProfileSetting(“OpenViewer”, “false”)
Call MyJob.ConvertTo(“C:\pdftest.pdf”)
'Attendre la fin
'Wait the end
Do Until MyJob.IsFinished
DoEvents
Loop
'Nettoyer
'Clean
Call PDFQueue.ReleaseCom
'Rétablir Printer sur l’ancienne imprimante
'Restore Printer to the old printer
For Each Prt In Printers
If Prt.DeviceName = OldPrinterName$ Then
Set Printer = Prt
Exit For
End If
Next
Command1.Enabled = True
Screen.MousePointer = vbNormal
End Sub
Private Sub Form_Load()
'Vérifier que PDFcreator est disponible
'Check PDFcreator available
If PDF.IsInstanceRunning Then
MsgBox “PDFcréator est occupé / PDFcreator is busy”
Command1.Enabled = False
End
End If
End Sub
bon pour moi c’est malheureux, mais je n’arrives pas à utiliser ce code dans excel, j’ai plein de bugs, notamment au niveau de prt et/ou Printer, d’ailleurs faut-il un s à Printer ?
OldPrinterName$ = Printer.DeviceName
'Obtenir le nom de l’imprimante PDF
'Get the name of the PDF printer
Set PDFdevices = PDF.GetPDFCreatorPrinters
PDFprinterName$ = PDFdevices.GetPrinterByIndex(0)
'Diriger Printer vers PDFcreator
'Direct Printer to PDFcreator
For Each Prt In Printers
If Prt.DeviceName = PDFprinterName$ Then
Set Printer = Prt
Exit For
End If
Next