Forum How do I...?

Need Help To Determine If Prince Is Installed Correctly

jkozar
We are using Solaris 10.

We have j2ee program which is deployed as an OC4J instance in Oracle's Application Server 10.1.2.3. This j2ee program invokes the prince executable.

I do not think that Prince is installed correctly on our server. The only way I can invoke any PrinceXML CSS is by injecting it into the javascript. I cannot simply add the css to my stylesheet.

See the following example below:

</style>


    <script language="javascript"> 
 function setFormContents(theForm,debug) { 
 var styletemp = "";
 var linetemp = "";
 var loope = 0;
 var loopi = 0;
 var fileDomain;
 
 var stylenumber = document.styleSheets.length;
 var rulenumber = 0;
 for (loope = 0;loope < stylenumber; loope++)
  {
 
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    {
    linetemp = document.styleSheets[loope].cssText;
    styletemp = styletemp + linetemp;
    }
    else
    {
    if (document.styleSheets[loope].href) {
       fileDomain = document.styleSheets[loope].href.split(/\/+/g)[1];
    }
    else {
       fileDomain = "";}
    if (fileDomain == "acgidevxx.acgisoftware.com" || fileDomain == "") // ignore CSS files from other domains
    {
       if (document.styleSheets[loope].rules){
          cssRules = document.styleSheets[loope].rules; }
       else {
          cssRules = document.styleSheets[loope].cssRules; }
       if (cssRules){
           rulenumber = cssRules.length;
           for (loopi = 0; loopi < rulenumber; loopi++)
           {
             linetemp = cssRules[loopi].cssText;
             styletemp = styletemp + linetemp;
           }
       }
    }
    
    } 
  }
 if (debug===true){
 document.thepdfdebugform.pdfreport.value='<HTML><STYLE type="text/css">' + styletemp + '</STYLE><BODY>' + 
    document.body.innerHTML + '</BODY></HTML>';
  }
 else{
 document.thepdfform.pdfreport.value='<HTML><STYLE type="text/css">@page {\rprince-shrink-to-fit: none;\r }\r' + styletemp + '</STYLE><BODY>' + 
    document.body.innerHTML + '</BODY></HTML>';
  }
 return true; 
   } 
 </script>


