Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
¿Cómo pasar CSS href a CSS en línea en el script de la aplicación?

ACTUALIZAR:

Necesito guardar una página web HTML como pdf en mi Google Drive. Estoy usando el script de la aplicación.
Sin embargo, el PDF se representa de manera diferente a la página HTLM. Necesito que el PDF sea el mismo que el HTML. DE LA INVESTIGACIÓN DESCUBRÍ QUE EL CSS EXTERNO NO SE REPRESENTA CORRECTAMENTE, SOLO CSS EN LÍNEA.

Tengo una página HTML y necesito transformar el CSS externo en CSS en línea. Necesito hacer esto usando un script de aplicación.

¿Es posible?

EDITAR: MÁS DETALLES: AQUÍ ESTÁ MI FUNCIÓN EN APPSCRIPT Y MI ENCABEZADO HTML CSS

 function downloadFile() { var fileURL = "https://www..... var folder = "primes" var fileName = ""; var fileSize = ""; var response = UrlFetchApp.fetch(fileURL, { headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() }, }) var htmlBody = response.getContentText(); var rc = response.getResponseCode(); if (rc == 200) { var blob = Utilities.newBlob(htmlBody, MimeType.HTML).getAs('application/pdf').setName('Nota.pdf'); var folder = DriveApp.getFolderById("1gBA8YCs3PH7v7CNl3nlsjNqYzhOxhjYa"); if(folder != null){ var file = folder.createFile(blob); fileName = file.getName() fileSize = file.getSize() } } var fileInfo = {'rc':rc,"filename": fileName, "fileSize":fileSize} Logger.log(fileInfo) }
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Bling - </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="https://www.bling.com.br/libs/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript" src="https://www.bling.com.br/libs/utils-1632934481.js"></script> <link rel="stylesheet" type="text/css" href="https://www.bling.com.br/styles/danfe.css" /> <style> table.grid tr td{ /*padding:2px;*/

La salida que obtengo no se representa correctamente

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente reemplace el css externo con el valor real con etiquetas de style rellenadas.

Guion:

 var htmlBody = response.getContentText(); // replace external css with the actual css, padded with style tags var externalCss = `<link rel="stylesheet" type="text/css" href="https://www.bling.com.br/styles/danfe.css" />`; htmlBody = htmlBody.replace(externalCss, `<style>${UrlFetchApp.fetch('https://www.bling.com.br/styles/danfe.css').getContentText()}</style>`) var rc = response.getResponseCode();

Si esto no funciona debido a captcha. (No estoy seguro de si captcha le causará algunos problemas al buscar). Copie el css real (rellénelo con etiquetas), guárdelo en un archivo e inclúyalo en su cadena antes de convertirlo en blob usando:

 HtmlService.createHtmlOutputFromFile(filename).getContent()

Producción:

producción

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!