本文整理汇总了Java中org.sejda.io.SeekableSources类的典型用法代码示例。如果您正苦于以下问题:Java SeekableSources类的具体用法?Java SeekableSources怎么用?Java SeekableSources使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SeekableSources类属于org.sejda.io包,在下文中一共展示了SeekableSources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkJpegStream
import org.sejda.io.SeekableSources; //导入依赖的package包/类
private void checkJpegStream(File testResultsDir, String filename, InputStream resourceStream)
throws IOException
{
try (PDDocument doc = PDFParser
.parse(SeekableSources.seekableSourceFrom(new File(testResultsDir, filename))))
{
PDImageXObject img = (PDImageXObject) doc.getPage(0).getResources()
.getXObject(COSName.getPDFName("Im1"));
InputStream dctStream = img.getCOSObject().getFilteredStream();
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
IOUtils.copy(resourceStream, baos1);
IOUtils.copy(dctStream, baos2);
resourceStream.close();
dctStream.close();
assertArrayEquals(baos1.toByteArray(), baos2.toByteArray());
}
}
示例2: indexOfPageFromOutlineDestination
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void indexOfPageFromOutlineDestination() throws IOException
{
try (PDDocument doc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
PDPageTreeTest.class.getResourceAsStream("with_outline.pdf"))))
{
PDDocumentOutline outline = doc.getDocumentCatalog().getDocumentOutline();
for (PDOutlineItem current : outline.children())
{
if (current.getTitle().contains("Second"))
{
assertEquals(2, doc.getPages().indexOf(current.findDestinationPage(doc)));
}
}
}
}
示例3: pageNotFoundIncludesSourcePathAndPageNumber
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void pageNotFoundIncludesSourcePathAndPageNumber() throws IOException
{
try (PDDocument doc = PDFParser.parse(SeekableSources.onTempFileSeekableSourceFrom(
PDPageTreeTest.class.getResourceAsStream("with_outline.pdf"))))
{
try {
doc.getPage(99 /* 0 based */);
fail("Exception expected");
} catch (PageNotFoundException ex) {
assertEquals(ex.getPage(), 100 /* 1 based, for humans */);
assertThat(ex.getSourcePath(), containsString(File.separator + "SejdaIO"));
assertThat(ex.getSourcePath(), endsWith(".tmp"));
}
}
}
示例4: readTransitions
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void readTransitions() throws IOException
{
try (PDDocument doc = PDFParser
.parse(SeekableSources
.inMemorySeekableSourceFrom(getClass()
.getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/pagenavigation/transitions_test.pdf"))))
{
PDTransition firstTransition = doc.getPages().get(0).getTransition();
assertEquals(PDTransitionStyle.Glitter.name(), firstTransition.getStyle());
assertEquals(2, firstTransition.getDuration(), 0);
assertEquals(PDTransitionDirection.TOP_LEFT_TO_BOTTOM_RIGHT.getCOSBase(),
firstTransition.getDirection());
}
}
示例5: testSaveLoadStream
import org.sejda.io.SeekableSources; //导入依赖的package包/类
/**
* Test document save/load using a stream.
*
* @throws IOException if something went wrong
*/
public void testSaveLoadStream() throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create PDF with one blank page
try (PDDocument document = new PDDocument())
{
document.addPage(new PDPage());
document.writeTo(baos);
}
// Verify content
byte[] pdf = baos.toByteArray();
assertTrue(pdf.length > 200);
assertEquals("%PDF-1.4", new String(Arrays.copyOfRange(pdf, 0, 8), "UTF-8"));
assertEquals("%%EOF\n",
new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), "UTF-8"));
// Load
try (PDDocument loadDoc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(pdf)))
{
assertEquals(1, loadDoc.getNumberOfPages());
}
}
示例6: testWidgetMissingRect
import org.sejda.io.SeekableSources; //导入依赖的package包/类
/**
* This will test the handling of a widget with a missing (required) /Rect entry.
*
* @throws IOException If there is an error loading the form or the field.
*/
@Test
public void testWidgetMissingRect() throws IOException
{
try (PDDocument doc = PDFParser
.parse(SeekableSources.inMemorySeekableSourceFrom(getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/AcroFormsBasicFields.pdf"))))
{
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
PDTextField textField = (PDTextField) form.getField("TextField-DefaultValue");
PDAnnotationWidget widget = textField.getWidgets().get(0);
// initially there is an Appearance Entry in the form
assertNotNull(widget.getCOSObject().getDictionaryObject(COSName.AP));
widget.getCOSObject().removeItem(COSName.RECT);
textField.setValue("field value");
// There shall be no appearance entry if there is no /Rect to
// behave as Adobe Acrobat does
assertNull(widget.getCOSObject().getDictionaryObject(COSName.AP));
}
}
示例7: setUp
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Before
public void setUp() throws IOException
{
document = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(this.getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/DifferentDALevels.pdf")));
acroForm = document.getDocumentCatalog().getAcroForm();
// prefill the fields to generate the appearance streams
PDTextField field = (PDTextField) acroForm.getField("SingleAnnotation");
field.setValue("single annotation");
field = (PDTextField) acroForm.getField("MultipeAnnotations-SameLayout");
field.setValue("same layout");
field = (PDTextField) acroForm.getField("MultipleAnnotations-DifferentLayout");
field.setValue("different layout");
}
示例8: testRadioButtonWithOptions
import org.sejda.io.SeekableSources; //导入依赖的package包/类
/**
* PDFBOX-3656
*
* Test a radio button with options. This was causing an ArrayIndexOutOfBoundsException when trying to set to "Off",
* as this wasn't treated to be a valid option.
*
* @throws IOException
*/
@Test
public void testRadioButtonWithOptions() throws IOException
{
try (PDDocument document = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(this.getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/radio_with_options.pdf"))))
{
PDRadioButton radioButton = (PDRadioButton) document.getDocumentCatalog().getAcroForm()
.getField("Checking/Savings");
radioButton.setValue("Off");
for (PDAnnotationWidget widget : radioButton.getWidgets())
{
assertEquals("The widget should be set to Off", COSName.Off,
widget.getCOSObject().getItem(COSName.AS));
}
}
}
示例9: testRadioButtonWithOptionsThatDontMatchNormalAppearance
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void testRadioButtonWithOptionsThatDontMatchNormalAppearance() throws IOException
{
try (PDDocument document = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(this.getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/simple_form.pdf"))))
{
PDRadioButton radioButton = (PDRadioButton) document.getDocumentCatalog().getAcroForm()
.getField("Choice_Caption_0wUBrGuJDKIWD9g7kWcKpg");
radioButton.setValue("1");
radioButton.setValue("Second Choice");
assertEquals("Export value does not exist in normal appearance. Don't export value",
radioButton.getValue(), "1");
assertEquals("First widget should be Off", COSName.Off,
radioButton.getWidgets().get(0).getCOSObject().getItem(COSName.AS));
assertEquals("Second widget should be set to 1", COSName.getPDFName("1"),
radioButton.getWidgets().get(1).getCOSObject().getItem(COSName.AS));
}
}
示例10: testRadioButtonWithOptionsThatDoMatchNormalAppearance
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void testRadioButtonWithOptionsThatDoMatchNormalAppearance() throws IOException
{
try (PDDocument document = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(this.getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/PDFBOX-3656 - test.pdf"))))
{
PDRadioButton radioButton = (PDRadioButton) document.getDocumentCatalog().getAcroForm()
.getField("RadioButton");
radioButton.setValue("c");
assertEquals("Export value does exist in normal appearance. Do export value",
radioButton.getValue(), "c");
assertEquals("First widget should be Off", COSName.Off,
radioButton.getWidgets().get(0).getCOSObject().getItem(COSName.AS));
assertEquals("Second widget should be Off", COSName.Off,
radioButton.getWidgets().get(1).getCOSObject().getItem(COSName.AS));
assertEquals("Third widget should be set to c", COSName.getPDFName("c"),
radioButton.getWidgets().get(2).getCOSObject().getItem(COSName.AS));
}
}
示例11: testFlattenWidgetNoRef
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void testFlattenWidgetNoRef() throws IOException
{
try (PDDocument doc = PDFParser
.parse(SeekableSources.inMemorySeekableSourceFrom(getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/AlignmentTests.pdf"))))
{
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
for (PDField field : acroForm.getFieldTree())
{
for (PDAnnotationWidget widget : field.getWidgets())
{
widget.getCOSObject().removeItem(COSName.P);
}
}
doc.getDocumentCatalog().getAcroForm().flatten();
assertTrue(doc.getDocumentCatalog().getAcroForm().getFields().isEmpty());
}
}
示例12: doTest
import org.sejda.io.SeekableSources; //导入依赖的package包/类
private void doTest(WriteOption... options) throws IOException
{
try (PDDocument current = PDFParser.parse(SeekableSources
.inMemorySeekableSourceFrom(getClass().getResourceAsStream(inputFile)), pwd))
{
try (ByteArrayOutputStream out = new ByteArrayOutputStream())
{
current.writeTo(out, options);
try (PDDocument outDoc = PDFParser
.parse(SeekableSources.inMemorySeekableSourceFrom(out.toByteArray())))
{
assertTrue(outDoc.getNumberOfPages() > 0);
}
}
}
}
示例13: doTestEncrypted
import org.sejda.io.SeekableSources; //导入依赖的package包/类
private void doTestEncrypted(StandardSecurity security, WriteOption... options)
throws IOException
{
try (PDDocument current = PDFParser.parse(SeekableSources
.inMemorySeekableSourceFrom(getClass().getResourceAsStream(inputFile)), pwd))
{
try (ByteArrayOutputStream out = new ByteArrayOutputStream())
{
current.writeTo(out, security, options);
try (PDDocument outDoc = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(out.toByteArray()),
new String(security.userPassword)))
{
assertTrue(outDoc.getNumberOfPages() > 0);
}
}
}
}
示例14: setVersion
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void setVersion() throws IOException
{
try (IncrementablePDDocument incrementable = PDFParser
.parseToIncrement(SeekableSources.inMemorySeekableSourceFrom(
getClass().getResourceAsStream("/sambox/simple_test.pdf"))))
{
incrementable.setVersion(SpecVersionUtils.V1_4);
assertTrue(incrementable.replacements().isEmpty());
incrementable.setVersion(SpecVersionUtils.V1_5);
assertTrue(incrementable.replacements().isEmpty());
incrementable.setVersion(SpecVersionUtils.V1_6);
assertFalse(incrementable.replacements().isEmpty());
IndirectCOSObjectReference catalogReplacement = incrementable.replacements().get(0);
assertEquals(new COSObjectKey(1, 0), catalogReplacement.xrefEntry().key());
assertEquals(SpecVersionUtils.V1_6, ((COSDictionary) catalogReplacement.getCOSObject())
.getNameAsString(COSName.VERSION));
}
}
示例15: requireMinVersion
import org.sejda.io.SeekableSources; //导入依赖的package包/类
@Test
public void requireMinVersion() throws IOException
{
try (IncrementablePDDocument incrementable = PDFParser
.parseToIncrement(SeekableSources.inMemorySeekableSourceFrom(
getClass().getResourceAsStream("/sambox/simple_test.pdf"))))
{
incrementable.requireMinVersion(SpecVersionUtils.V1_4);
assertTrue(incrementable.replacements().isEmpty());
incrementable.requireMinVersion(SpecVersionUtils.V1_5);
assertTrue(incrementable.replacements().isEmpty());
incrementable.requireMinVersion(SpecVersionUtils.V1_6);
assertFalse(incrementable.replacements().isEmpty());
IndirectCOSObjectReference catalogReplacement = incrementable.replacements().get(0);
assertEquals(new COSObjectKey(1, 0), catalogReplacement.xrefEntry().key());
assertEquals(SpecVersionUtils.V1_6, ((COSDictionary) catalogReplacement.getCOSObject())
.getNameAsString(COSName.VERSION));
}
}