IMPRIMER UN FICHIER HTML depuis une URL

jfuck Messages postés 59 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 31 mars 2009 - 19 janv. 2009 à 17:02
cs_fauve Messages postés 661 Date d'inscription vendredi 2 décembre 2005 Statut Membre Dernière intervention 23 mars 2011 - 20 janv. 2009 à 22:38
Hello,
voila je cherchais comment imprimer un fichier HTML à partir d'une URL, en cherchant sur le forum j'ai vu que beaucoup de gens avait le meme probleme...mais que peu de monde avait la réponse.
Je vous donne ma solution qui fonctionne, c'est un script qui vient de l'aide microsoft (c'est pas de moi) c'est efficace :

    Private Sub PrintHelpPage()
        ' Create a WebBrowser instance.
        Dim webBrowserForPrinting As New WebBrowser()
        ' Add an event handler that prints the document after it loads.
        AddHandler webBrowserForPrinting.DocumentCompleted, New  _
            WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocument)
        ' Set the Url property to load the document.
        webBrowserForPrinting.Url = New Uri("http://urlquivabien.html")
    End Sub

    Private Sub PrintDocument(ByVal sender As Object, _
        ByVal e As WebBrowserDocumentCompletedEventArgs)
        Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)
        ' Print the document now that it is fully loaded.
        webBrowserForPrinting.Print()
        MessageBox.Show("print")
        ' Dispose the WebBrowser now that the task is complete.
        webBrowserForPrinting.Dispose()
    End Sub

il suffit dappeler la fonction PrintHelpPage() (et de mettre la bonne url)

Voila j'epsère que ca vous aidera parce que moi j'ai bien galéré la dessus :).

bye

2 réponses

jfuck Messages postés 59 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 31 mars 2009
19 janv. 2009 à 17:51
si vous voulez imprimer un HTML en local il faut faire gaffe a changer les \ par des /.

Voili.

Enjoy
0
cs_fauve Messages postés 661 Date d'inscription vendredi 2 décembre 2005 Statut Membre Dernière intervention 23 mars 2011 8
20 janv. 2009 à 22:38
Salut,

Voici ton code que j'ai modifié un peu et qui fonctionne parfaitement :

Note : Je préfère celui-là car on peut sélectionner l'imprimante sur laquelle on veut imprimer, on peut la configurer, définir le nombre de copies, si on veut imprimer toutes les pages ou seulement quelques unes.





Private Sub
 PrintHelpPage(ByVal URL As String)
     ' Crée une instance d'un WebBrowser.
     Dim webBrowserForPrinting As New WebBrowser

     ' Ajoute un évènement qui appellera la fonction PrintDocument
     ' dés que le document sera entièrement chargé.
     AddHandler webBrowserForPrinting.DocumentCompleted, AddressOf PrintDocument

     ' Défini la page web qui doit être imprimée.
     webBrowserForPrinting.Url =   New  Uri(URL)
End Sub

Private Sub PrintDocument(ByVal sender As ObjectByVal e As WebBrowserDocumentCompletedEventArgs)

     sender.ShowPrintDialog()

End Sub





++

Fauve

<hr size ="2" width="100%" />
Pensez : Réponse Acceptée 
0
Rejoignez-nous