移除报表导出pdf时附带的Demo Version字样
作者:胡海龙
日期:2007-11-09日
Compiere自带的报表,在导出为pdf文档时,会在pdf文档的背景上附带有Demo Version字样,下面讲述如何移除Demo Version字样。
1,把jPDFPrinter.jar放到compiere_all(源码)的lib文件夹。
2,在compiere_all/print/src/org/compiere/print 建立一个print.java类。
// add by huhailong 20071109
package org.compiere.print;
import java.io.*;
import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import org.compiere.print.layout.*;
publicclass Print implements Pageable, Printable, Doc
{
public Print (LayoutEngine layout, boolean isCopy)
{
m_layout = layout;
m_isCopy = isCopy;
}
private LayoutEngine m_layout;
privateboolean m_isCopy;
publicint getNumberOfPages()
{
returnm_layout.getNumberOfPages();
}
privateboolean havePage (int pageIndex)
{
if (pageIndex < 0 || pageIndex >= m_layout.getNumberOfPages())
returnfalse;
returntrue;
}
public PageFormat getPageFormat (int pageIndex) throws IndexOutOfBoundsException
{
if (!havePage(pageIndex))
thrownew IndexOutOfBoundsException("Print.getPageFormat - no page index" + pageIndex);
returnm_layout.getPageFormat();
}
public Printable getPrintable (int pageIndex) throws IndexOutOfBoundsException
{
if (!havePage(pageIndex))
thrownew IndexOutOfBoundsException("Print.getPrintable - no page index " + pageIndex);
returnthis;
}
publicint print (Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (!havePage(pageIndex))
return Printable.NO_SUCH_PAGE;
Rectangle r = new Rectangle (0, 0, (int)m_layout.getPaper().getWidth(true),
(int)m_layout.getPaper().getHeight(true));
Page page = m_layout.getPage(pageIndex+1);
//
page.paint((Graphics2D)graphics, r, false, m_isCopy);
m_layout.getHeaderFooter().paint((Graphics2D)graphics, r, false);
return Printable.PAGE_EXISTS;
}
public DocFlavor getDocFlavor()
{
return DocFlavor.SERVICE_FORMATTED.PAGEABLE;
}
public Object getPrintData() throws IOException
{
returnthis;
}
public DocAttributeSet getAttributes()
{
returnnull;
}
public Reader getReaderForText() throws IOException
{
returnnull;
}
public InputStream getStreamForBytes() throws IOException
{
returnnull;
}
} // Print
3,把ReportEngine.java的 createPDF (File file) 方法改为以下內容。
/**startaddbyhuhailong20071109*/
import com.qoppa.pdfPrinter.PDFPrinterJob;
/**endaddbyhuhailong20071109*/
publicboolean createPDF (File file)
{
String fileName = null;
URI uri = null;
try
{
if (file == null)
file = File.createTempFile ("ReportEngine", ".pdf");
fileName = file.getAbsolutePath();
uri = file.toURI();
if (file.exists())
file.delete();
}
catch (Exception e)
{
log.log(Level.SEVERE, "file", e);
returnfalse;
}
log.fine(uri.toString());
/**startaddbyhuhailong20071109*/
if (m_layout == null)
layout ();
Print print = new Print (m_layout, false);
PrintRequestAttributeSet prats = m_layout.getPaper().getPrintRequestAttributeSet ();
prats.add (new JobName(fileName, Locale.getDefault()));
prats.add (new Destination (uri));
try
{
if (false)
Class.forName("com.qoppa.pdfPrinter.PDFPrinterJob");
com.qoppa.pdfPrinter.PDFPrinterJob job = (PDFPrinterJob)PDFPrinterJob.getPrinterJob ();
job.setPrintable(print, m_layout.getPageFormat());
job.print(fileName);
}
catch (ClassNotFoundException cnf)
{
returnfalse;
}
catch (Exception e)
{
returnfalse;
}
/**endaddbyhuhailong20071109*/
/**startcommentbyhuhailong20071109*/
/*try
{
if (m_layout == null)
layout ();
ArchiveEngine.get().archive(m_layout, m_info);
Document.getPDFAsFile(fileName, m_layout.getPageable(false));
}
catch (Exception e)
{
log.log(Level.SEVERE, "PDF", e);
return false;
}*/
/**endcommentbyhuhailong20071109*/
File file2 = new File(fileName);
log.info(file2.getAbsolutePath() + " - " + file2.length());
return file2.exists();
} // createPDF
4,修改 compiere_all/print/build.xml,如下:
<pathelement path="../lib/jPDF.jar"/>
<!-- start add by huhailong 20071109 -->
<pathelement path="../lib/jPDFPrinter.jar"/>
<!-- end add by huhailong 20071109 -->
把jPDFPrinter.jar抄到 compiere_all/print/
5,修改 compiere_all/Client/build.xml,如下:
<pathelement path="../tools/lib/j2ee.jar"/>
<!-- start add by huhailong 20071109 -->
<pathelement path="../lib/jPDFPrinter.jar"/>
<!-- end add by huhailong 20071109 -->
……
<unjar src="../interfaces/Interfaces.jar" dest="${build.dir}" />
<!-- start add by huhailong 20071109 -->
<unjar src="../lib/jPDFPrinter.jar" dest="${build.dir}" />
<!-- end add by huhailong 20071109 -->
6,编译print,然后编译client,测试,移除Demo Version成功。