¿Cómo exportar una página web a PDF con solo pasar la URL de parámetro?4190

¿Cómo exportar una página web a PDF con solo pasar la URL de parámetro?

En este post veremos una tarea que es muy común en el desarrollo de sitios web, cómo exportar una página web  o HTML a PDF. El código es muy sencillo, solo se requiere de 4 líneas de código y listo. Al final del artículo puedes encontrar un video que te lleva paso a paso de cómo exportar una página web a PDF. Bueno pasamos al ejemplo

  1. Vas a Estrada WebGroup, HTML a PDF y seleccionas probar para generar tu API
  2. Creas un sitio web nuevo en Visual Studio
  3. Agregas la referencia del servicio web (http://produccion.developerji.com/ConvertirHtmlaPDF.asmx), como se muestra a continuación.
    convertir html a pdf en mi sitio web      convertir html a pdf con asp.net

    servicio web para convertir html a pdf
     
  4. Agregas una página al sitio y a esta le agregas un botón, que sería el que invoque la conversión de la página a PDF. El HTML queda de la siguiente manera:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="bntConvertPDF" runat="server" Text="Convertir a PDF" />
        </div>
        </form>
    </body>
    </html>
    
  5. Creas el código de servidor en el evento clic del botón y este quedaría de la siguiente manera:
     Protected Sub bntConvertPDF_Click(sender As Object, e As EventArgs) Handles bntConvertPDF.Click
            'Dirección fisica donde se guardara el pdf 
            Dim sFile As String = Server.MapPath("~/Cliente/pdfdemo.pdf")
            'Llamada al servicio web  
            Dim servicio As New ConvertPDF.ConvertirHtmlaPDFSoapClient
            'Descargo el PDF y se guarda en el servidor del cliente  
            'sFile: la dirección donde se guarda el PDF. En el servicio web servicio.ConvertirUrl_PDF,  
            ' se pasa por parametro la url a convertir, el nombre de usuario y el API que se genera cuando  
            'el usuario se registra en developerji.com 
            File.WriteAllBytes(sFile, servicio.ConvertirUrl_PDF("http://es.wikipedia.org", "jiestrada", "qF4OxILMDYXY6vQ"))
            'Por ultimo redirigimos a donde se encuentra el PDF
            Response.Redirect("~/Cliente/pdfdemo.pdf")
        End Sub
  6. Por ultimo abres el web.config  y en <binding debe quedar de la siguiente manera, no modifique el parámetro name, solo agrega lo que falte y listo, ejecuta tu sitio web.
     <binding name="ConvertirHtmlaPDFSoap" openTimeout="00:12:00" receiveTimeout="00:12:00" sendTimeout="00:12:00" maxBufferPoolSize="2097152" maxReceivedMessageSize="2097152"/>

Compartir

Comentarios (20)

  • Carlos Responder

    Muy bueno el post. Tengo dos dudas . Se puede implantar desde un entorno alojada en una intranet?. otra duda es si la api ley de la opcion probar tiene caducidad?

    Wednesday, November 23, 2016 12:16 PM
  • DHB Responder

    Pregunta puedo implementarlo en c#?? y cual seria el ejemplo

    Wednesday, November 23, 2016 12:50 PM
  • Stansbury Responder

    Heya! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no back up. Do you have any solutions to stop hackers?

    Wednesday, May 31, 2017 11:25 AM
  • Leeson Responder

    Awesome issues here. I am very happy to peer your post. Thanks so much and I'm taking a look ahead to contact you. Will you please drop me a mail?

    Sunday, June 4, 2017 10:02 PM
  • McWilliams Responder

    Hello! This is my 1st comment here so I just wanted to give a quick shot out and say I really enjoy reading your posts. Can you suggest any other blogs/websites/forums that go over the same topics? Thank you so much!

    Wednesday, June 14, 2017 8:41 AM
  • Torreggiani Responder

    Antibiótico bem como corticosteróide bom contra ?

    Tuesday, September 12, 2017 1:08 AM
  • Tuckett Responder

    Hello there! I know this iss somewhat off topic but I was wondering which blog platform are you using for this site? I'm getting tired of Wordpress because I've had issues with hackers and I'm looking at alternatives forr another platform. I would be greeat if yyou could point me in the direction of a good platform.

    Wednesday, September 13, 2017 1:51 PM
  • Fitzhardinge Responder

    Neede? to create you that litt?e observation so as t? give thank? over ag?in with y?ur remarjable opinions ?ou've featured h??e. It w?s ?ertainly wonderfully generous of people likke ?ou to give publicly ?xactly what a f?w people m?ght have made avail?ble as ?n e-book tto mak? ?ome money ?n their o?n, p?rticularly c?nsidering that you c?uld h?ve tried it if you e?er wanted. Tholse secrets iin ?ddition ?orked t? become a fantastic way to be ?ertain that ?omeone el?e have similar dreams juat ?? myy personal own to realize ? little mre with regard t? this p?oblem. I b?lieve there a?e many mo?e fun sessions up fr?nt fo? people ?ho discover yopur website. I ?ould like to express thanks to y?u for rescuing me from thi? particuloar trouble. ?ight ?fter exploring through the online w?rld and coming ac?oss techniques ?hich are not helpful, ? thought m? life was over. Beingg alivce ?ithout the solutions to the issues yo? ha?? solved ?y m?ans of your ent?re site iis a crucial ?ase, and the kind that could hav? negatively damaged my entire careerr ?f I h?d not ?om acroas thhe website. Youur understanding ?nd kindness in touching ?ll thing? w?s vital. I'm not sure wh?t I would ha?e done if I had not encountered s?ch a stuff like th?s. ? ?an now look forward to my future. ?hanks a l?t ?ery much f?r our professional and efective he?p. I won't hesitate t? endorse y?ur web ?age t? any person ?ho needs counseoling on this topic. I really w?nted to m?ke a bri?f remark to express gratitude to ?ou for the nice tactics yoou are giving on th?s website. My ?articularly ?ong internet search has at the end ?f thhe day be?n compensated with awesome ideas t? wrjte a?out with my company. I wou?? declare that w? website visitors are extremely fortunate too be in a notable community ?ith so many outstanding professionals with great tricks. I feel extremely happy to have s?en your website ?age and ?ook forward to plenty of mor? thrrilling moments reading here. Thank ?ou once again for everything. Thanks so much for providing individuals ?ith an extraordinarily spectacular possiblity t? rea? critical reviews f?om here. It can bee very seful ?nd aas we?l , packed with amusemeht fo? me and my office peers to visit y?ur site at m?nimum 3 t?me? in one week to s?e the l?test issues you h?ve. And indeed, we're usually contented ?ith all the attractive ?oints yo? give. Certain 3 ar?as inn thi? post a?e unquestionably the mo?t impressive ?e have ?ver ha?. I ?ould like to point ouut my love for you? generosity supporting women ?h? shoulkd hav? help w?th the niche. Your very own dedication to passing the message across ?as exceptioonally im?ortant and hav? specifically helped associates lioke me to attain their objectives. ?he u?eful publication implies ? ?ot to m? ?nd additionally to my mates. Re?ards; fr?m all of ?s. I in addtion to m? friends came analyzing the best things fr?m your web blog then aat once I had a terrible sujspicion ? h?? not expressed respeht to the web blog owner for them. ?ll the people ended up so warmed to learn all of them and have now ?ctually been tapping into those things. We appreciate ??u turning out to bbe s? thoughtful ?nd also fo? choosing ce?tain nice subject areas millions of indviduals ?re really desiros to learn about. My very own honest apologies f?r not ?aying thanks to sooner. I'm ?lso writing t? let you understand what a superb discovery my girl enjoyed reading ?our webblog. She discovered ?o many issues, which inclu?e what it's l?ke to h??e an amazing giving style t? ha?e men ?nd women eaxily fullyy grasp choseen multifaceted topics. ??u undoubtedly did mor? than our own expectations. Thank yoou for providing those invaluable, healthy, informative ?nd also unique guidance ?n the topic to Mary. ? precisely had t? thank you very much again. I do not kno? tthe things I co?ld p?ssibly h??e handled wothout these thoughts pro?ided by you oover my concern. ?h?s was the difficult crisis iin m? position, butt being ?ble to vi?w your specialized approach y?u hanndled that t??k me to cry fo? delight. N?w i'm thankful f?r yourr ?ork and thus beieve ?ou are aware of ? ?reat job y?u were providing teaching other individduals ?sing your blog post. ? am cert?in you ha?? nevrr come across aall of us. My husband and i fe?t so thankful wh?n Raymond co?ld do hi? web research ?ith the precious recommendations he was given out ?f your blog. It i? now and again perplexing just t?? pos?ibly be givin freely techniques that m?ny the others could ha?e been m?king money from. S? w? discover we have

    Wednesday, September 13, 2017 11:01 PM
  • Cushing Responder

    Tremendous issues here. I'm very happy to peer your article. Thank you a lot and I'm having a look forward to contact you. Will you please drop me a e-mail?

    Tuesday, September 19, 2017 4:42 PM
  • Sherlock Responder

    It's nearly impossible to find educated people for this subject, however, you sound like you know what you're talking about! Thanks

    Sunday, October 8, 2017 12:52 PM
  • Mead Responder

    lick my pussy she said to me. I was with a partner who said she does not always cum with guys when swinging.

    Monday, October 9, 2017 1:29 AM
  • Burg Responder

    34 yr old Judge Kristopher from Saint-Jovite, loves to spend time languages, Agen Judi Togel and dumpster diving. Recently had a family visit to Monastery of Batalha.

    Monday, October 16, 2017 8:03 PM
  • Cloutier Responder

    I couldn't refrain from commenting. Well written!

    Thursday, October 19, 2017 4:17 PM
  • Horning Responder

    Thanks for sharing ??ur ideas. I'd ?lso like to sayy that video games have ?e?n ever befolre evolving. Modern tools ?nd revolutions have helped create practical and interactive games. ?hese entertainment games ?ere not re?lly sensible when th? real concept wa? bejng ?sed. ?ust like other kinds ?f know-how, vireo games ?ay to? have had to deelop ?y w?y ?f many ages. Thi? i? testimony t?wards f?st development of video games. I ha?e observed in the w?rld the ?resent mom?nt, video games ?ould ?e thee latest popularity w?th kids ?f ?ll ages. Periodically ?t ma? be extremely hard t? drag ?our family away f?om the activities. If y?u want the very ?est of both worlds, there ?re v?rious educational gaming activities f?r kids. Gr?at post. One mpre issue i? video games are typically serious aas the name indic?ted with th? major focus ?n finding out ?ather than leisure. ?lthough, the?e i? an entertainment feature t? ?eep the kids engaged, each game will ?ikely bee designed to ?ork towards a specific expertise ?r area, such as mathemaatics or scientific research. Thanks for your post. ? have discovered s?me s?gnificant things th?ough you? site post. One other thing I woulkd l?ke to express ?s tat thyere ?re various games inn the marketplace designed ?n prticular f?r toddler agge ?ittle ones. They consist ?f pattern recognition, colors, pets, ?nd styles. ?hese typically focfus ?n familiarization ?s opposed t? memorization. ?his keep? children engaged without sensing li?e they are studying. Thanks A furthe? issue is that video gaming has b?c?me ?ne ?f the all-time gre?test forms ?f fun ffor people off vario?s age gro?ps. Kids h?ve fun ?ith video games, ?lus adukts ??, too. The p?rticular XBox 360 is probably the favforite viddeo games systems f?r people who love to h??? hundreds ?f activities ?vailable t? them, ?lus who li?e t? learn live ?ith others all over the ?orld. Th?nks for sharing your notions.

    Friday, October 20, 2017 4:11 PM
  • Nance Responder

    It is highly recommended that content of this web page should be compressed using GZIP, as it can save up to 81.3 kB or 79% of the original size.

    Sunday, October 22, 2017 7:27 AM
  • Reeve Responder

    Wonderful site you have here but I was wondering if you knew of any user discussion forums that cover the same topics talked about here? I'd really like to be a part of community where I can get comments from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Thank you!

    Wednesday, October 25, 2017 1:59 PM
  • Forsyth Responder

    He hasn't done anything big in his hacking life.

    Thursday, November 9, 2017 7:00 AM
  • Clopton Responder

    Quality articles is the crucial to attract the visitors to visit the web site, that's what this web site is providing.

    Friday, November 24, 2017 6:32 PM
  • Lima Responder

    MiniXtend HD Cable, our highest-density micro cable featuring Corning SMF-28® Ultra 200 fiber and delivering fiber counts up to 288 fibers.

    Tuesday, December 5, 2017 10:47 AM
  • Mackersey Responder

    Hi there to ?very b?dy, it's my first go to see of this website; this website includes amazing ?nd actually good material for reader?.

    Wednesday, December 6, 2017 11:34 PM

Animate deja un comentario!!!

Eres un humano?

Últimos Tweets

Contáctanos

  • Dirección: Plutarco Elias Calles 243, Granjas México, Iztacalco, DF.

  • Teléfono:55-2712-3820 o 55-4164-9484

  • Email: info@developerji.com