@Test public void write_long_filename_that_needs_truncation() throws TaskException { PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); new FilenameFooterWriter(true, doc).addFooter(page, "My very long title that will not fit on the page and needs to be truncated so that it will not overflow and cover the page number and generally look not so nice", 20); assertPageFooterText(page,"My very long title that will not fit on the page and needs to be truncated so that it will not overflow and cover the page number a20"); }
public void addFooter(PDPage page, String fileName, long pageNumber) throws TaskException { if (addFooter) { try { String truncatedFilename = truncateIfRequired(fileName, maxWidth(page, pageNumber)); writer.write(page, HorizontalAlign.LEFT, VerticalAlign.BOTTOM, truncatedFilename, FONT, FONT_SIZE, Color.BLACK); writer.write(page, HorizontalAlign.RIGHT, VerticalAlign.BOTTOM, Long.toString(pageNumber), FONT, FONT_SIZE, Color.BLACK); } catch (TaskIOException | IOException e) { throw new TaskException("Unable to write the page footer", e); } } }
FilenameFooterWriter { public void addFooter(PDPage page, String fileName, long pageNumber) throws TaskException { if (addFooter) { try { String truncatedFilename = truncateIfRequired(fileName, maxWidth(page, pageNumber)); writer.write(page, HorizontalAlign.LEFT, VerticalAlign.BOTTOM, truncatedFilename, FONT, FONT_SIZE, Color.BLACK); writer.write(page, HorizontalAlign.RIGHT, VerticalAlign.BOTTOM, Long.toString(pageNumber), FONT, FONT_SIZE, Color.BLACK); } catch (TaskIOException | IOException e) { throw new TaskException("Unable to write the page footer", e); } } } }
FilenameFooterWriter { public void addFooter(PDPage page, String fileName, long pageNumber) throws TaskException { if (addFooter) { try { String truncatedFilename = truncateIfRequired(fileName, maxWidth(page, pageNumber)); writer.write(page, HorizontalAlign.LEFT, VerticalAlign.BOTTOM, truncatedFilename, FONT, FONT_SIZE, Color.BLACK); writer.write(page, HorizontalAlign.RIGHT, VerticalAlign.BOTTOM, Long.toString(pageNumber), FONT, FONT_SIZE, Color.BLACK); } catch (TaskIOException | IOException e) { throw new TaskException("Unable to write the page footer", e); } } } FilenameFooterWriter(boolean addFooter, PDDocument document); }
FilenameFooterWriter { public void addFooter(PDPage page, String fileName, long pageNumber) throws TaskException { if (addFooter) { try { String truncatedFilename = truncateIfRequired(fileName, maxWidth(page, pageNumber)); writer.write(page, HorizontalAlign.LEFT, VerticalAlign.BOTTOM, truncatedFilename, FONT, FONT_SIZE, Color.BLACK); writer.write(page, HorizontalAlign.RIGHT, VerticalAlign.BOTTOM, Long.toString(pageNumber), FONT, FONT_SIZE, Color.BLACK); } catch (TaskIOException | IOException e) { throw new TaskException("Unable to write the page footer", e); } } } FilenameFooterWriter(boolean addFooter, PDDocument document); void addFooter(PDPage page, String fileName, long pageNumber); }
FilenameFooterWriter { public void addFooter(PDPage page, String fileName, long pageNumber) throws TaskException { if (addFooter) { try { String truncatedFilename = truncateIfRequired(fileName, maxWidth(page, pageNumber)); writer.write(page, HorizontalAlign.LEFT, VerticalAlign.BOTTOM, truncatedFilename, FONT, FONT_SIZE, Color.BLACK); writer.write(page, HorizontalAlign.RIGHT, VerticalAlign.BOTTOM, Long.toString(pageNumber), FONT, FONT_SIZE, Color.BLACK); } catch (TaskIOException | IOException e) { throw new TaskException("Unable to write the page footer", e); } } } FilenameFooterWriter(boolean addFooter, PDDocument document); void addFooter(PDPage page, String fileName, long pageNumber);  }