There are a couple of things I would like to determine as we have a large client base that will use this:


    Would it be better to install this on a windows server... is that even doable? Can Prince reside on a different server than my main web-server?

    Is there someplace that I can see how the output is suppose to look? (Do you have someplace I can past my html to see how the output looks on a proper PrinceXML imstall?

Thanks!!!
mikeday
It is best to start with something simple. Save the HTML you want to convert in a file, and run Prince by hand from the command-line (or the Windows GUI) to generate a PDF. This is the easiest way to see what is going on.

However, you are then trying to do something much more complex: make a HTML page viewed in the browser, with a form that submits a copy of the page itself to the server, which then takes that serialised copy of the page and passes it to Prince for rendering. Each extra link in that chain adds a potential source of error. Perhaps you could try saving a copy of the HTML just before you pass it to Prince? That would probably reveal why the CSS isn't working, which I expect would be a path error.
jkozar
mikeday wrote:
It is best to start with something simple. Save the HTML you want to convert in a file, and run Prince by hand from the command-line (or the Windows GUI) to generate a PDF. This is the easiest way to see what is going on.

However, you are then trying to do something much more complex: make a HTML page viewed in the browser, with a form that submits a copy of the page itself to the server, which then takes that serialised copy of the page and passes it to Prince for rendering. Each extra link in that chain adds a potential source of error. Perhaps you could try saving a copy of the HTML just before you pass it to Prince? That would probably reveal why the CSS isn't working, which I expect would be a path error.



Before I go down this path (pun intended). Am I correct in assuming that the css should not have to be hacked into the javascritpt as in the above example? I should just be able to add any PrinceXML css in the head of the document like this...correct:

<style>

@page { border: solid 1pt red }

@page { margin: 40pt 30pt 40pt 30pt }


</style>




Thanks Mike!!!

Edited by jkozar

jim_albright
Here is my VB code for running Prince and passing parameters to it. The /tracking/ part is extra feature to add tracking at the paragraph level. The /tracking css/ then adds color to paragraphs with tracking added. You can process multiple files or just one at a time with this code.

The css is /sStylesheetFileName/.

 Private Function convertUsingPrince()
        Dim percentCompleted As Integer
        If File.Exists(sPrinceEXE) Then
            Dim pdfCreated As Boolean = False
            Try
                ' delete output file
                If File.Exists(sPDFoutputName) Then File.Delete(sPDFoutputName)

            Catch ex As Exception
                MessageBox.Show("Another program has locked the output file: " + vbCrLf + sPDFoutputName + vbCrLf + "Please close the program displaying the file and start over. Princess will remember your settings.", "File locked", MessageBoxButtons.OK, MessageBoxIcon.Stop)
            End Try

            updateLogHistoryFile()
            '    Dim sOptions As String = " --server --progress --verbose  "
            Dim sOptions As String = " --verbose --server --log-stats "

            '--------------------------------------------------------


            Dim sArguments As String

            ifMultipleFilesGenerateDocumentNameWithAllFilesIncluded()


            If sStylesheetFileName = "" Or sStylesheetFileName = "#none#" Then
                sArguments = sOptions & _
                    " --script " + quote + sJavascriptFileName + quote + _
                    " --log " + quote + sLogCurrentName + quote + _
                    " --output " + quote + sPDFoutputName + quote + _
                    " --input " + quote + sInputFormat + quote + _
                    " " + quote + sDocumentFileName + quote
            Else
                If sToggleTracking = sTrackingHidden Then
                    sArguments = sOptions & _
                    " --script " + quote + sJavascriptFileName + quote + _
                    " --style " + quote + sStylesheetFileName + quote + _
                    " --style " + quote + sRemoveTrackingColor + quote + _
                    " --log " + quote + sLogCurrentName + quote + _
                    " --output " + quote + sPDFoutputName + quote + _
                    " --input " + quote + sInputFormat + quote + _
                    " " + quote + sDocumentFileName + quote

                Else
                    If blnProcessMultipleInputFiles = True Then
                        sArguments = sOptions & _
                        " --script " + quote + sJavascriptFileName + quote + _
                        " --style " + quote + sStylesheetFileName + quote + _
                        " --style " + quote + sShowTrackingColor + quote + _
                        " --log " + quote + sLogCurrentName + quote + _
                        " --output " + quote + sPDFoutputName + quote + _
                        " --input " + quote + sInputFormat + quote + _
                        " " + sDocumentFileName
                    Else
                        sArguments = sOptions & _
                        " --debug " + _
                        " --script " + quote + sJavascriptFileName + quote + _
                        " --style " + quote + sStylesheetFileName + quote + _
                        " --style " + quote + sShowTrackingColor + quote + _
                        " --log " + quote + sLogCurrentName + quote + _
                        " --output " + quote + sPDFoutputName + quote + _
                        " --input " + quote + sInputFormat + quote + _
                        " " + quote + sDocumentFileName + quote
                    End If

                End If

            End If
            ' create a new process
            Dim myPrince As Process = New Process
            Dim sErrorInput As String = "start"

            ' set the file name and the command line args
            myPrince.StartInfo.FileName = sPrinceEXE
            myPrince.StartInfo.Arguments = sArguments

            ' start the process in a hidden window
            myPrince.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            myPrince.StartInfo.CreateNoWindow = True

            ' stdErr redirected
            myPrince.StartInfo.RedirectStandardError = True
            myPrince.StartInfo.UseShellExecute = False
            myPrince.Start()
            Dim iStart As Integer = Microsoft.VisualBasic.Timer
            Dim test As String
            Dim blnWarning As Boolean = False
            LogToolStripMenuItem.BackColor = Nothing

            Do Until (sErrorInput = Nothing) ' this part never fires
                ' While Not myPrince.HasExited
                sErrorInput = myPrince.StandardError.ReadLine
                If sErrorInput = Nothing Then
                    Exit Do
                End If

                If sErrorInput.StartsWith("prg|") Then
                    test = sErrorInput.Substring(4)
                    percentCompleted = Convert.ToInt16(test)
                    bWkrPrince.ReportProgress(percentCompleted, sErrorInput)
                ElseIf sErrorInput.Contains("total-page-count|") Then
                    test = sErrorInput.Substring(21)
                    iLastPageNumber = Convert.ToInt16(test)
                ElseIf sErrorInput.Contains("fin|failure") Then
                    LogToolStripMenuItem.BackColor = Color.Red
                ElseIf sErrorInput.Contains("Could not resolve host") Then
                    MessageBox.Show("Please verify that you are connected to the internet and try again.", "No connection to internet found.", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                ElseIf sErrorInput.Contains("fin|success") Then
                    If blnWarning = True Then
                        LogToolStripMenuItem.BackColor = Color.Yellow
                    Else
                        LogToolStripMenuItem.BackColor = Color.Lime
                    End If
                ElseIf sErrorInput.Contains("inapplicable license") Then  ' new vesion of Prince gave this error 2010-12-18
                    blnWarning = False
                ElseIf sErrorInput.Contains("msg|wrn|") Then
                    LogToolStripMenuItem.BackColor = Color.Yellow
                    blnWarning = True
                End If
            Loop


            ' if the process doesn't complete within
            ' 10 second, kill it
            ' will probably need to remove this as the loop above keeps control
            myPrince.WaitForExit(10000)
            '   MessageBox.Show("waiting " + sArguments)
            Dim iEnd As Integer = Microsoft.VisualBasic.Timer
            If myPrince.HasExited Then
                '    MessageBox.Show("Prince completed " & iEnd - iStart & " seconds.")
            Else
                myPrince.Kill()
                ' this will say 0 seconds now
                MessageBox.Show("Prince process terminated as it is taking more than " & iEnd - iStart & " seconds.")

            End If
            pdfCreated = File.Exists(sPDFoutputName)
            ' MessageBox.Show("Prince completed.")
            Me.ProgressBar1.Value = 0

            Me.Cursor = Cursors.Default
            Return pdfCreated
        Else
            ' where is prince.exe?
            locatePrinceExe()
            Me.Cursor = Cursors.Default

            Return False
        End If

    End Function


Jim Albright
Wycliffe Bible Translators

jkozar
Thanks for the info Jim. I am gathering info to take to the developer that handles the Java install (I am the Web-Designer).

I will pass along the information...as I am not sure what I am looking at in your post :?
mikeday
Add the CSS to the document using the <style> element, not the <script> element.
jkozar
mikeday wrote:
Add the CSS to the document using the <style> element, not the <script> element.


Sorry about that Mike. Indeed I do use the style tag...I must not have been fully awake when I made that post.(I corrected it above to represent the way the post should read) I had script on the brain as I was thinking about how I had to hack the css into the javascript to get it to work.

So for clarification purpose...I always used the style tags...but the css never took in the style tag...it had to be placed in the javascript as in the above initial post. I am assuming that I should be able to use style tags in the document and not have to resort to the script hack.
mikeday
Yes, assuming you are feeding the document straight to Prince, and not doing anything weird with it first. :)
jkozar
One more quick question before I start testing on a local install. We have a server license. Can I use that same license to install on a local windows machine? Do I even need a license for testing purposes?
mikeday
You can install it on another machine for testing purposes.
jkozar
mikeday wrote:
You can install it on another machine for testing purposes.



Ok - It works perfectly on my local install.

Do you have any clients or a third party that you could recommend that could help us do a proper java install of PrinceXML on a Unix machine?

Do you offer any services for this type of installation?

Thanks!!!
mikeday
First you need to install Prince, and test that it works from the command-line. This part should not be too tricky, has nothing to do with Java, and we can walk you through it on the forum if necessary.

Calling Prince from Java should only be attempted once you have verified that it is working correctly from the command-line, then build up from there. :)
jkozar
mikeday wrote:
First you need to install Prince, and test that it works from the command-line. This part should not be too tricky, has nothing to do with Java, and we can walk you through it on the forum if necessary.

Calling Prince from Java should only be attempted once you have verified that it is working correctly from the command-line, then build up from there. :)



Excellent. All is well from the command line.

One of the issues we are running into as per the developer that installed it...is that we are using JavaScript to send the page info to PrinceXML and that javascript does not recognize the @ symbol in the Prince CSS. Does this sound right to you?

Shouldn't we be able to use a javascript submit button to send the page to PrinceXML?

Thanks for all of your help Mike!!!
mikeday
Okay, now we are discussing browser JavaScript issues. :)

If the original HTML page was generated on the server and delivered to the browser, is it necessary for the browser to submit the entire HTML and CSS back to the server again for conversion to PDF? Normally people would just hit a print button or follow a print link that would cause the server to generate the HTML and convert it with Prince all on the server-side, without sending the HTML back and forth across the network.