use of com.tom_roush.pdfbox.pdmodel.PDPageContentStream in project PdfBox-Android by TomRoush.
the class TestFontEmbedding method testMaxEntries.
/**
* Test corner case of PDFBOX-4302.
*
* @throws java.io.IOException
*/
@Test
public void testMaxEntries() throws IOException {
File file;
String text;
text = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" + "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" + "12345678";
// The test must have MAX_ENTRIES_PER_OPERATOR unique characters
Set<Character> set = new HashSet<Character>(ToUnicodeWriter.MAX_ENTRIES_PER_OPERATOR);
for (int i = 0; i < text.length(); ++i) {
set.add(text.charAt(i));
}
assertEquals(ToUnicodeWriter.MAX_ENTRIES_PER_OPERATOR, set.size());
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A0);
document.addPage(page);
File ipafont = new File("target/fonts/ipag00303", "ipag.ttf");
assumeTrue(ipafont.exists());
PDType0Font font = PDType0Font.load(document, ipafont);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(font, 20);
contentStream.newLineAtOffset(50, 3000);
contentStream.showText(text);
contentStream.endText();
contentStream.close();
file = new File(OUT_DIR, "PDFBOX-4302-test.pdf");
document.save(file);
document.close();
// check that the extracted text matches what we wrote
String extracted = getUnicodeText(file);
assertEquals(text, extracted.trim());
}
use of com.tom_roush.pdfbox.pdmodel.PDPageContentStream in project PdfBox-Android by TomRoush.
the class TestFontEncoding method testPDFBox3884.
/**
* PDFBOX-3826: Some unicodes are reached by several names in glyphlist.txt, e.g. tilde and
* ilde.
*
* @throws IOException
*/
public void testPDFBox3884() throws IOException {
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
PDPageContentStream cs = new PDPageContentStream(doc, page);
cs.setFont(PDType1Font.HELVETICA, 20);
cs.beginText();
cs.newLineAtOffset(100, 700);
// first tilde is "asciitilde" (from the keyboard), 2nd tilde is "tilde"
// using ˜ would bring IllegalArgumentException prior to bugfix
cs.showText("~˜");
cs.endText();
cs.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos);
doc.close();
// verify
doc = PDDocument.load(baos.toByteArray());
PDFTextStripper stripper = new PDFTextStripper();
String text = stripper.getText(doc);
assertEquals("~˜", text.trim());
doc.close();
}
Aggregations