[ 
https://issues.apache.org/jira/browse/FOP-2616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15353478#comment-15353478
 ] 

Ramnikunj Prajapati commented on FOP-2616:
------------------------------------------

[~psancho] We are using FOP version 2.0 and we are generating pdf 
programmatically using Java code. We referred to sample java code provided on 
FOP site for creating pdf using XSL and XML. 


Here goes the java code: 

import java.io.File;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.fop.apps.MimeConstants;

public class JavaCodePDF{
 public static void main(String s[]) 
         {
        try
                {
                String xmlPath = s[0];
                String xslPath = s[1];
                String pdfPath = s[2];
                                        System.out.println("Preparing PDF...");
                  
                File xmlFile = new File(xmlPath);
                File xsltFile = new File(xslPath);
                File pdfFile = new File(pdfPath);
        
                System.out.println("Input XML (" + xmlFile + ")");
                        System.out.println("Output PDF (" + pdfFile + ")");
                        
                FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new 
File(".").toURI()).setStrictFOValidation(false);
                final FopFactory fopFactory = fopFactoryBuilder.build();        
        
                FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
              
                // Setup output
                OutputStream out = new java.io.FileOutputStream(pdfFile);
                out = new java.io.BufferedOutputStream(out);
                try 
                {                  
                    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, 
foUserAgent, out);       
                    TransformerFactory factory = 
TransformerFactory.newInstance();
                    Transformer transformer = factory.newTransformer(new 
StreamSource(xsltFile));         
                    transformer.setParameter("versionParam", "2.0");
                    Source src = new StreamSource(xmlFile);
                    Result res = new SAXResult(fop.getDefaultHandler());
                            // Start XSLT transformation and FOP processing
                    transformer.transform(src, res);
                } 
                finally 
                {
                    out.close();
                }
                System.out.println("Success!");
                }
        catch(Exception expMsg)
                {
                        System.out.println(expMsg.getMessage());
                }       
    }
 }



> Extra blank page gets created even though the content fits in previous page
> ---------------------------------------------------------------------------
>
>                 Key: FOP-2616
>                 URL: https://issues.apache.org/jira/browse/FOP-2616
>             Project: FOP
>          Issue Type: Bug
>         Environment: windows 7, Java 1.8
>            Reporter: Ramnikunj Prajapati
>
> Hi,
> We are creating a pdf out of a xml using xsl and FOP library. We have set 
> header and footer for all pages. We have a coupon which needs to be 
> positioned at the bottom of last page of pdf and when the coupon is in the 
> bottom the footer text should not appear. If the data in the current page is 
> more to accommodate in one page than the extra data and coupon should be 
> shifted to the next page. The condition for coupon is that it should always 
> be placed in bottom of last page. We found an issue where if the data in the 
> body is about 36-39 lines which fits the current page with coupon still an 
> extra blank page gets added with the header.
> For reference please check the xsl, sample xml and pdf  which is placed in 
> this google drive folder: https://goo.gl/4Pwqev Please read the readme file 
> for more info



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to