Forum How do I...?

Author style sheets <link rel="stylesheet" ... /> not getting applied

satyavati
Hi ,

I am trying to convert html file using p.convert(InputStream, ByteArrayOutputStream) in java

I am converting html file to InputStream and then writing the ByteArrayOutputStream as pdf.

The <link rel="stylesheet" ... /> styles of html are not getting applied on the generated pdf.

I do not want to use addStyleSheet() of princexml for internal stylesheet applied in html, because these html files are dynamically passed.

Also the images are not getting applied in the resulting pdf.


How can I apply css and images
mikeday
If there are relative paths to the images and style sheets, then you will need to specify a base URL for the document for them to be resolved against. You can do this in the document, or by calling setBaseURL.

Alternatively, check the Prince output log to see if there are any warning messages about being unable to load the referenced resources.
satyavati
Thanks Mikeday :)

It worked with setBaseUrl()
satyavati
But for me the requirement is to convert the ByteArrayInputStream to pdf. the BaseUrl of html will not be known to me.

The Sample project worked as I passed the html file path as base url.
But in actual Project I am going to get the Byte[]. It is getting converted to pdf but css and images not set.

Is there any other method to set css and images to resulting pdf.

mikeday
You must know where the images are, and what kind of paths the document is using. If the document has an image like "../../images/logo.jpg" then what should that path be resolved to?
satyavati
:)
Thanks Mike for your support

For external urls like http://127.0.0.1/images/logo.jpg it works, I didn't even needed to set baseUrl()
Pdf is getting generated all correct
mikeday
Right, the base URL is only required for relative URLs, not absolute URLs.
satyavati
Hi Mikeday,

Pdf generated from Linux version princexml is slightly different than in windows version princexml.
Please see the attached file, the texts are getting overlapped in resulting pdf.

Is there any extra setting needed for linux princexml
I used prince-9.0-5.centos60.x86_64.rpm
Is css not getting applied properly in this version of princexml
  1. Linux_princexml_generated.png77.5 kB
    Overlapping texts
mikeday
Are the fonts the same? Are the style sheets being applied? Are there any errors or warnings in the output log?
satyavati
I have applied same css file which I used for windows
Same code I executed in windows and linux

I have used @page css for shrinking the result pdf @page { prince-shrink-to-fit: auto; }
Is it because of this but then why not on windows

I am not getting any warning or error in the log

Log traces in Linux machine:

Thu Jul 3 08:37:55 2014: -- begin
Thu Jul 3 08:37:55 2014: Loading document...
Thu Jul 3 08:37:55 2014: Running scripts...
Thu Jul 3 08:37:55 2014: Applying style sheets...
Thu Jul 3 08:37:55 2014: Preparing document...
Thu Jul 3 08:37:55 2014: Converting document...
Thu Jul 3 08:37:55 2014: finished: success
Thu Jul 3 08:37:55 2014: -- end
Thu Jul 3 08:37:55 2014: -- begin
Thu Jul 3 08:37:55 2014: Loading document...
Thu Jul 3 08:37:55 2014: Running scripts...
Thu Jul 3 08:37:55 2014: Applying style sheets...
Thu Jul 3 08:37:55 2014: Preparing document...
Thu Jul 3 08:37:55 2014: Converting document...
Thu Jul 3 08:37:55 2014: finished: success
Thu Jul 3 08:37:55 2014: -- end
mikeday
Do the PDF documents use the same fonts? You can check under Document Properties > Fonts in Acrobat.
satyavati
Yes, fonts are different

In Windows pfd it is Arial

and in Linux pdf it is DejaVuSans

why is this changing, is Linux machine do not have Arial font
mikeday
No, not by default. You can install it on CentOS 6 with these two commands:
yum install curl cabextract xorg-x11-font-utils fontconfig

rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
satyavati
Thanks Mikeday,

:) it worked.
satyavati
Hi Mikeday,

The page breaks are getting applied on the table rows
Here in example the image remain at the first page with overlapping border and the text goes down.
I have use @page { prince-shrink-to-fit: auto; } css
If I don't apply page css then half content is cut. That do not fit into the page.

Is there way to apply proper A4 size css and all the content fits into it.
  1. page breaks on the rows.PNG4.7 kB
    page breaks getting appled on the rows
mikeday
Do you have some floats or absolute positioning? These are tricky to break across pages.
satyavati
It worked with A4 page css