first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,100 @@
package com.lowagie.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class BuildTutorial {
static String root;
static FileWriter build;
public static void main(String[] paramArrayOfString) {
if (paramArrayOfString.length == 4) {
File file1 = new File(paramArrayOfString[0]);
File file2 = new File(paramArrayOfString[1]);
File file3 = new File(file1, paramArrayOfString[2]);
File file4 = new File(file1, paramArrayOfString[3]);
try {
System.out.print("Building tutorial: ");
root = new File(paramArrayOfString[1], file1.getName()).getCanonicalPath();
System.out.println(root);
build = new FileWriter(new File(root, "build.xml"));
build.write("<project name=\"tutorial\" default=\"all\" basedir=\".\">\n");
build.write("<target name=\"all\">\n");
action(file1, file2, file3, file4);
build.write("</target>\n</project>");
build.flush();
build.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.err.println("Wrong number of parameters.\nUsage: BuildSite srcdr destdir xsl_examples xsl_site");
}
}
public static void action(File paramFile1, File paramFile2, File paramFile3, File paramFile4) throws IOException {
if (".svn".equals(paramFile1.getName()))
return;
System.out.print(paramFile1.getName());
if (paramFile1.isDirectory()) {
System.out.print(" ");
System.out.println(paramFile1.getCanonicalPath());
File file = new File(paramFile2, paramFile1.getName());
file.mkdir();
File[] arrayOfFile = paramFile1.listFiles();
if (arrayOfFile != null) {
for (int i = 0; i < arrayOfFile.length; i++) {
File file1 = arrayOfFile[i];
action(file1, file, paramFile3, paramFile4);
}
} else {
System.out.println("... skipped");
}
} else if (paramFile1.getName().equals("index.xml")) {
System.out.println("... transformed");
convert(paramFile1, paramFile4, new File(paramFile2, "index.php"));
File file = new File(paramFile2, "build.xml");
String str = file.getCanonicalPath().substring(root.length());
str = str.replace(File.separatorChar, '/');
if ("/build.xml".equals(str))
return;
convert(paramFile1, paramFile3, file);
build.write("\t<ant antfile=\"${basedir}");
build.write(str);
build.write("\" target=\"install\" inheritAll=\"false\" />\n");
} else {
System.out.println("... skipped");
}
}
public static void convert(File paramFile1, File paramFile2, File paramFile3) {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Templates templates = transformerFactory.newTemplates(new StreamSource(new FileInputStream(paramFile2)));
Transformer transformer = templates.newTransformer();
String str = paramFile3.getParentFile().getCanonicalPath().substring(root.length());
str = str.replace(File.separatorChar, '/');
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '/')
stringBuffer.append("/..");
}
transformer.setParameter("branch", str);
transformer.setParameter("root", stringBuffer.toString());
StreamSource streamSource = new StreamSource(new FileInputStream(paramFile1));
StreamResult streamResult = new StreamResult(new FileOutputStream(paramFile3));
transformer.transform(streamSource, streamResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,58 @@
package com.lowagie.tools;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.SimpleBookmark;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
public class ConcatPdf {
public static void main(String[] paramArrayOfString) {
if (paramArrayOfString.length < 2) {
System.err.println("arguments: file1 [file2 ...] destfile");
} else {
try {
int i = 0;
ArrayList arrayList = new ArrayList();
int j = 0;
String str = paramArrayOfString[paramArrayOfString.length - 1];
Document document = null;
PdfCopy pdfCopy = null;
while (j < paramArrayOfString.length - 1) {
PdfReader pdfReader = new PdfReader(paramArrayOfString[j]);
pdfReader.consolidateNamedDestinations();
int k = pdfReader.getNumberOfPages();
List list = SimpleBookmark.getBookmark(pdfReader);
if (list != null) {
if (i)
SimpleBookmark.shiftPageNumbers(list, i, null);
arrayList.addAll(list);
}
i += k;
System.out.println("There are " + k + " pages in " + paramArrayOfString[j]);
if (j == 0) {
document = new Document(pdfReader.getPageSizeWithRotation(1));
pdfCopy = new PdfCopy(document, new FileOutputStream(str));
document.open();
}
int m = 0;
while (m < k) {
PdfImportedPage pdfImportedPage = pdfCopy.getImportedPage(pdfReader, ++m);
pdfCopy.addPage(pdfImportedPage);
System.out.println("Processed page " + m);
}
pdfCopy.freeReader(pdfReader);
j++;
}
if (!arrayList.isEmpty())
pdfCopy.setOutlines(arrayList);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View file

@ -0,0 +1,63 @@
package com.lowagie.tools;
import com.lowagie.text.pdf.PdfEncryptor;
import com.lowagie.text.pdf.PdfReader;
import java.io.FileOutputStream;
import java.util.HashMap;
public class EncryptPdf {
private static final int INPUT_FILE = 0;
private static final int OUTPUT_FILE = 1;
private static final int USER_PASSWORD = 2;
private static final int OWNER_PASSWORD = 3;
private static final int PERMISSIONS = 4;
private static final int STRENGTH = 5;
private static final int MOREINFO = 6;
private static final int[] permit = new int[] { 2052, 8, 16, 32, 256, 512, 1024, 4 };
private static void usage() {
System.out.println("usage: input_file output_file user_password owner_password permissions 128|40 [new info string pairs]");
System.out.println("permissions is 8 digit long 0 or 1. Each digit has a particular security function:");
System.out.println();
System.out.println("AllowPrinting");
System.out.println("AllowModifyContents");
System.out.println("AllowCopy");
System.out.println("AllowModifyAnnotations");
System.out.println("AllowFillIn (128 bit only)");
System.out.println("AllowScreenReaders (128 bit only)");
System.out.println("AllowAssembly (128 bit only)");
System.out.println("AllowDegradedPrinting (128 bit only)");
System.out.println("Example permissions to copy and print would be: 10100000");
}
public static void main(String[] paramArrayOfString) {
System.out.println("PDF document encryptor");
if (paramArrayOfString.length <= 5 || paramArrayOfString[4].length() != 8) {
usage();
return;
}
try {
int i = 0;
String str = paramArrayOfString[4];
for (int j = 0; j < str.length(); j++)
i |= (str.charAt(j) == '0') ? 0 : permit[j];
System.out.println("Reading " + paramArrayOfString[0]);
PdfReader pdfReader = new PdfReader(paramArrayOfString[0]);
System.out.println("Writing " + paramArrayOfString[1]);
HashMap hashMap = new HashMap();
for (int k = 6; k < paramArrayOfString.length - 1; k += 2)
hashMap.put(paramArrayOfString[k], paramArrayOfString[k + 1]);
PdfEncryptor.encrypt(pdfReader, new FileOutputStream(paramArrayOfString[1]), paramArrayOfString[2].getBytes(), paramArrayOfString[3].getBytes(), i, paramArrayOfString[5].equals("128"), hashMap);
System.out.println("Done.");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,130 @@
package com.lowagie.tools;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
public class Executable {
public static String acroread = null;
private static Process action(String paramString1, String paramString2, boolean paramBoolean) throws IOException {
Process process = null;
if (paramString2.trim().length() > 0) {
paramString2 = " " + paramString2.trim();
} else {
paramString2 = "";
}
if (acroread != null) {
process = Runtime.getRuntime().exec(acroread + paramString2 + " \"" + paramString1 + "\"");
} else if (isWindows()) {
if (isWindows9X()) {
process = Runtime.getRuntime().exec("command.com /C start acrord32" + paramString2 + " \"" + paramString1 + "\"");
} else {
process = Runtime.getRuntime().exec("cmd /c start acrord32" + paramString2 + " \"" + paramString1 + "\"");
}
} else if (isMac()) {
if (paramString2.trim().length() == 0) {
process = Runtime.getRuntime().exec(new String[] { "/usr/bin/open", paramString1 });
} else {
process = Runtime.getRuntime().exec(new String[] { "/usr/bin/open", paramString2.trim(), paramString1 });
}
}
try {
if (process != null && paramBoolean)
process.waitFor();
} catch (InterruptedException e) {}
return process;
}
public static final Process openDocument(String paramString, boolean paramBoolean) throws IOException {
return action(paramString, "", paramBoolean);
}
public static final Process openDocument(File paramFile, boolean paramBoolean) throws IOException {
return openDocument(paramFile.getAbsolutePath(), paramBoolean);
}
public static final Process openDocument(String paramString) throws IOException {
return openDocument(paramString, false);
}
public static final Process openDocument(File paramFile) throws IOException {
return openDocument(paramFile, false);
}
public static final Process printDocument(String paramString, boolean paramBoolean) throws IOException {
return action(paramString, "/p", paramBoolean);
}
public static final Process printDocument(File paramFile, boolean paramBoolean) throws IOException {
return printDocument(paramFile.getAbsolutePath(), paramBoolean);
}
public static final Process printDocument(String paramString) throws IOException {
return printDocument(paramString, false);
}
public static final Process printDocument(File paramFile) throws IOException {
return printDocument(paramFile, false);
}
public static final Process printDocumentSilent(String paramString, boolean paramBoolean) throws IOException {
return action(paramString, "/p /h", paramBoolean);
}
public static final Process printDocumentSilent(File paramFile, boolean paramBoolean) throws IOException {
return printDocumentSilent(paramFile.getAbsolutePath(), paramBoolean);
}
public static final Process printDocumentSilent(String paramString) throws IOException {
return printDocumentSilent(paramString, false);
}
public static final Process printDocumentSilent(File paramFile) throws IOException {
return printDocumentSilent(paramFile, false);
}
public static final void launchBrowser(String paramString) throws IOException {
try {
if (isMac()) {
Class clazz = Class.forName("com.apple.mrj.MRJFileUtils");
Method method = clazz.getDeclaredMethod("openURL", new Class[] { String.class });
method.invoke(null, new Object[] { paramString });
} else if (isWindows()) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + paramString);
} else {
String[] arrayOfString = { "firefox", "opera", "konqueror", "mozilla", "netscape" };
String str = null;
for (int i = 0; i < arrayOfString.length && str == null; i++) {
if (Runtime.getRuntime().exec(new String[] { "which", arrayOfString[i] }).waitFor() == 0)
str = arrayOfString[i];
}
if (str == null)
throw new Exception("Could not find web browser.");
Runtime.getRuntime().exec(new String[] { str, paramString });
}
} catch (Exception e) {
throw new IOException("Error attempting to launch web browser");
}
}
public static boolean isWindows() {
String str = System.getProperty("os.name").toLowerCase();
return (str.indexOf("windows") != -1 || str.indexOf("nt") != -1);
}
public static boolean isWindows9X() {
String str = System.getProperty("os.name").toLowerCase();
return (str.equals("windows 95") || str.equals("windows 98"));
}
public static boolean isMac() {
String str = System.getProperty("os.name").toLowerCase();
return (str.indexOf("mac") != -1);
}
public static boolean isLinux() {
String str = System.getProperty("os.name").toLowerCase();
return (str.indexOf("linux") != -1);
}
}

View file

@ -0,0 +1,78 @@
package com.lowagie.tools;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import java.io.FileOutputStream;
public class HandoutPdf {
public static void main(String[] paramArrayOfString) {
if (paramArrayOfString.length != 3) {
System.err.println("arguments: srcfile destfile pages");
} else {
try {
int i = Integer.parseInt(paramArrayOfString[2]);
if (i < 2 || i > 8)
throw new DocumentException("You can't have " + i + " pages on one page (minimum 2; maximum 8).");
float f1 = 30.0F;
float f2 = 280.0F;
float f3 = 320.0F;
float f4 = 565.0F;
float[] arrayOfFloat1 = new float[i];
float[] arrayOfFloat2 = new float[i];
float f5 = (778.0F - 20.0F * (float)(i - 1)) / (float)i;
arrayOfFloat1[0] = 812.0F;
arrayOfFloat2[0] = 812.0F - f5;
for (int j = 1; j < i; j++) {
arrayOfFloat1[j] = arrayOfFloat2[j - 1] - 20.0F;
arrayOfFloat2[j] = arrayOfFloat1[j] - f5;
}
PdfReader pdfReader = new PdfReader(paramArrayOfString[0]);
int k = pdfReader.getNumberOfPages();
System.out.println("There are " + k + " pages in the original file.");
Document document = new Document(PageSize.A4);
PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(paramArrayOfString[1]));
document.open();
PdfContentByte pdfContentByte = pdfWriter.getDirectContent();
int m = 0;
int n = 0;
while (m < k) {
Rectangle rectangle = pdfReader.getPageSizeWithRotation(++m);
float f6 = (f2 - f1) / rectangle.getWidth();
float f7 = (arrayOfFloat1[n] - arrayOfFloat2[n]) / rectangle.getHeight();
float f8 = (f6 < f7) ? f6 : f7;
float f9 = (f6 == f8) ? 0.0F : ((f2 - f1 - rectangle.getWidth() * f8) / 2.0F);
float f10 = (f7 == f8) ? 0.0F : ((arrayOfFloat1[n] - arrayOfFloat2[n] - rectangle.getHeight() * f8) / 2.0F);
PdfImportedPage pdfImportedPage = pdfWriter.getImportedPage(pdfReader, m);
int i1 = pdfReader.getPageRotation(m);
if (i1 == 90 || i1 == 270) {
pdfContentByte.addTemplate(pdfImportedPage, 0.0F, -f8, f8, 0.0F, f1 + f9, arrayOfFloat2[n] + f10 + rectangle.getHeight() * f8);
} else {
pdfContentByte.addTemplate(pdfImportedPage, f8, 0.0F, 0.0F, f8, f1 + f9, arrayOfFloat2[n] + f10);
}
pdfContentByte.setRGBColorStroke(192, 192, 192);
pdfContentByte.rectangle(f3 - 5.0F, arrayOfFloat2[n] - 5.0F, f4 - f3 + 10.0F, arrayOfFloat1[n] - arrayOfFloat2[n] + 10.0F);
for (float f11 = arrayOfFloat1[n] - 19.0F; f11 > arrayOfFloat2[n]; f11 -= 16.0F) {
pdfContentByte.moveTo(f3, f11);
pdfContentByte.lineTo(f4, f11);
}
pdfContentByte.rectangle(f1 + f9, arrayOfFloat2[n] + f10, rectangle.getWidth() * f8, rectangle.getHeight() * f8);
pdfContentByte.stroke();
System.out.println("Processed page " + m);
if (++n == i) {
n = 0;
document.newPage();
}
}
document.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
}
}
}

View file

@ -0,0 +1,62 @@
package com.lowagie.tools;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import java.io.FileOutputStream;
public class SplitPdf {
public static void main(String[] paramArrayOfString) {
if (paramArrayOfString.length != 4) {
System.err.println("arguments: srcfile destfile1 destfile2 pagenumber");
} else {
try {
int i = Integer.parseInt(paramArrayOfString[3]);
PdfReader pdfReader = new PdfReader(paramArrayOfString[0]);
int j = pdfReader.getNumberOfPages();
System.out.println("There are " + j + " pages in the original file.");
if (i < 2 || i > j)
throw new DocumentException("You can't split this document at page " + i + "; there is no such page.");
Document document1 = new Document(pdfReader.getPageSizeWithRotation(1));
Document document2 = new Document(pdfReader.getPageSizeWithRotation(i));
PdfWriter pdfWriter1 = PdfWriter.getInstance(document1, new FileOutputStream(paramArrayOfString[1]));
PdfWriter pdfWriter2 = PdfWriter.getInstance(document2, new FileOutputStream(paramArrayOfString[2]));
document1.open();
PdfContentByte pdfContentByte1 = pdfWriter1.getDirectContent();
document2.open();
PdfContentByte pdfContentByte2 = pdfWriter2.getDirectContent();
int k = 0;
while (k < i - 1) {
document1.setPageSize(pdfReader.getPageSizeWithRotation(++k));
document1.newPage();
PdfImportedPage pdfImportedPage = pdfWriter1.getImportedPage(pdfReader, k);
int m = pdfReader.getPageRotation(k);
if (m == 90 || m == 270) {
pdfContentByte1.addTemplate(pdfImportedPage, 0.0F, -1.0F, 1.0F, 0.0F, 0.0F, pdfReader.getPageSizeWithRotation(k).getHeight());
continue;
}
pdfContentByte1.addTemplate(pdfImportedPage, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F);
}
while (k < j) {
document2.setPageSize(pdfReader.getPageSizeWithRotation(++k));
document2.newPage();
PdfImportedPage pdfImportedPage = pdfWriter2.getImportedPage(pdfReader, k);
int m = pdfReader.getPageRotation(k);
if (m == 90 || m == 270) {
pdfContentByte2.addTemplate(pdfImportedPage, 0.0F, -1.0F, 1.0F, 0.0F, 0.0F, pdfReader.getPageSizeWithRotation(k).getHeight());
} else {
pdfContentByte2.addTemplate(pdfImportedPage, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F);
}
System.out.println("Processed page " + k);
}
document1.close();
document2.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View file

@ -0,0 +1,22 @@
package com.lowagie.tools;
import com.lowagie.text.Document;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
public class ToolboxAvailable {
public static void main(String[] paramArrayOfString) {
if (GraphicsEnvironment.isHeadless()) {
System.out.println(Document.getVersion() + " Toolbox error: headless display");
} else {
try {
Class clazz = Class.forName("com.lowagie.toolbox.Toolbox");
Method method = clazz.getMethod("main", new Class[] { paramArrayOfString.getClass() });
method.invoke(null, new Object[] { paramArrayOfString });
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "You need the iText-toolbox.jar with class com.lowagie.toolbox.Toolbox to use the iText Toolbox.", Document.getVersion() + " Toolbox error", 0);
}
}
}
}