| 1 |
package org.sejda.impl.sambox.util; |
| 2 |
|
| 3 |
import org.sejda.impl.sambox.component.DefaultPdfSourceOpener; |
| 4 |
import org.sejda.model.exception.TaskIOException; |
| 5 |
import org.sejda.model.input.PdfFileSource; |
| 6 |
import org.sejda.model.input.PdfStreamSource; |
| 7 |
import org.sejda.sambox.pdmodel.PDDocument; |
| 8 |
|
| 9 |
import java.io.File; |
| 10 |
|
| 11 |
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; |
| 12 |
|
| 13 |
public class TestUtils { |
| 14 |
|
| 15 |
public static PDDocument getTestDoc(String name) throws TaskIOException { |
| 16 |
File file = new File(name); |
| 17 |
if(file.exists()) { |
| 18 |
PdfFileSource source = PdfFileSource.newInstanceNoPassword(file); |
| 19 |
return new DefaultPdfSourceOpener().open(source).getUnderlyingPDDocument(); |
| 20 |
} |
| 21 |
|
| 22 |
PdfStreamSource source = PdfStreamSource.newInstanceNoPassword( |
| 23 |
TestUtils.class.getClassLoader().getResourceAsStream(name), randomAlphanumeric(16) + ".pdf"); |
| 24 |
|
| 25 |
return new DefaultPdfSourceOpener().open(source).getUnderlyingPDDocument(); |
| 26 |
} |
| 27 |
} |