本文整理匯總了Java中org.sejda.sambox.pdmodel.PDDocument類的典型用法代碼示例。如果您正苦於以下問題:Java PDDocument類的具體用法?Java PDDocument怎麽用?Java PDDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PDDocument類屬於org.sejda.sambox.pdmodel包,在下文中一共展示了PDDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PDType0Font
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
/**
* Private. Creates a new TrueType font for embedding.
*/
private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset,
boolean closeOnSubset)
throws IOException
{
embedder = new PDCIDFontType2Embedder(document, dict, ttf, embedSubset, this);
descendantFont = embedder.getCIDFont();
readEncoding();
fetchCMapUCS2();
if (closeOnSubset)
{
if (embedSubset)
{
this.ttf = ttf;
}
else
{
// the TTF is fully loaded and it is safe to close the underlying data source
ttf.close();
}
}
}
示例2: writeText
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
/**
* This will take a PDDocument and write the text of that document to the print writer.
*
* @param doc The document to get the data from.
* @param outputStream The location to put the text.
*
* @throws IOException If the doc is in an invalid state.
*/
public void writeText(PDDocument doc, Writer outputStream) throws IOException
{
resetEngine();
document = doc;
output = outputStream;
if (getAddMoreFormatting())
{
paragraphEnd = lineSeparator;
pageStart = lineSeparator;
articleStart = lineSeparator;
articleEnd = lineSeparator;
}
startDocument(document);
processPages(document.getPages());
endDocument(document);
}
示例3: write
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
/**
* Writes the {@link PDDocument}.
*
* @param document
* @throws IOException
*/
public void write(PDDocument document) throws IOException
{
requireNotNullArg(document, "PDDocument cannot be null");
if (context.hasWriteOption(WriteOption.XREF_STREAM)
|| context.hasWriteOption(WriteOption.OBJECT_STREAMS))
{
document.requireMinVersion(SpecVersionUtils.V1_5);
}
ofNullable(document.getDocument().getTrailer()).map(t -> t.getCOSObject())
.ifPresent(t -> t.removeItem(COSName.ENCRYPT));
encryptionContext.ifPresent(c -> {
document.getDocument()
.setEncryptionDictionary(c.security.encryption.generateEncryptionDictionary(c));
LOG.debug("Generated encryption dictionary");
ofNullable(document.getDocumentCatalog().getMetadata()).map(m -> m.getCOSObject())
.ifPresent(str -> str.encryptable(c.security.encryptMetadata));
});
writer.writeHeader(document.getDocument().getHeaderVersion());
writeBody(document.getDocument());
writeXref(document);
}
示例4: testPDFBox3208
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
@Test
public void testPDFBox3208() throws IOException
{
try (PDDocument doc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(getClass()
.getResourceAsStream(
"/org/sejda/sambox/input/PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf"))))
{
PDDocumentInformation di = doc.getDocumentInformation();
assertEquals("Liquent Enterprise Services", di.getAuthor());
assertEquals("Liquent services server", di.getCreator());
assertEquals("Amyuni PDF Converter version 4.0.0.9", di.getProducer());
assertEquals("", di.getKeywords());
assertEquals("", di.getSubject());
assertEquals("892B77DE781B4E71A1BEFB81A51A5ABC_20140326022424.docx", di.getTitle());
assertEquals(DateConverter.toCalendar("D:20140326142505-02'00'"), di.getCreationDate());
assertEquals(DateConverter.toCalendar("20140326172513Z"), di.getModificationDate());
}
}
示例5: doParse
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
private static PDDocument doParse(DecryptionMaterial decryptionMaterial, COSParser parser)
throws IOException
{
String headerVersion = readHeader(parser);
LOG.trace("Parsed header version: " + headerVersion);
XrefParser xrefParser = new XrefParser(parser);
xrefParser.parse();
COSDocument document = new COSDocument(xrefParser.trailer(), headerVersion);
if (document.isEncrypted())
{
LOG.debug("Preparing for document decryption");
PDEncryption encryption = new PDEncryption(document.getEncryptionDictionary());
SecurityHandler securityHandler = encryption.getSecurityHandler();
securityHandler.prepareForDecryption(encryption, document.getDocumentID(), Optional
.ofNullable(decryptionMaterial).orElse(new StandardDecryptionMaterial("")));
parser.provider().initializeWith(securityHandler);
return new PDDocument(document, securityHandler);
}
return new PDDocument(document);
}
示例6: writeBodySync
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
@Test
public void writeBodySync() throws Exception
{
PDDocument document = mock(PDDocument.class);
COSDocument cosDoc = mock(COSDocument.class);
FileTrailer trailer = new FileTrailer();
when(document.getDocument()).thenReturn(cosDoc);
when(cosDoc.getTrailer()).thenReturn(trailer);
this.victim = new PDDocumentWriter(from(new DevNullWritableByteChannel()), null,
WriteOption.SYNC_BODY_WRITE);
TestUtils.setProperty(victim, "writer", this.writer);
ArgumentCaptor<PDFBodyWriter> bodyWriter = ArgumentCaptor.forClass(PDFBodyWriter.class);
victim.write(document);
verify(cosDoc).accept(bodyWriter.capture());
assertThat(bodyWriter.getValue().objectsWriter,
new InstanceOf(SyncPDFBodyObjectsWriter.class));
}
示例7: writeBodyCompressed
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
@Test
public void writeBodyCompressed() throws Exception
{
PDDocument document = mock(PDDocument.class);
COSDocument cosDoc = mock(COSDocument.class);
FileTrailer trailer = new FileTrailer();
when(document.getDocument()).thenReturn(cosDoc);
when(cosDoc.getTrailer()).thenReturn(trailer);
this.victim = new PDDocumentWriter(from(new DevNullWritableByteChannel()), null,
WriteOption.SYNC_BODY_WRITE, WriteOption.OBJECT_STREAMS);
TestUtils.setProperty(victim, "writer", this.writer);
ArgumentCaptor<PDFBodyWriter> bodyWriter = ArgumentCaptor.forClass(PDFBodyWriter.class);
victim.write(document);
verify(cosDoc).accept(bodyWriter.capture());
assertThat(bodyWriter.getValue().objectsWriter,
new InstanceOf(ObjectsStreamPDFBodyObjectsWriter.class));
}
示例8: setUp
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
@Before
public void setUp() throws IOException
{
victim = ExistingPagesSizePredictor.instance();
document = new PDDocument();
page = new PDPage();
document.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
try (PDPageContentStream contents = new PDPageContentStream(document, page))
{
contents.beginText();
contents.setFont(font, 12);
contents.newLineAtOffset(100, 700);
contents.showText("Chuck Norris");
contents.endText();
}
}
示例9: testCreateLosslessFromTransparentGIF
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
/**
* Tests LosslessFactoryTest#createFromImage(PDDocument document, BufferedImage image) with transparent GIF
*
* @throws java.io.IOException
*/
public void testCreateLosslessFromTransparentGIF() throws IOException
{
PDDocument document = new PDDocument();
BufferedImage image = ImageIO.read(this.getClass().getResourceAsStream("gif.gif"));
assertEquals(Transparency.BITMASK, image.getColorModel().getTransparency());
PDImageXObject ximage = LosslessFactory.createFromImage(image);
int w = image.getWidth();
int h = image.getHeight();
validate(ximage, 8, w, h, "png", PDDeviceRGB.INSTANCE.getName());
checkIdent(image, ximage.getImage());
checkIdentRGB(image, ximage.getOpaqueImage());
assertNotNull(ximage.getSoftMask());
validate(ximage.getSoftMask(), 1, w, h, "png", PDDeviceGray.INSTANCE.getName());
assertEquals(2, colorCount(ximage.getSoftMask().getImage()));
doWritePDF(document, ximage, testResultsDir, "gif.pdf");
}
示例10: checkJpegStream
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的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());
}
}
示例11: testWidgetMissingRect
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的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));
}
}
示例12: testRadioButtonWithOptions
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的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));
}
}
}
示例13: testRadioButtonWithOptionsThatDontMatchNormalAppearance
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的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));
}
}
示例14: testRadioButtonWithOptionsThatDoMatchNormalAppearance
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的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));
}
}
示例15: testCheckboxWithExportValuesMoreThanWidgets
import org.sejda.sambox.pdmodel.PDDocument; //導入依賴的package包/類
@Test
public void testCheckboxWithExportValuesMoreThanWidgets() throws IOException
{
try (PDDocument document = PDFParser.parse(
SeekableSources.inMemorySeekableSourceFrom(this.getClass().getResourceAsStream(
"/org/sejda/sambox/pdmodel/interactive/form/P020130830121570742708.pdf"))))
{
PDCheckBox checkbox = (PDCheckBox) document.getDocumentCatalog().getAcroForm()
.getField("Check Box3");
try
{
checkbox.check();
fail("Expecting exception, since this will use the first export value");
// TODO: fix getOnValue to return the first normal appearance value?
}
catch (IllegalArgumentException ex)
{
assertThat(ex.getMessage(), containsString(
"The number of options doesn't match the number of widgets"));
}
checkbox.setValue("0");
assertEquals(checkbox.getValue(), "0");
}
}