本文整理汇总了Java中com.itextpdf.text.pdf.PdfName类的典型用法代码示例。如果您正苦于以下问题:Java PdfName类的具体用法?Java PdfName怎么用?Java PdfName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PdfName类属于com.itextpdf.text.pdf包,在下文中一共展示了PdfName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSwitchOrientation
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/34394199/i-cant-rotate-my-page-from-existing-pdf">
* I can't rotate my page from existing PDF
* </a>
* <p>
* Switching between portrait and landscape like this obviously will cut off some parts of the page.
* </p>
*/
@Test
public void testSwitchOrientation() throws DocumentException, IOException
{
try (InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/n2013.00849449.pdf"))
{
PdfReader reader = new PdfReader(resourceStream);
int n = reader.getNumberOfPages();
PdfDictionary pageDict;
for (int i = 1; i <= n; i++) {
Rectangle rect = reader.getPageSize(i);
Rectangle crop = reader.getCropBox(i);
pageDict = reader.getPageN(i);
pageDict.put(PdfName.MEDIABOX, new PdfArray(new float[] {rect.getBottom(), rect.getLeft(), rect.getTop(), rect.getRight()}));
pageDict.put(PdfName.CROPBOX, new PdfArray(new float[] {crop.getBottom(), crop.getLeft(), crop.getTop(), crop.getRight()}));
}
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(new File(RESULT_FOLDER, "n2013.00849449-switch.pdf")));
stamper.close();
reader.close();
}
}
示例2: testOPCode
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
@Test
public void testOPCode() throws IOException, DocumentException
{
try ( InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/merge/testA4.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "testA4-annotate.pdf")) )
{
PdfReader reader = new PdfReader(resourceStream);
PdfStamper stamper = new PdfStamper(reader, outputStream);
Rectangle linkLocation = new Rectangle( 100, 700, 100 + 200, 700 + 25 );
PdfName highlight = PdfAnnotation.HIGHLIGHT_INVERT;
PdfAnnotation linkRed = PdfAnnotation.createLink( stamper.getWriter(), linkLocation, highlight, "red" );
PdfAnnotation linkGreen = PdfAnnotation.createLink( stamper.getWriter(), linkLocation, highlight, "green" );
BaseColor baseColorRed = new BaseColor(255,0,0);
BaseColor baseColorGreen = new BaseColor(0,255,0);
linkRed.setColor(baseColorRed);
linkGreen.setColor(baseColorGreen);
double angleDegrees = 10;
double angleRadians = Math.PI*angleDegrees/180;
stamper.addAnnotation(linkRed, 1);
linkGreen.applyCTM(AffineTransform.getRotateInstance(angleRadians));
stamper.addAnnotation(linkGreen, 1);
stamper.close();
}
}
示例3: buildSignedPDF
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
public byte[] buildSignedPDF(String digestOID, byte[] signature, byte[] hash) throws Exception {
byte[] hashTmp = null;
if (dateTime != null)
hashTmp = hash;
byte[] pkcs7enc = PKCS7Manager.buildPDFPKCS7(digestOID, x509Certificate, signature, hashTmp, dateTime);
PdfDictionary dic = new PdfDictionary();
PdfString contents = new PdfString(pkcs7enc).setHexWriting(true);
contentsSize = contents.length();
dic.put(PdfName.CONTENTS, contents);
sap.close(dic);
return bout.toByteArray();
}
示例4: numberOfVisibleSignatureFieldsOnSignaturePage
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
private int numberOfVisibleSignatureFieldsOnSignaturePage(AcroFields readerFields, ArrayList<String> signatureFieldsNames, int signaturePage) {
int count = 0;
for (String signatureFieldName : signatureFieldsNames) {
Item i = readerFields.getFieldItem(signatureFieldName);
int page = i.getPage(0);
if(page == signaturePage){
PdfDictionary pdct = i.getMerged(0);
PdfNumber flags = pdct.getAsNumber(PdfName.F);
if ((flags.intValue() & PdfAnnotation.FLAGS_HIDDEN) == 0) {
count = count + 1;
}
}
}
return count;
}
示例5: write
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
@Override
protected void write(PdfContentStreamProcessor processor, PdfLiteral operator, List<PdfObject> operands) throws IOException
{
String operatorString = operator.toString();
if ("gs".equals(operatorString))
{
updateTransparencyFrom((PdfName) operands.get(0));
}
PdfLiteral[] mapping = operatorMapping.get(operatorString);
if (mapping != null)
{
int index = 0;
if (strokingAlpha < 1)
index |= 1;
if (nonStrokingAlpha < 1)
index |= 2;
operator = mapping[index];
operands.set(operands.size() - 1, operator);
}
super.write(processor, operator, operands);
}
示例6: testCreateEllipseOnRotated
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/43205385/trying-to-draw-an-ellipse-annotation-and-the-border-on-the-edges-goes-thin-and-t">
* Trying to draw an ellipse annotation and the border on the edges goes thin and thik when i try to roatate pdf itext5
* </a>
* <p>
* This test creates an ellipse annotation without appearance on a page with rotation.
* The ellipse form looks ok but it is moved to the right of the actual appearance rectangle when viewed in Adobe Reader.
* This is caused by iText creating a non-standard rectangle, the lower left not being the lower left etc.
* </p>
* @see #testCreateEllipse()
* @see #testCreateEllipseAppearance()
* @see #testCreateEllipseAppearanceOnRotated()
* @see #testCreateCorrectEllipseAppearanceOnRotated()
*/
@Test
public void testCreateEllipseOnRotated() throws IOException, DocumentException
{
try ( InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/merge/testA4.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "testA4-rotated-ellipse.pdf")) )
{
PdfReader reader = new PdfReader(resourceStream);
reader.getPageN(1).put(PdfName.ROTATE, new PdfNumber(90));
PdfStamper stamper = new PdfStamper(reader, outputStream);
Rectangle rect = new Rectangle(202 + 6f, 300, 200 + 100, 300 + 150);
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(stamper.getWriter(), rect, null, false);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setColor(BaseColor.RED);
annotation.setBorderStyle(new PdfBorderDictionary(3.5f, PdfBorderDictionary.STYLE_SOLID));
stamper.addAnnotation(annotation, 1);
stamper.close();
reader.close();
}
}
示例7: testRemoveContent
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/43870545/filling-a-pdf-with-itextsharp-and-then-hiding-the-base-layer">
* Filling a PDF with iTextsharp and then hiding the base layer
* </a>
* <p>
* This test shows how to remove all content.
* </p>
*/
@Test
public void testRemoveContent() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("document.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "document-removedContent.pdf")))
{
PdfReader pdfReader = new PdfReader(resource);
for (int page = 1; page <= pdfReader.getNumberOfPages(); page++)
{
PdfDictionary pageDictionary = pdfReader.getPageN(page);
pageDictionary.remove(PdfName.CONTENTS);
}
new PdfStamper(pdfReader, result).close();
}
}
示例8: extractAttachments
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* These two methods ({@link #extractAttachments(PdfReader, String)} and
* {@link #extractAttachment(PdfReader, File, PdfString, PdfDictionary)})
* essentially are the OP's original code posted in his question. They
* extract files without the folder structure.
*/
public static void extractAttachments(PdfReader reader, String dir) throws IOException
{
File folder = new File(dir);
folder.mkdirs();
PdfDictionary root = reader.getCatalog();
PdfDictionary names = root.getAsDict(PdfName.NAMES);
System.out.println("" + names.getKeys().toString());
PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
System.out.println("" + embedded.toString());
PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);
//System.out.println(filespecs.getAsString(root1));
for (int i = 0; i < filespecs.size();)
{
extractAttachment(reader, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
}
}
示例9: extractAttachmentsWithFolders
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* <p>
* These two methods ({@link #extractAttachmentsWithFolders(PdfReader, String)} and
* {@link #extractAttachment(PdfReader, Map, PdfString, PdfDictionary)}) extend the
* functionality of the OP's original code posted in his question. They extract files
* with the folder structure.
* </p>
* <p>
* The information concerning the portfolio folder structure is retrieved using
* the method {@link #retrieveFolders(PdfReader, File)} and its helper method
* {@link #collectFolders(Map, PdfDictionary, File)}.
* </p>
*/
public static void extractAttachmentsWithFolders(PdfReader reader, String dir) throws IOException, DocumentException
{
File folder = new File(dir);
folder.mkdirs();
Map<Integer, File> folders = retrieveFolders(reader, folder);
PdfDictionary root = reader.getCatalog();
PdfDictionary names = root.getAsDict(PdfName.NAMES);
System.out.println("" + names.getKeys().toString());
PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
System.out.println("" + embedded.toString());
PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);
for (int i = 0; i < filespecs.size();)
{
extractAttachment(reader, folders, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
}
}
示例10: retrieveFolders
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
static Map<Integer, File> retrieveFolders(PdfReader reader, File baseDir) throws DocumentException
{
Map<Integer, File> result = new HashMap<Integer, File>();
PdfDictionary root = reader.getCatalog();
PdfDictionary collection = root.getAsDict(PdfName.COLLECTION);
if (collection == null)
throw new DocumentException("Document has no Collection dictionary");
PdfDictionary folders = collection.getAsDict(FOLDERS);
if (folders == null)
throw new DocumentException("Document collection has no folders dictionary");
collectFolders(result, folders, baseDir);
return result;
}
示例11: getConfiguredViewerPreferencesMap
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
*
* @param parameters
* @return a map of preferences with corresponding value to be set on the documents
*/
private Map<PdfName, PdfObject> getConfiguredViewerPreferencesMap(ViewerPreferencesParameters parameters) {
Map<PdfName, PdfObject> confPreferences = new HashMap<PdfName, PdfObject>();
if (parameters.getDirection() != null) {
confPreferences.put(PdfName.DIRECTION, ViewerPreferencesUtils.getDirection(parameters.getDirection()));
}
if (parameters.getDuplex() != null) {
confPreferences.put(PdfName.DUPLEX, ViewerPreferencesUtils.getDuplex(parameters.getDuplex()));
}
if (parameters.getPrintScaling() != null) {
confPreferences.put(PdfName.PRINTSCALING,
ViewerPreferencesUtils.getPrintScaling(parameters.getPrintScaling()));
}
confPreferences.put(PdfName.NONFULLSCREENPAGEMODE, ViewerPreferencesUtils.getNFSMode(parameters.getNfsMode()));
Set<PdfBooleanPreference> activePref = parameters.getEnabledPreferences();
for (PdfBooleanPreference boolPref : PdfBooleanPreference.values()) {
if (activePref.contains(boolPref)) {
confPreferences.put(ViewerPreferencesUtils.getBooleanPreference(boolPref), PdfBoolean.PDFTRUE);
} else {
confPreferences.put(ViewerPreferencesUtils.getBooleanPreference(boolPref), PdfBoolean.PDFFALSE);
}
}
return confPreferences;
}
示例12: unpack
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
private void unpack(Set<PdfDictionary> dictionaries) throws TaskIOException {
for (PdfDictionary dictionary : dictionaries) {
PdfName type = dictionary.getAsName(PdfName.TYPE);
if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) {
PdfDictionary ef = dictionary.getAsDict(PdfName.EF);
PdfString fn = dictionary.getAsString(PdfName.F);
if (fn != null && ef != null) {
PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
if (prs != null) {
File tmpFile = copyToTemporaryFile(prs);
outputWriter.addOutput(file(tmpFile).name(fn.toUnicodeString()));
}
}
}
}
}
示例13: doExecute
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
private void doExecute() throws TaskException, IOException {
when(context.getTask(parameters)).thenReturn((Task) victimTask);
victim.execute(parameters);
PdfReader reader = getReaderFromResultStream("test_file.pdf");
assertCreator(reader);
assertEquals(PdfVersion.VERSION_1_7.getVersionAsCharacter(), reader.getPdfVersion());
PdfDictionary catalog = PdfViewerPreferencesImp.getViewerPreferences(reader.getCatalog())
.getViewerPreferences();
assertEquals(PdfName.SIMPLEX, catalog.getAsName(PdfName.DUPLEX));
assertEquals(PdfName.L2R, catalog.getAsName(PdfName.DIRECTION));
assertEquals(PdfName.APPDEFAULT, catalog.getAsName(PdfName.PRINTSCALING));
assertEquals(PdfName.USETHUMBS, catalog.getAsName(PdfName.NONFULLSCREENPAGEMODE));
assertEquals(PdfBoolean.PDFTRUE, catalog.getAsBoolean(PdfName.CENTERWINDOW));
assertEquals(PdfBoolean.PDFTRUE, catalog.getAsBoolean(PdfName.HIDEMENUBAR));
assertEquals(PdfBoolean.PDFFALSE, catalog.getAsBoolean(PdfName.HIDETOOLBAR));
reader.close();
}
示例14: extractText
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
/**
* Extracts text from a PDF document.
*
* @param src the original PDF document
* @throws java.io.IOException
*/
public List<Page> extractText(InputStream src) throws IOException {
List<Page> pages = Lists.newArrayList();
PdfReader reader = new PdfReader(src);
RenderListener listener = new InternalListener();
PdfContentStreamProcessor processor = new PdfContentStreamProcessor(listener);
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
pages.add(currentPage = new Page());
PdfDictionary pageDic = reader.getPageN(i);
PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES);
processor.processContent(ContentByteUtils.getContentBytesForPage(reader, i), resourcesDic);
}
reader.close();
return pages;
}
示例15: getLevelPdfName
import com.itextpdf.text.pdf.PdfName; //导入依赖的package包/类
public PdfName getLevelPdfName() {
int level = getLevel();
switch (level) {
case 0:
return PdfName.H1;
case 1:
return PdfName.H2;
case 2:
return PdfName.H3;
case 3:
return PdfName.H4;
case 4:
return PdfName.H5;
case 5:
return PdfName.H6;
default:
return PdfName.H;
}
}