Forum How do I...?

want information on prince

preksha
hi

i am an ammeteur , want to convert html with css to pdf . I am also intrested in buying license for the same . but would like to get some information about prince .
1. i tried using prince as a standalone tool , it rendered my html fine , but using its API through my java code , my external CSS file wasnt rendered .
2. If my html code has hardcoded alignments and page size , will prince shrink the html to my pdf page ? which i donot see working

Thanks in advance
mikeday
For your first issue, how are you passing the HTML to Prince? If you are passing it via the Java interface as a string, and it contains relative paths, you will need to call setBaseURL() before convert(). For the second issue, you can enable shrink-to-fit like this:
@page {
    prince-shrink-to-fit: auto
}

However, very wide page layouts may not work very well on narrow paper.
preksha
This is how i am calling from my code :

public static void main (String args[]){
Prince prince = new Prince("C:\\Program Files\\Prince\\Engine\\bin\\Prince.exe");
prince.setHTML(true);
prince.setLog("C:\\prince.log");

try
{
FileInputStream fis = new FileInputStream("C:\\login_cloud.html");
FileOutputStream fos = new FileOutputStream("D:\\Princepdf.pdf");
Boolean b=prince.convert(fis, fos);
fis.close();
fos.close();

} catch (IOException e)
{

e.printStackTrace();
}
}


This code snippet doesnt render my css file . The text is displayed in the generated pdf as it is .
mikeday
Because you are passing an InputStream to convert(), Prince can't tell the file path, and so any relative paths within that file will not resolve correctly. Either call convert() where you pass a string filename, or call this:
prince.setBaseURL("file://c:\login_cloud.html");

Hopefully I've got the syntax correct for that URL. :)