private void prepareOutputDirs(String outPath, String differenceImagePrefix) { File[] imageFiles; File[] cmpImageFiles; File[] diffFiles; if (!FileUtil.directoryExists(outPath)) { FileUtil.createDirectories(outPath); } else { imageFiles = FileUtil.listFilesInDirectoryByFilter(outPath, new PngFileFilter()); for (File file : imageFiles) { file.delete(); } cmpImageFiles = FileUtil.listFilesInDirectoryByFilter(outPath, new CmpPngFileFilter()); for (File file : cmpImageFiles) { file.delete(); } diffFiles = FileUtil.listFilesInDirectoryByFilter(outPath, new DiffPngFileFilter(differenceImagePrefix)); for (File file : diffFiles) { file.delete(); } } }
/** Creates a new instance of Pfm2afm */ private Pfm2afm(RandomAccessFileOrArray input, OutputStream output) throws java.io.IOException { this.input = input; this.output = FileUtil.createPrintWriter(output, "ISO-8859-1"); }
/** * Create a PdfWriter writing to the passed filename and using the passed writer properties. * * @param filename filename of the resulting pdf. * @param properties writerproperties to use. * @throws FileNotFoundException */ public PdfWriter(String filename, WriterProperties properties) throws FileNotFoundException { this(FileUtil.getBufferedOutputStream(filename), properties); }
/** * Add all the fonts in a directory and possibly its subdirectories. * * @param dir path to directory. * @param scanSubdirectories recursively scan subdirectories if {@code true}. * @return number of added fonts. */ public int addDirectory(String dir, boolean scanSubdirectories) { int count = 0; String[] files = FileUtil.listFilesInDirectory(dir, scanSubdirectories); if (files == null) return 0; for (String file : files) { try { String suffix = file.length() < 4 ? null : file.substring(file.length() - 4).toLowerCase(); if (".afm".equals(suffix) || ".pfm".equals(suffix)) { // Add only Type 1 fonts with matching .pfb files. String pfb = file.substring(0, file.length() - 4) + ".pfb"; if (FileUtil.fileExists(pfb) && addFont(file)) { count++; } } else if ((".ttf".equals(suffix) || ".otf".equals(suffix) || ".ttc".equals(suffix)) && addFont(file)) { count++; } } catch (Exception ignored) { } } return count; }
public int addSystemFonts() { int count = 0; String[] withSubDirs = { FileUtil.getFontsDir(), "/usr/share/X11/fonts", "/usr/X/lib/X11/fonts", "/usr/openwin/lib/X11/fonts", "/usr/share/fonts", "/usr/X11R6/lib/X11/fonts" }; for (String directory : withSubDirs) { count += fontSet.addDirectory(directory, true); } String[] withoutSubDirs = { "/Library/Fonts", "/System/Library/Fonts" }; for (String directory : withoutSubDirs) { count += fontSet.addDirectory(directory, false); } return count; }
/** * Creates a new {@link TrueTypeCollection} instance by its file path. * * @param ttcPath the path of the collection * @throws java.io.IOException in case the input in mal-formatted */ public TrueTypeCollection(String ttcPath) throws java.io.IOException { if (!FileUtil.fileExists(ttcPath)) { throw new IOException(IOException.FontFile1NotFound).setMessageParams(ttcPath); } raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createBestSource(ttcPath)); this.ttcPath = ttcPath; initFontSize(); }
/** * Creates a PdfSigner instance. Uses a {@link java.io.ByteArrayOutputStream} instead of a temporary file. * * @param reader PdfReader that reads the PDF file * @param outputStream OutputStream to write the signed PDF file * @param path File to which the output is temporarily written * @param properties {@link StampingProperties} for the signing document. Note that encryption will be * preserved regardless of what is set in properties. * @throws IOException */ public PdfSigner(PdfReader reader, OutputStream outputStream, String path, StampingProperties properties) throws IOException { StampingProperties localProps = new StampingProperties(properties).preserveEncryption(); if (path == null) { temporaryOS = new ByteArrayOutputStream(); document = initDocument(reader, new PdfWriter(temporaryOS), localProps); } else { this.tempFile = FileUtil.createTempFile(path); document = initDocument(reader, new PdfWriter(FileUtil.getFileOutputStream(tempFile)), localProps); } originalOS = outputStream; signDate = DateTimeUtil.getCurrentTimeCalendar(); fieldName = getNewSigFieldName(); appearance = new PdfSignatureAppearance(document, new Rectangle(0, 0), 1); appearance.setSignDate(signDate); closed = false; }
/** * Runs ghostscript to create images of pdfs. * * @param outPath Path to the output folder. * @throws CompareToolExecutionException * @throws IOException * @throws InterruptedException */ private void runGhostScriptImageGeneration(String outPath) throws IOException, InterruptedException { if (!FileUtil.directoryExists(outPath)) { throw new CompareToolExecutionException(cannotOpenOutputDirectory.replace("<filename>", outPdf)); } String currGsParams = gsParams.replace("<outputfile>", outPath + cmpImage).replace("<inputfile>", cmpPdf); if (!SystemUtil.runProcessAndWait(gsExec, currGsParams)) { throw new CompareToolExecutionException(gsFailed.replace("<filename>", cmpPdf)); } currGsParams = gsParams.replace("<outputfile>", outPath + outImage).replace("<inputfile>", outPdf); if (!SystemUtil.runProcessAndWait(gsExec, currGsParams)) { throw new CompareToolExecutionException(gsFailed.replace("<filename>", outPdf)); } }
/** * Converts SVG stored in a {@link File} to a PDF {@link File}, * using specific {@link ISvgConverterProperties} and {@link WriterProperties}. * * @param svgFile the {@link File} containing the source SVG * @param pdfFile the {@link File} containing the resulting PDF * @param props a {@link ISvgConverterProperties} instance * @param writerProps a {@link WriterProperties} for the pdf document * @throws IOException Signals that an I/O exception has occurred. */ public static void createPdf(File svgFile, File pdfFile, ISvgConverterProperties props, WriterProperties writerProps) throws IOException { if (props == null) { props = new SvgConverterProperties().setBaseUri(FileUtil.getParentDirectory(svgFile)); } else if (props.getBaseUri() == null || props.getBaseUri().isEmpty()) { String baseUri = FileUtil.getParentDirectory(svgFile); props = convertToSvgConverterProps(props, baseUri); } try (FileInputStream fileInputStream = new FileInputStream(svgFile.getAbsolutePath()); FileOutputStream fileOutputStream = new FileOutputStream(pdfFile.getAbsolutePath())) { createPdf(fileInputStream, fileOutputStream, props, writerProps); } }
/** * Add all the fonts in a directory and possibly its subdirectories. * * @param dir path to directory. * @param scanSubdirectories recursively scan subdirectories if {@code true}. * @return number of added fonts. */ public int addDirectory(String dir, boolean scanSubdirectories) { int count = 0; String[] files = FileUtil.listFilesInDirectory(dir, scanSubdirectories); if (files == null) return 0; for (String file : files) { try { String suffix = file.length() < 4 ? null : file.substring(file.length() - 4).toLowerCase(); if (".afm".equals(suffix) || ".pfm".equals(suffix)) { // Add only Type 1 fonts with matching .pfb files. String pfb = file.substring(0, file.length() - 4) + ".pfb"; if (FileUtil.fileExists(pfb) && addFont(file)) { count++; } } else if ((".ttf".equals(suffix) || ".otf".equals(suffix) || ".ttc".equals(suffix)) && addFont(file)) { count++; } } catch (Exception ignored) { } } return count; }
public int addSystemFonts() { int count = 0; String[] withSubDirs = { FileUtil.getFontsDir(), "/usr/share/X11/fonts", "/usr/X/lib/X11/fonts", "/usr/openwin/lib/X11/fonts", "/usr/share/fonts", "/usr/X11R6/lib/X11/fonts" }; for (String directory : withSubDirs) { count += fontSet.addDirectory(directory, true); } String[] withoutSubDirs = { "/Library/Fonts", "/System/Library/Fonts" }; for (String directory : withoutSubDirs) { count += fontSet.addDirectory(directory, false); } return count; }
/** * Creates a new {@link TrueTypeCollection} instance by its file path. * * @param ttcPath the path of the collection * @throws java.io.IOException in case the input in mal-formatted */ public TrueTypeCollection(String ttcPath) throws java.io.IOException { if (!FileUtil.fileExists(ttcPath)) { throw new IOException(IOException.FontFile1NotFound).setMessageParams(ttcPath); } raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createBestSource(ttcPath)); this.ttcPath = ttcPath; initFontSize(); }
/** * Creates a PdfSigner instance. Uses a {@link java.io.ByteArrayOutputStream} instead of a temporary file. * * @param reader PdfReader that reads the PDF file * @param outputStream OutputStream to write the signed PDF file * @param path File to which the output is temporarily written * @param properties {@link StampingProperties} for the signing document. Note that encryption will be * preserved regardless of what is set in properties. * @throws IOException */ public PdfSigner(PdfReader reader, OutputStream outputStream, String path, StampingProperties properties) throws IOException { StampingProperties localProps = new StampingProperties(properties).preserveEncryption(); if (path == null) { temporaryOS = new ByteArrayOutputStream(); document = initDocument(reader, new PdfWriter(temporaryOS), localProps); } else { this.tempFile = FileUtil.createTempFile(path); document = initDocument(reader, new PdfWriter(FileUtil.getFileOutputStream(tempFile)), localProps); } originalOS = outputStream; signDate = DateTimeUtil.getCurrentTimeCalendar(); fieldName = getNewSigFieldName(); appearance = new PdfSignatureAppearance(document, new Rectangle(0, 0), 1); appearance.setSignDate(signDate); closed = false; }
int count = 0; try { String[] files = FileUtil.listFilesInDirectory(dir, scanSubdirectories); if (files == null) return 0; if (FileUtil.fileExists(pfb)) { registerFont(file, null); ++count;
/** * Register fonts in some probable directories. It usually works in Windows, * Linux and Solaris. * * @return the number of fonts registered */ int registerSystemFontDirectories() { int count = 0; String[] withSubDirs = { FileUtil.getFontsDir(), "/usr/share/X11/fonts", "/usr/X/lib/X11/fonts", "/usr/openwin/lib/X11/fonts", "/usr/share/fonts", "/usr/X11R6/lib/X11/fonts" }; for (String directory : withSubDirs) { count += registerFontDirectory(directory, true); } String[] withoutSubDirs = { "/Library/Fonts", "/System/Library/Fonts" }; for (String directory : withoutSubDirs) { count += registerFontDirectory(directory, false); } return count; }
/** Creates a new instance of Pfm2afm */ private Pfm2afm(RandomAccessFileOrArray input, OutputStream output) throws java.io.IOException { this.input = input; this.output = FileUtil.createPrintWriter(output, "ISO-8859-1"); }
int count = 0; try { String[] files = FileUtil.listFilesInDirectory(dir, scanSubdirectories); if (files == null) return 0; if (FileUtil.fileExists(pfb)) { registerFont(file, null); ++count;
/** * Register fonts in some probable directories. It usually works in Windows, * Linux and Solaris. * * @return the number of fonts registered */ int registerSystemFontDirectories() { int count = 0; String[] withSubDirs = { FileUtil.getFontsDir(), "/usr/share/X11/fonts", "/usr/X/lib/X11/fonts", "/usr/openwin/lib/X11/fonts", "/usr/share/fonts", "/usr/X11R6/lib/X11/fonts" }; for (String directory : withSubDirs) { count += registerFontDirectory(directory, true); } String[] withoutSubDirs = { "/Library/Fonts", "/System/Library/Fonts" }; for (String directory : withoutSubDirs) { count += registerFontDirectory(directory, false); } return count; }