Forum How do I...?

import css from external file

mehrshadms
hi
i download html file and after using price dll (c#) i created pdf but i want to import css from external file such as https://d1jztyon2mtydf.cloudfront.net/static/ltr/en/css/compiled/souq_main.2014120814.min.css

what i must to do ?

thx
mikeday
You can refer to it from your document, using the <style> element with @import rule, or the <link> element, or you can apply it from C# with the AddStyleSheet method.
mehrshadms
do you have example ?
mikeday
In the document:
<link rel="stylesheet" type="text/css" href="https://d1jztyon2mtydf.cloudfront.net/static/ltr/en/css/compiled/souq_main.2014120814.min.css">

In the code:
prince.AddStyleSheet("https://d1jztyon2mtydf.cloudfront.net/static/ltr/en/css/compiled/souq_main.2014120814.min.css");
prince.Convert(...);
mehrshadms
thx a lot but doesn't work
mikeday
Are you getting any errors or warnings in the Prince output log?
mehrshadms
Wed Jan 7 10:46:30 2015: ---- begin
Wed Jan 7 10:46:30 2015: Loading document...
Wed Jan 7 10:46:30 2015: Running scripts...
Wed Jan 7 10:46:30 2015: Applying style sheets...
Wed Jan 7 10:46:30 2015: C:\docs\css\stylesheet-1.css: warning: failed to parse all CSS rules
Wed Jan 7 10:46:30 2015: Preparing document...
Wed Jan 7 10:46:31 2015: https://ssl.souq.com/static/ltr/en/images/header/logo_hitmeister.png: warning: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm
Wed Jan 7 10:46:32 2015: https://ssl.souq.com/static/ltr/en/images/icons/cash_on_delivery.jpg: warning: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm
Wed Jan 7 10:46:32 2015: Converting document...
Wed Jan 7 10:46:32 2015: finished: success
Wed Jan 7 10:46:32 2015: ---- end
Wed Jan 7 10:46:33 2015: ---- begin
Wed Jan 7 10:46:33 2015: Loading document...
Wed Jan 7 10:46:33 2015: Running scripts...
Wed Jan 7 10:46:33 2015: Applying style sheets...
Wed Jan 7 10:46:33 2015: C:\docs\css\stylesheet-1.css: warning: failed to parse all CSS rules
Wed Jan 7 10:46:33 2015: Preparing document...
Wed Jan 7 10:46:36 2015: Converting document...
Wed Jan 7 10:46:36 2015: finished: success
Wed Jan 7 10:46:36 2015: ---- end
Wed Jan 7 10:49:11 2015: ---- begin
Wed Jan 7 10:49:11 2015: Loading document...
Wed Jan 7 10:49:11 2015: Running scripts...
Wed Jan 7 10:49:11 2015: Applying style sheets...
Wed Jan 7 10:49:14 2015: internal error: string.det_base_string_to_int/2: conversion failed
Wed Jan 7 10:49:14 2015: ---- end
Wed Jan 7 10:49:15 2015: ---- begin
Wed Jan 7 10:49:15 2015: Loading document...
Wed Jan 7 10:49:15 2015: Running scripts...
Wed Jan 7 10:49:15 2015: Applying style sheets...
Wed Jan 7 10:49:15 2015: C:\docs\css\stylesheet-1.css: warning: failed to parse all CSS rules
Wed Jan 7 10:49:15 2015: Preparing document...
Wed Jan 7 10:49:18 2015: Converting document...
Wed Jan 7 10:49:18 2015: finished: success
Wed Jan 7 10:49:18 2015: ---- end
Wed Jan 7 11:12:07 2015: ---- begin
Wed Jan 7 11:12:07 2015: Loading document...
Wed Jan 7 11:12:07 2015: Running scripts...
Wed Jan 7 11:12:07 2015: Applying style sheets...
Wed Jan 7 11:12:07 2015: C:\docs\css\stylesheet-1.css: warning: failed to parse all CSS rules
Wed Jan 7 11:12:07 2015: Preparing document...
Wed Jan 7 11:12:08 2015: https://ssl.souq.com/static/ltr/en/images/header/logo_hitmeister.png: warning: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm
Wed Jan 7 11:12:09 2015: https://ssl.souq.com/static/ltr/en/images/icons/cash_on_delivery.jpg: warning: error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm
Wed Jan 7 11:12:09 2015: Converting document...
Wed Jan 7 11:12:09 2015: finished: success
Wed Jan 7 11:12:09 2015: ---- end
Wed Jan 7 11:12:10 2015: ---- begin
Wed Jan 7 11:12:10 2015: Loading document...
Wed Jan 7 11:12:10 2015: Running scripts...
Wed Jan 7 11:12:10 2015: Applying style sheets...
Wed Jan 7 11:12:10 2015: C:\docs\css\stylesheet-1.css: warning: failed to parse all CSS rules
Wed Jan 7 11:12:10 2015: Preparing document...
Wed Jan 7 11:12:13 2015: Converting document...
Wed Jan 7 11:12:13 2015: finished: success
Wed Jan 7 11:12:13 2015: ---- end
Wed Jan 7 12:38:35 2015: ---- begin
Wed Jan 7 12:38:35 2015: Loading document...
Wed Jan 7 12:38:35 2015: Running scripts...
Wed Jan 7 12:38:35 2015: Applying style sheets...
Wed Jan 7 12:38:38 2015: internal error: string.det_base_string_to_int/2: conversion failed
Wed Jan 7 12:38:38 2015: ---- end
Wed Jan 7 12:38:39 2015: ---- begin
Wed Jan 7 12:38:39 2015: Loading document...
Wed Jan 7 12:38:39 2015: Running scripts...
Wed Jan 7 12:38:39 2015: Applying style sheets...
Wed Jan 7 12:38:41 2015: internal error: string.det_base_string_to_int/2: conversion failed
Wed Jan 7 12:38:41 2015: ---- end
mikeday
Yikes, would like to resolve that internal error. Can you attach the style sheet, or email it to me? (mikeday@yeslogic.com)

The error does not seem to be coming from the CSS URL you mentioned earlier; are there other style sheets applied to the document, or inline <style> rules?
mehrshadms
was attached
  1. stylesheet-1.css0.1 kB
mikeday
Okay that won't work because it has a <link> element in the CSS; the link element belongs in the HTML document. In CSS you can do this to import another style sheet:
@import url("...");
mikeday
I'm curious about the "internal error" that pops up in the logs though. Can you make that happen again?
mehrshadms
in bellow directory in my pc
docs/css/stylesheet-1.css
i write
@import url("https://d1jztyon2mtydf.cloudfront.net/static/ltr/en/css/compiled/souq_main.2014120814.min.css");

but pdf doenst created (sry i can speak en very well)
mikeday
Any new errors in the output log?
mehrshadms
log was attached
  1. log.txt5.3 kB
mehrshadms
how long i can use prince dll in my program ?
mikeday
Thanks, there is an error in the log, but it is difficult to see what is causing it. Are there other style sheets included in your document? (It would help if you can attach the HTML document here, or email it).

How long you can use Prince, is that a licensing question or a technical question? If you purchase a license, they do not expire, so you can keep using it forever, but may wish to purchase upgrades or support later.
mehrshadms
its not free ?
mikeday
Non-commercial license is free, for non-commercial purposes. It adds a small "P" annotation in the corner of PDF files.
mehrshadms
my html file was attached
i so thank you for your support
  1. test1.html6.2 kB
mikeday
Thank you, I can reproduce the same problem here now. I will investigate the issue.
mehrshadms
thx i waiting
mikeday
The problem is caused by setting the z-index property to very large numbers in the CSS, like this:
z-index:99999999999

If you can replace this with a smaller number like 99, 999, 9999, etc. then it should be fine.
mehrshadms
if i download css file and replace into stylesheet-1.css then replace 999999999 to 99
is that working ?
mikeday
Yes that should fix the problem. There are a few places in the style sheet with these big numbers though, so you may need to search for "z-index" or "9999".
mehrshadms
ye thats fixed i so thank you
mikeday
We have now released Prince 10 which fixes the issue caused by very large numbers in CSS. Thanks for your help with this. :)