()
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public Integer call() |
| 166 | { |
| 167 | try (PDDocument doc = new PDDocument()) |
| 168 | { |
| 169 | if (ttf != null) |
| 170 | { |
| 171 | font = PDType0Font.load(doc, ttf); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | font = new PDType1Font(standardFont); |
| 176 | } |
| 177 | |
| 178 | setFont(font); |
| 179 | setFontSize(fontSize); |
| 180 | setMediaBox(pageSize.getPageSize()); |
| 181 | setLandscape(landscape); |
| 182 | setLineSpacing(lineSpacing); |
| 183 | setLeftMargin(margins[0]); |
| 184 | setRightMargin(margins[1]); |
| 185 | setTopMargin(margins[2]); |
| 186 | setBottomMargin(margins[3]); |
| 187 | |
| 188 | try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(infile))) |
| 189 | { |
| 190 | if (charset.equals(StandardCharsets.UTF_8)) |
| 191 | { |
| 192 | final int readLimit = 3; |
| 193 | is.mark(readLimit); |
| 194 | |
| 195 | byte[] firstBytes = new byte[readLimit]; |
| 196 | if (is.read(firstBytes) != readLimit) |
| 197 | { |
| 198 | throw new IOException("Could not read 3 bytes, size changed?!"); |
| 199 | } |
| 200 | |
| 201 | if (firstBytes[0] == (byte) 0xEF && |
| 202 | firstBytes[1] == (byte) 0xBB && |
| 203 | firstBytes[2] == (byte) 0xBF) |
| 204 | { |
| 205 | //UTF-8 with BOM |
| 206 | //3 bytes already read (skipped) |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | //It looks like UTF with no BOM or file was corrupted |
| 211 | is.reset(); |
| 212 | } |
| 213 | } |
| 214 | try (Reader reader = new InputStreamReader(is, charset)) |
| 215 | { |
| 216 | createPDFFromText(doc, reader); |
| 217 | } |
| 218 | } |
| 219 | doc.save(outfile); |
| 220 | } |
| 221 | catch (IOException ioe) |
nothing calls this directly
no test coverage detected