IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

Problème d'impression d'un fichier pdf


Sujet :

VB 6 et antérieur

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Février 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Février 2011
    Messages : 4
    Par défaut Problème d'impression d'un fichier pdf
    Bonjour,
    Je vous explique mon problème, je travaille pour une entreprise et je dois modifier une application déjà créée en vb6 qui permet, grâce à l'outil pdfcreator, d'imprimer un document en pdf. Jusqu'ici tout va bien mais je dois maintenant changer le format du papier. C'est-à-dire, le fichier est enregistré au format A4 dans mon dossier et il doit être imprimé au format A3. La fonction fonctionne correctement, elle utilise bien l'imprimante virtuelle mais après de nombreux jours de recherche je n'ai toujours pas trouvé de solution pour changer le format avant impression. J'ai essayé l'objet Printer.PaperSize à plusieurs reprises mais sans résultat cela ne fonctionne pas et je désespère. Si quelqu'un est dans la capacité de m'aider j'en serais très heureuse!

    Merci d'avance

    Je travaille sous Windows XP avec Visual Basic 6

  2. #2
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 132
    Par défaut
    Bienvenue sur DVP
    Printer.Zoom ? éventuellement

    Édit:
    Avec un peu plus de temps
    Si l'image = A4 donc 21x29.7 cm
    pour une sortie impression A3 = VbPRPSA3 donc 29.7 x 42 cm
    Ce qui pourrait donner
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Printer.zoom = 141 '% = 29.6 x 41.8 cm
    Printer.PaperSize = VbPRPSA3 ' 29.7 x 42 cm 
    Printer.Orientation = VbPRORPortrait ' 29.7 x 42 cm
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Février 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Février 2011
    Messages : 4
    Par défaut
    Bonjour,

    cette solution ne fonctionne pas non plus. Le fichier pdf est toujour enregistré au format 21 X 29.7 après l'exécution... Peut être que le code n'est pas placé au bon endroit? Mon bouton imprime PDF fonctionne comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
     
    Private Sub Command1_Click()
        Dim file_name As String
        file_name = App.Path
        If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
        file_name = file_name & "test.pdf"
     
        Dim PDFArray As Variant
        ReDim PDFArray(0 To 0)
        PDFArray(0) = file_name
        PrintPDFs PDFArray
    End Sub
    Ensuite il y a donc le code de la procédure PDFArray appelé précedemment. Le bout de code que vous m'avez donné doit être mis dans la partie ci-dessus ou dans la procédure ?

    Merci

  4. #4
    Membre émérite
    Inscrit en
    Décembre 2007
    Messages
    512
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 512
    Par défaut
    Bonjour,

    Je suppose, mais je n'en suis pas certain, qu'étant des paramètres d'impression, ils doivent être mis en début de la procédure
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Private Sub Command1_Click()
    Mais retiens quand même ceci


    De la MSDN

    Note : L'effet des propriétés de l'objet Printer dépend du pilote fourni par le fabricant de l'imprimante. Certaines propriétés peuvent n'avoir aucune incidence, et des valeurs différentes peuvent avoir le même effet. L'affectation à une propriété d'une valeur en dehors de la plage des valeurs acceptées peut ou non provoquer une erreur. Pour plus d'informations, reportez-vous à la documentation du fabricant pour le pilote considéré.
    Quel est le code des autres procédures?

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Février 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Février 2011
    Messages : 4
    Par défaut
    Le code des autres procédures est celui-ci (a priori récupéré sur le net par mon entreprise) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    Private Sub PrintPDFs(PDFArray As Variant)
    '' Accepts one dimensional array PrintPDFs containing paths to .PDF files to be printed,
    '' then silently prints them using DDE. Acrobat Reader does not support OLE, and silent
    '' printing through the pdf.oxc has some issues in v5.1 and higher
    ''
    '' pdf.ocx is an unsupported, non-developement tool that is subject to change in functionality.
    '' Under Acrobat 5.1 and higher, a warning dialog is displayed each time printAllFit() is called.
    '' If "Do not ask me again" is selected, printing from script will *fail* unless the user opens
    '' acrobat reader, goes to tools>options and "Resets all warnings".
    '' "Do not ask me again" is stored in:
    ''   HKCU\Software\Adobe\Acrobat Reader\5.0\AVAlert\cCheckbox\cEWH\iWarnScriptPrintAll
    ''   HKCU\Software\Adobe\Acrobat Reader\6.0\AVAlert\cCheckbox\cEWH\iWarnScriptPrintAll
    ''
    '' This sub requires:
    '' - PDFArray starts at row 0, not row 1
    '' - TextBox txtAcrobatDDE
    '' - declaration of API function FindExecutable
    ''
    '' ** WILL NOT WORK FROM AN ACTIVEX DLL **
    ''
     
    On Error GoTo ErrHandler
     
      Dim Error282Count As Integer  '' Count of "Can't open DDE channel" errors
      Dim AcroDDEFailed As Boolean  '' Set to true if a DDE connection cannot be established
      Dim sPDFPath As String        '' Path to a PDF file
      Dim sCmd As String            '' DDE command
      Dim lStatus As Long           '' response from ShellExecute command
      Dim n As Integer              '' for iterating
      Const Max282Errors = 6        '' Number of times we will ignore "Can't open DDE channel" errors
                                    '' before accepting the fact that Acrobat is not started. We need
                                    '' to test more than once, because it might just be busy loading
      Dim sAcroPath As String       '' Path to acrobat, determined by FindExecutable
      Dim bCloseAcrobat As Boolean  '' If we open acrobat, we will close it when we are done
     
      '' If acrobat is already running (and hidden), shelling it will cause it to be shown.
      '' We do not want that. So try a DDE connect, which will fail if acrobat is not running
      '' I have looked at other API means of testing this, but it may be running as a process (no window)
      '' and there does not seem to be many graceful ways of testing for this.
      Error282Count = Max282Errors      '' we only need to try once to see if it is already running.
      AcroDDEFailed = False             '' ErrHandler will set to true if Acro is not running
      txtAcrobatDDE.LinkMode = 0        '' Close any current DDE Link
      txtAcrobatDDE.LinkTopic = "acroview|control"    '' Acrobat's DDE Application|Topic
      txtAcrobatDDE.LinkMode = 2        '' Try to establish 'Manual' DDE Link. This will fail
                                        '' if Acrobat is not ready (or in this case, not running)
     
      If AcroDDEFailed = True Then
        '' We could not set our linkmode, so Acro is not running. Find it and launch it
        sPDFPath = PDFArray(0)  '' grab the first pdf path. We assume this file exists
     
        '' Use the FindExecutable API function to grab the path to our PDF handler.
        '' This should be Acrobat Reader or Acrobat, but it might be something else.
        '' When we try to DDE link to it, non-acrobat will error out. This is ok.
        sAcroPath = String(128, 32)
        lStatus = FindExecutable(sPDFPath, vbNullString, sAcroPath)
        If lStatus <= 32 Then
          MsgBox "Acrobat could not be found on this computer. Printing cancelled", vbCritical, "Problem"
          Exit Sub
        End If
     
        '' Launch the PDF handler
        lStatus = Shell(sAcroPath, vbHide)
        If (lStatus >= 0) And (lStatus <= 32) Then
          MsgBox "An error occured launching Acrobat. Printing cancelled", vbCritical, "Problem"
          Exit Sub
        End If
        bCloseAcrobat = True  '' We will try to close Acrobat when we are done
      End If
     
      PauseFor 2  '' Lets take a break here to let Acrobat finish loading
     
      Error282Count = 0       '' This time, we will allow all acceptable tries, as
      AcroDDEFailed = False   '' Acrobat is running, but may be busy loading its modules
      txtAcrobatDDE.LinkMode = 0
      txtAcrobatDDE.LinkTopic = "acroview|control"
      txtAcrobatDDE.LinkTimeout = 2500 ' 3 minute timeout delay. Should be moer than enough
      txtAcrobatDDE.LinkMode = 2
     
      If AcroDDEFailed = True Then
        MsgBox "An error occured connecting to Acrobat. Printing cancelled", vbCritical, "Problem"
        Exit Sub
      End If
     
      '' Send the PDF's to the printer. In my testing, this was very immediate
      For n = 0 To UBound(PDFArray)
        '' We need to put the long filenames in quotes. Again, we assume these file exist
        sPDFPath = PDFArray(n)
        sCmd = "[FilePrintSilent(" & Chr(34) & sPDFPath & Chr(34) & ")]"
        txtAcrobatDDE.LinkExecute sCmd
      Next
     
      If bCloseAcrobat = True Then
        '' [AppExit()] causes memory errors with v6.0 and 6.1, so avoid closing these versions
        If InStr(sAcroPath, "6.0") = 0 Then
          sCmd = "[AppExit()]"
          txtAcrobatDDE.LinkExecute sCmd
        End If
      End If
     
      '' Close the DDE Connection
      txtAcrobatDDE.LinkMode = 0
     
    Exit Sub
     
    ErrHandler:
      If Err.Number = 282 Then '' Can't open DDE channel
        '' This error may happen because Acro is not fully loaded.
        '' Give it Max282Errors attempts before returning AcroDDEFailed = True
        Error282Count = Error282Count + 1
        If Error282Count <= Max282Errors Then
          PauseFor 3
          Resume
        Else
          AcroDDEFailed = True
          Resume Next
        End If
      End If
     
      MsgBox "Error in PrintPDFs sub of " & Me.Name & " form. Error# " & Err.Number & " " & Err.Description & "."
    End Sub
     
    Private Sub PauseFor(iSeconds As Integer)
    '' Pauses for iSecond seconds
      Dim sngTimer As Single
     
      sngTimer = Timer
      While Timer - sngTimer < iSeconds
        DoEvents
      Wend
     
    End Sub

    Surement que les propriétés ne fonctionnent pas sur cette imprimante mais comme c'est une imprimante virtuelle je pensais que ça ne poserait pas de problème. Mais je ne vois pas d'autres solutions...

    Merci en tout cas

Discussions similaires

  1. Impression dans un fichier PDF
    Par Souleyre dans le forum VB 6 et antérieur
    Réponses: 10
    Dernier message: 08/05/2008, 23h06
  2. problèmes d'impression de document avec pdf creator
    Par sergentgarcia dans le forum Word
    Réponses: 5
    Dernier message: 27/11/2007, 14h23
  3. impression d'un fichier pdf
    Par vince2005 dans le forum Langage
    Réponses: 3
    Dernier message: 26/09/2007, 00h16
  4. Impression d'un fichier PDF
    Par Orionmel dans le forum VB.NET
    Réponses: 3
    Dernier message: 28/04/2007, 22h51
  5. impression d'un fichier PDF
    Par rogger dans le forum Access
    Réponses: 6
    Dernier message: 01/01/2006, 17h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo