Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass long HTML strings to Chrome #12

Closed
westy92 opened this issue Jun 20, 2017 · 6 comments
Closed

Pass long HTML strings to Chrome #12

westy92 opened this issue Jun 20, 2017 · 6 comments

Comments

@westy92
Copy link
Owner

westy92 commented Jun 20, 2017

Most likely, 'data:text/html,' + html has a length limitation. Instead of passing a string of HTML to Chrome using a data URL, use a temporary file.

@westy92 westy92 added this to the v0.2.0 milestone Jun 20, 2017
@westy92 westy92 added the bug label Jun 20, 2017
@popsail
Copy link

popsail commented Jun 29, 2017

What if it's a remote chrome instance, though?
How would you pass the temporary file?

@westy92
Copy link
Owner Author

westy92 commented Jun 29, 2017

This would only work for locally-running Chrome instances.

@westy92
Copy link
Owner Author

westy92 commented Jun 29, 2017

This is likely a better solution: cyrus-and/chrome-remote-interface#95 (comment).

@westy92 westy92 changed the title Pass HTML strings to Chrome via a temporary file Pass long HTML strings to Chrome Jun 29, 2017
@westy92
Copy link
Owner Author

westy92 commented Jul 14, 2017

I believe this is blocked by ChromeDevTools/devtools-protocol#13.

@westy92 westy92 modified the milestones: v0.3.0, v0.2.0 Jul 14, 2017
@westy92
Copy link
Owner Author

westy92 commented Nov 17, 2017

This does not appear to be an issue any longer. I was able to generate a 365 page PDF with the code below that used an HTML string composed of over over 2 million characters.

it('should generate from a lengthy HTML string', async () => {
  const options: HtmlPdf.CreateOptions = {
    port,
  };
  const filler = `
    <p>
      Bacon ipsum dolor amet fatback pastrami tongue short ribs jowl jerky meatloaf chuck pancetta pork pork loin tail cow brisket. Frankfurter chuck prosciutto tongue venison beef ribs filet mignon brisket turkey chicken hamburger ground round porchetta leberkas short ribs. Jerky doner ball tip, beef strip steak pancetta venison shankle boudin brisket. Rump leberkas biltong bresaola. Tongue burgdoggen strip steak beef ribs salami doner. Hamburger beef ribs shank, ribeye tail chuck pig turkey short loin shankle boudin cow. Cupim spare ribs turducken pastrami frankfurter jowl.
      Shankle beef corned beef porchetta. Capicola kevin pork chop short ribs, ham hock pancetta shankle. Buffalo kielbasa turducken beef ribs tongue. Filet mignon kevin pork loin pastrami meatloaf. Alcatra sausage brisket burgdoggen flank filet mignon biltong short ribs pork chop jowl pork venison rump sirloin beef ribs.
      Rump flank hamburger shank meatball alcatra ground round doner ham boudin. Beef pig pork chop bacon short loin ball tip rump, ground round frankfurter pork belly strip steak chicken landjaeger picanha. Ham frankfurter ball tip drumstick sausage doner salami. Venison alcatra kielbasa ribeye salami pork belly rump fatback cupim buffalo jerky pig bresaola. Picanha biltong brisket prosciutto hamburger kielbasa. Hamburger buffalo chuck spare ribs.
      Strip steak short ribs bacon, hamburger drumstick tenderloin filet mignon ball tip. Jowl biltong tenderloin doner capicola, porchetta boudin pork loin prosciutto pastrami shankle pork belly. Short ribs t-bone capicola tail tri-tip turkey chicken pig fatback ham brisket bresaola. Jerky sausage tail, venison spare ribs prosciutto meatloaf beef ribs swine shoulder tri-tip sirloin salami cupim.
      Capicola drumstick kielbasa pork jerky. Brisket chicken kielbasa salami flank short ribs, venison prosciutto swine bresaola ham spare ribs buffalo. Andouille chicken doner ball tip alcatra short loin burgdoggen. Capicola picanha strip steak meatball t-bone, bresaola cow ground round pastrami tenderloin tongue buffalo cupim prosciutto. Tongue spare ribs leberkas, pork pig jerky pancetta turducken kevin t-bone kielbasa boudin ribeye pork loin shankle. Tail drumstick turducken chuck shankle shank t-bone. Cow pastrami salami corned beef cupim alcatra, ham brisket sirloin meatloaf shankle.
    </p>
  `;
  const html = `
    <html>
      <head>
      </head>
      <body>
        ${filler.repeat(850)}
        END
      </body>
    </html>
  `;
  console.log(html.length);
  const result = await HtmlPdf.create(html, options);
  await result.toFile('long.pdf');
});

Please add a comment if you see this issue surface again.

@westy92 westy92 closed this as completed Nov 17, 2017
@GendelfLugansk
Copy link
Contributor

GendelfLugansk commented Feb 21, 2018

Hello. URL length is limited to 2097152 characters. This is an error chromium throws in console for very big html which contains few base64-encoded images: Refusing to load URL as it exceeds 2097152 characters. Unfortunately I can't share html that I'm trying to convert (those images contain some sensitive data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants