Added PDFlib lite 5.0.3 which is required to build the PDF printer driver.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9229 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2004-10-06 17:16:52 +00:00
parent b86ab0a9dd
commit 9f61371bd2
13 changed files with 5632 additions and 0 deletions

View File

@ -0,0 +1,11 @@
# PDFlib bindings Makefile
# $Id: Makefile,v 1.1 2004/10/06 17:16:51 laplace Exp $
include ../../config/mkcommon.inc
SUB_DIRS = $(BINDINGS)
include ../../config/mksubdirs.inc
distclean::
-$(RM) php/Makefile.in

View File

@ -0,0 +1,76 @@
# Microsoft Developer Studio Project File - Name="Java" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=Java - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Java.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Java.mak" CFG="Java - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Java - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Java___Win32_Release"
# PROP BASE Intermediate_Dir "Java___Win32_Release"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /MT /W3 /O2 /I "c:\jdk1.3\include" /I "c:\jdk1.3\include\win32" /I "..\..\..\libs\pdflib" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_MT" /D "PDFLIB_STATIC" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x407 /d "_DEBUG"
# ADD RSC /l 0x407 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"pdf_java.dll" /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pdflib.lib /nologo /base:"0x55320000" /dll /pdb:none /machine:I386 /out:"pdf_java.dll" /libpath:"..\..\..\libs\pdflib\Release"
# SUBTRACT LINK32 /map /debug
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Desc=Creating jar file and documentation...
PostBuild_Cmds=c:\jdk1.3\bin\javac PDFlibException.java pdflib.java rmdir /s /q com mkdir com\pdflib copy pdflib.class com\pdflib copy PDFlibException.class com\pdflib c:\jdk1.3\bin\jar cvf pdflib.jar com/pdflib/PDFlibException.class com/pdflib/pdflib.class rmdir /s /q javadoc mkdir javadoc c:\jdk1.3\bin\javadoc -notree -author -version -d javadoc -public pdflib.java
# End Special Build Tool
# Begin Target
# Name "Java - Win32 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\pdflib_java.c
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,89 @@
# Makefile for PDFlib's Java binding
# $Id: Makefile,v 1.1 2004/10/06 17:16:51 laplace Exp $
top_builddir = ../../..
include $(top_builddir)/config/mkcommon.inc
PDFPEDANTIC =
LIBS = $(PDFLIBLINK)
INCLUDES = $(PDFLIBINC) $(JAVAINCLUDE)
LANG_LIBDIR = $(libdir)
LIBNAME = libpdf_java$(LA)
OBJ = pdflib_java$(LO)
SRC = pdflib_java.c
TESTPROGS = \
hello.class \
image.class \
pdfclock.class \
chartab.class \
invoice.class \
businesscard.class \
quickreference.class
include $(top_builddir)/config/mkbind.inc
.SUFFIXES: .java .class
.java.class:
-CLASSPATH=$$CLASSPATH:pdflib.jar:. javac $<
all:: pdflib.jar
pdflib.jar:: pdflib.java PDFlibException.java
$(RM) com
mkdir -p com/pdflib
javac PDFlibException.java pdflib.java && mv pdflib.class com/pdflib\
&& mv PDFlibException.class com/pdflib/PDFlibException.class
jar cvf pdflib.jar com/pdflib/pdflib.class \
com/pdflib/PDFlibException.class
$(RM) com
javadoc::
$(RM) javadoc
mkdir javadoc
-javadoc -notree -author -version -d javadoc -public \
pdflib.java PDFlibException.java
test:: $(LIBNAME) pdflib.jar $(TESTPROGS)
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java hello
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java image
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java pdfclock
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java chartab
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java invoice
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java businesscard
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java quickreference
smoke:: test smoketest.class
-CLASSPATH=$$CLASSPATH:pdflib.jar:. $(LIBTOOL_EXE) java smoketest
install:: $(LIBNAME) pdflib.jar
@-if test -f .libs/libpdf_java.jnilib; then \
$(LIBTOOL) --mode=install $(INSTALL_DATA) \
.libs/libpdf_java.jnilib $(LANG_LIBDIR); \
else \
$(LIBTOOL) --mode=install $(INSTALL_DATA) \
$(LIBNAME) $(LANG_LIBDIR); \
fi
@echo Copy pdflib.jar and javadoc to an appropriate directory,
@echo and include pdflib.jar in your CLASSPATH.
uninstall::
@-if test -f .libs/libpdf_java.jnilib; then \
$(LIBTOOL) --mode=uninstall $(RM) \
$(LANG_LIBDIR)/libpdf_java.jnilib; \
else \
$(LIBTOOL) --mode=uninstall $(RM) \
$(LANG_LIBDIR)/$(LIBNAME); \
fi
clean::
$(RM) *.class com pdflib.jar javadoc smoke_c_?.pdf
$(RM) hello.pdf image.pdf pdfclock.pdf chartab.pdf invoice.pdf
$(RM) businesscard.pdf quickreference.pdf
# Automatically generated dependencies

View File

@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
| Copyright (c) 1997-2004 Thomas Merz and PDFlib GmbH. All rights reserved. |
+---------------------------------------------------------------------------+
| |
| This software is subject to the PDFlib license. It is NOT in the |
| public domain. Extended versions and commercial licenses are |
| available, please check http://www.pdflib.com. |
| |
*---------------------------------------------------------------------------*/
/* $Id: PDFlibException.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlibException Java class
*/
package com.pdflib;
/** PDFlib - A library for generating PDF on the fly
Exception handling for PDFlib.
@author Rainer Schaaf
@version 5.0.3
*/
public class PDFlibException extends Exception {
public PDFlibException() {
super();
}
public PDFlibException(String msg) {
super(msg);
}
public PDFlibException(String msg, int errnum, String apiname) {
super(msg);
pdf_errnum = errnum;
pdf_apiname = apiname;
}
/** Map standard getMessage method to get_errmsg. */
public String get_errmsg() {
return super.getMessage();
}
/** Get the error number of the exception. */
public int get_errnum() {
return pdf_errnum;
}
/** Get the name of the API function which caused the exception. */
public String get_apiname() {
return pdf_apiname;
}
private int pdf_errnum;
private String pdf_apiname;
}

View File

@ -0,0 +1,90 @@
/* $Id: businesscard.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: hello example in Java
*/
import java.io.*;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class businesscard
{
public static void main (String argv[])
{
int font;
pdflib p = null ;
int i, blockcontainer, page;
String infile = "boilerplate.pdf";
/* This is where font/image/PDF input files live. Adjust as necessary.
*
* Note that this directory must also contain the LuciduxSans font
* outline and metrics files.
*/
String searchpath = "../data";
String[][] data = {
{ "name", "Victor Kraxi" },
{ "business.title", "Chief Paper Officer" },
{ "business.address.line1", "17, Aviation Road" },
{ "business.address.city", "Paperfield" },
{ "business.telephone.voice","phone +1 234 567-89" },
{ "business.telephone.fax", "fax +1 234 567-98" },
{ "business.email", "victor@kraxi.com" },
{ "business.homepage", "www.kraxi.com" },
};
try{
p = new pdflib();
// open new PDF file
if (p.open_file("businesscard.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_parameter("SearchPath", searchpath);
p.set_info("Creator", "businesscard.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title","PDFlib block processing sample (Java)");
blockcontainer = p.open_pdi(infile, "", 0);
if (blockcontainer == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
page = p.open_pdi_page(blockcontainer, 1, "");
if (page == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.begin_page(20, 20); // dummy page size
// This will adjust the page size to the block container's size.
p.fit_pdi_page(page, 0, 0, "adjustpage");
// Fill all text blocks with dynamic data
for (i = 0; i < (int) data.length; i++) {
if (p.fill_textblock(page, data[i][0], data[i][1],
"embedding encoding=winansi") == -1) {
System.err.println("Warning: " + p.get_errmsg());
}
}
p.end_page(); // close page
p.close_pdi_page(page);
p.close(); // close PDF document
p.close_pdi(blockcontainer);
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in businesscard sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

View File

@ -0,0 +1,124 @@
/* $Id: chartab.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: character table
*/
import java.io.*;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class chartab
{
/* change these as required */
static final String fontname = "LuciduxSans-Oblique";
/* This is where font/image/PDF input files live. Adjust as necessary. */
static final String searchpath = "../data";
/* list of encodings to use */
static final String encodings[] = { "iso8859-1", "iso8859-2", "iso8859-15" };
static final int ENCODINGS = 3;
static final float FONTSIZE = 16;
static final float TOP = 700;
static final float LEFT = 50;
static final float YINCR = 2*FONTSIZE;
static final float XINCR = 2*FONTSIZE;
public static void main (String argv[])
{
/* whether or not to embed the font */
int embed = 1;
String buf;
float x, y;
int row, col, font, page;
pdflib p = null ;
try{
p = new pdflib();
/* open new PDF file */
if (p.open_file("chartab.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_parameter("openaction", "fitpage");
p.set_parameter("fontwarning", "true");
p.set_parameter("SearchPath", searchpath);
p.set_info("Creator", "chartab.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "Character table (Java)");
/* loop over all encodings */
for (page = 0; page < ENCODINGS; page++)
{
p.begin_page(595, 842); /* start a new page */
/* print the heading and generate the bookmark */
font = p.load_font("Helvetica", "winansi", "");
p.setfont(font, FONTSIZE);
if (embed == 1) {
buf = fontname + " (" + encodings[page] + ") embedded";
} else{
buf = fontname + " (" + encodings[page] + ") not embedded";
}
p.show_xy(buf, LEFT - XINCR, TOP + 3 * YINCR);
p.add_bookmark(buf, 0, 0);
/* print the row and column captions */
p.setfont(font, 2 * FONTSIZE/3);
for (row = 0; row < 16; row++)
{
buf ="x" + (Integer.toHexString(row)).toUpperCase();
p.show_xy(buf, LEFT + row*XINCR, TOP + YINCR);
buf = (Integer.toHexString(row)).toUpperCase() + "x";
p.show_xy(buf, LEFT - XINCR, TOP - row * YINCR);
}
/* print the character table */
if (embed == 1) {
buf = "embedding";
} else{
buf = "";
}
font = p.load_font(fontname, encodings[page],buf);
p.setfont(font, FONTSIZE);
y = TOP;
x = LEFT;
for (row = 0; row < 16; row++)
{
for (col = 0; col < 16; col++) {
buf = String.valueOf((char)(16*row + col));
p.show_xy(buf, x, y);
x += XINCR;
}
x = LEFT;
y -= YINCR;
}
p.end_page(); /* close page */
}
p.close(); /* close PDF document */
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in chartab sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

View File

@ -0,0 +1,54 @@
/* $Id: hello.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: hello example in Java
*/
import java.io.*;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class hello
{
public static void main (String argv[])
{
int font;
pdflib p = null;
try{
p = new pdflib();
/* open new PDF file */
if (p.open_file("hello.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_info("Creator", "hello.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "Hello world (Java)!");
p.begin_page(595, 842); /* start a new page */
font = p.load_font("Helvetica-Bold", "winansi", "");
p.setfont(font, 18);
p.set_text_pos(50, 700);
p.show("Hello world!");
p.continue_text("(says Java)");
p.end_page(); /* close page */
p.close(); /* close PDF document */
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in hello sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

View File

@ -0,0 +1,61 @@
/* $Id: image.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: image example in Java
*/
import java.io.*;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class image
{
public static void main (String argv[])
{
int image;
float width, height;
pdflib p = null;
String imagefile = "nesrin.jpg";
/* This is where font/image/PDF input files live. Adjust as necessary.*/
String searchpath = "../data";
try{
p = new pdflib();
/* open new PDF file */
if (p.open_file("image.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_parameter("SearchPath", searchpath);
p.set_info("Creator", "image.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "image sample (Java)");
image = p.load_image("auto", imagefile, "");
if (image == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
/* dummy page size, will be adjusted by PDF_fit_image() */
p.begin_page(10, 10);
p.fit_image(image, (float) 0.0, (float) 0.0, "adjustpage");
p.close_image(image);
p.end_page(); /* close page */
p.close(); /* close PDF document */
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in hello sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

View File

@ -0,0 +1,169 @@
/* $Id: invoice.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: invoice example in Java
*/
import java.io.*;
import java.text.*; // DateFormat
import java.util.*; // Date
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class invoice
{
public static void main (String argv[])
{
pdflib p = null ;
int i, form, page, regularfont, boldfont;
String infile = "stationery.pdf";
/* This is where font/image/PDF input files live. Adjust as necessary.*/
String searchpath = "../data";
final float col1 = 55;
final float col2 = 100;
final float col3 = 330;
final float col4 = 430;
final float col5 = 530;
float fontsize = 12, leading, y;
float sum, total;
float pagewidth = 595, pageheight = 842;
Date now = new Date();
DateFormat fulldate = DateFormat.getDateInstance(DateFormat.LONG);
String closingtext =
"30 days warranty starting at the day of sale. " +
"This warranty covers defects in workmanship only. " +
"Kraxi Systems, Inc. will, at its option, repair or replace the " +
"product under the warranty. This warranty is not transferable. " +
"No returns or exchanges will be accepted for wet products.";
String[][] data = {
{ "Super Kite", "20", "2"},
{ "Turbo Flyer", "40", "5"},
{ "Giga Trash", "180", "1"},
{ "Bare Bone Kit", "50", "3"},
{ "Nitty Gritty", "20", "10"},
{ "Pretty Dark Flyer", "75", "1"},
{ "Free Gift", "0", "1"},
};
String[] months = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
try{
p = new pdflib();
// open new PDF file
if (p.open_file("invoice.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_parameter("SearchPath", searchpath);
p.set_info("Creator", "invoice.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "PDFlib invoice generation demo (Java)");
form = p.open_pdi(infile, "", 0);
if (form == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
page = p.open_pdi_page(form, 1, "");
if (page == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
boldfont = p.load_font("Helvetica-Bold", "winansi", "");
regularfont = p.load_font("Helvetica", "winansi", "");
leading = fontsize + 2;
// Establish coordinates with the origin in the upper left corner.
p.set_parameter("topdown", "true");
p.begin_page(pagewidth, pageheight); // A4 page
p.fit_pdi_page(page, 0, pageheight, "");
p.close_pdi_page(page);
p.setfont(regularfont, fontsize);
// Print the address
y = 170;
p.set_value("leading", leading);
p.show_xy("John Q. Doe", col1, y);
p.continue_text("255 Customer Lane");
p.continue_text("Suite B");
p.continue_text("12345 User Town");
p.continue_text("Everland");
// Print the header and date
p.setfont(boldfont, fontsize);
y = 300;
p.show_xy("INVOICE", col1, y);
p.fit_textline(fulldate.format(now), col5, y, "position {100 0}");
// Print the invoice header line
p.setfont(boldfont, fontsize);
// "position {0 0}" is left-aligned, "position {100 0}" right-aligned
y = 370;
p.fit_textline("ITEM", col1, y, "position {0 0}");
p.fit_textline("DESCRIPTION", col2, y, "position {0 0}");
p.fit_textline("QUANTITY", col3, y, "position {100 0}");
p.fit_textline("PRICE", col4, y, "position {100 0}");
p.fit_textline("AMOUNT", col5, y, "position {100 0}");
// Print the article list
p.setfont(regularfont, fontsize);
y += 2*leading;
total = 0;
for (i = 0; i < data.length; i++) {
p.show_xy(Integer.toString(i+1), col1, y);
p.show_xy(data[i][0], col2, y);
p.fit_textline(data[i][2], col3, y, "position {100 0}");
p.fit_textline(data[i][1], col4, y, "position {100 0}");
sum = 0;
sum = Integer.parseInt(data[i][2]) * Integer.parseInt(data[i][1]);
p.fit_textline(Float.toString(sum), col5, y, "position {100 0}");
y += leading;
total += sum;
}
y += leading;
p.setfont(boldfont, fontsize);
p.fit_textline(Float.toString(total), col5, y, "position {100 0}");
// Print the closing text
y += 5*leading;
p.setfont(regularfont, fontsize);
p.set_value("leading", leading);
p.show_boxed(closingtext,
col1, y + 4*leading, col5-col1, 4*leading, "justify", "");
p.end_page();
p.close();
p.close_pdi(form);
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in invoice sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

View File

@ -0,0 +1,121 @@
/* $Id: pdfclock.java,v 1.1 2004/10/06 17:16:51 laplace Exp $
*
* PDFlib client: pdfclock example in Java
*/
import java.io.*;
import java.text.*; // SimpleDateFormat
import java.util.*; // Date
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class pdfclock
{
public static void main (String argv[])
{
pdflib p = null;
int tm_hour, tm_min, tm_sec, alpha;
float RADIUS = 200.0f;
float MARGIN = 20.0f;
SimpleDateFormat format;
Date now = new Date();
try{
p = new pdflib();
/* open new PDF file */
if (p.open_file("pdfclock.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_info("Creator", "pdfclock.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "PDF clock (Java)");
p.begin_page( (int) (2 * (RADIUS + MARGIN)),
(int) (2 * (RADIUS + MARGIN)));
p.translate(RADIUS + MARGIN, RADIUS + MARGIN);
p.setcolor("fillstroke", "rgb", 0.0f, 0.0f, 1.0f, 0.0f);
p.save();
// minute strokes
p.setlinewidth(2.0f);
for (alpha = 0; alpha < 360; alpha += 6)
{
p.rotate(6.0f);
p.moveto(RADIUS, 0.0f);
p.lineto(RADIUS-MARGIN/3, 0.0f);
p.stroke();
}
p.restore();
p.save();
// 5 minute strokes
p.setlinewidth(3.0f);
for (alpha = 0; alpha < 360; alpha += 30)
{
p.rotate(30.0f);
p.moveto(RADIUS, 0.0f);
p.lineto(RADIUS-MARGIN, 0.0f);
p.stroke();
}
format = new SimpleDateFormat("hh");
tm_hour= Integer.parseInt(format.format(now));
format = new SimpleDateFormat("mm");
tm_min = Integer.parseInt(format.format(now));
format = new SimpleDateFormat("ss");
tm_sec = Integer.parseInt(format.format(now));
// draw hour hand
p.save();
p.rotate((-((tm_min/60.0f) + tm_hour - 3.0f) * 30.0f));
p.moveto(-RADIUS/10, -RADIUS/20);
p.lineto(RADIUS/2, 0.0f);
p.lineto(-RADIUS/10, RADIUS/20);
p.closepath();
p.fill();
p.restore();
// draw minute hand
p.save();
p.rotate((-((tm_sec/60.0f) + tm_min - 15.0f) * 6.0f));
p.moveto(-RADIUS/10, -RADIUS/20);
p.lineto(RADIUS * 0.8f, 0.0f);
p.lineto(-RADIUS/10, RADIUS/20);
p.closepath();
p.fill();
p.restore();
// draw second hand
p.setcolor("fillstroke", "rgb", 1.0f, 0.0f, 0.0f, 0.0f);
p.setlinewidth(2);
p.save();
p.rotate(-((tm_sec - 15.0f) * 6.0f));
p.moveto(-RADIUS/5, 0.0f);
p.lineto(RADIUS, 0.0f);
p.stroke();
p.restore();
// draw little circle at center
p.circle(0f, 0f, RADIUS/30);
p.fill();
p.restore();
p.end_page();
p.close();
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in pdfclock sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,97 @@
/* $Id: quickreference.java,v 1.1 2004/10/06 17:16:52 laplace Exp $
*
* PDFlib/PDI client: mini imposition demo
*/
import java.io.*;
import com.pdflib.pdflib;
import com.pdflib.PDFlibException;
public class quickreference
{
public static void main (String argv[])
{
int manual, page;
int font, row, col;
final int maxrow = 2, maxcol = 2;
int i, startpage = 1, endpage = 4;
final float width = 500, height = 770;
int pageno;
pdflib p = null;
String infile = "reference.pdf";
/* This is where font/image/PDF input files live. Adjust as necessary.*/
String searchpath = "../data";
try{
p = new pdflib();
if (p.open_file("quickreference.pdf") == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.set_parameter("SearchPath", searchpath);
p.set_info("Creator", "quickreference.java");
p.set_info("Author", "Thomas Merz");
p.set_info("Title", "imposition demo (Java)");
manual = p.open_pdi(infile, "", 0);
if (manual == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
row = 0;
col = 0;
p.set_parameter("topdown", "true");
for (pageno = startpage; pageno <= endpage; pageno++) {
if (row == 0 && col == 0) {
p.begin_page(width, height);
font = p.load_font("Helvetica-Bold", "winansi", "");
p.setfont(font, 18);
p.set_text_pos(24, 24);
p.show("PDFlib Quick Reference");
}
page = p.open_pdi_page(manual, pageno, "");
if (page == -1) {
throw new Exception("Error: " + p.get_errmsg());
}
p.fit_pdi_page(manual, width/maxcol*col,
(row + 1) * height/maxrow, "scale " + (float)1/maxrow);
p.close_pdi_page(page);
col++;
if (col == maxcol) {
col = 0;
row++;
}
if (row == maxrow) {
row = 0;
p.end_page();
}
}
// finish the last partial page
if (row != 0 || col != 0)
p.end_page();
p.close();
p.close_pdi(manual);
} catch (PDFlibException e) {
System.err.print("PDFlib exception occurred in quickreference sample:\n");
System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +
": " + e.getMessage() + "\n");
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (p != null) {
p.delete(); /* delete the PDFlib object */
}
}
}
}