本文整理汇总了Java中org.apache.pdfbox.cos.COSName.getPDFName方法的典型用法代码示例。如果您正苦于以下问题:Java COSName.getPDFName方法的具体用法?Java COSName.getPDFName怎么用?Java COSName.getPDFName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.cos.COSName
的用法示例。
在下文中一共展示了COSName.getPDFName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRenderSdnList
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/42032729/render-type3-font-character-as-image-using-pdfbox">
* Render Type3 font character as image using PDFBox
* </a>
* <br/>
* <a href="https://drive.google.com/file/d/0B0f6X4SAMh2KRDJTbm4tb3E1a1U/view">
* 4700198773.pdf
* </a>
* from
* <a href="http://stackoverflow.com/questions/37754112/extract-text-with-custom-font-result-non-readble">
* extract text with custom font result non readble
* </a>
* <p>
* This test shows how one can render individual Type 3 font glyphs as bitmaps.
* Unfortunately PDFBox out-of-the-box does not provide a class to render contents
* of arbitrary XObjects, merely for rendering pages; thus, we simply create a page
* with the glyph in question and render that page.
* </p>
* <p>
* As the OP did not provide a sample PDF, we simply use one from another
* stackoverflow question. There obviously might remain issues with the
* OP's files.
* </p>
*/
@Test
public void testRenderSdnList() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("sdnlist.pdf"))
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getPage(1);
PDResources pageResources = page.getResources();
COSName f1Name = COSName.getPDFName("R144");
PDType3Font fontF1 = (PDType3Font) pageResources.getFont(f1Name);
Map<String, Integer> f1NameToCode = fontF1.getEncoding().getNameToCodeMap();
COSDictionary charProcsDictionary = fontF1.getCharProcs();
for (COSName key : charProcsDictionary.keySet())
{
COSStream stream = (COSStream) charProcsDictionary.getDictionaryObject(key);
PDType3CharProc charProc = new PDType3CharProc(fontF1, stream);
PDRectangle bbox = charProc.getGlyphBBox();
if (bbox == null)
bbox = charProc.getBBox();
Integer code = f1NameToCode.get(key.getName());
if (code != null)
{
PDDocument charDocument = new PDDocument();
PDPage charPage = new PDPage(bbox);
charDocument.addPage(charPage);
charPage.setResources(pageResources);
PDPageContentStream charContentStream = new PDPageContentStream(charDocument, charPage);
charContentStream.beginText();
charContentStream.setFont(fontF1, bbox.getHeight());
charContentStream.getOutput().write(String.format("<%2X> Tj\n", code).getBytes());
charContentStream.endText();
charContentStream.close();
File result = new File(RESULT_FOLDER, String.format("sdnlist-%s-%s.png", key.getName(), code));
PDFRenderer renderer = new PDFRenderer(charDocument);
BufferedImage image = renderer.renderImageWithDPI(0, 96);
ImageIO.write(image, "PNG", result);
charDocument.save(new File(RESULT_FOLDER, String.format("sdnlist-%s-%s.pdf", key.getName(), code)));
charDocument.close();
}
}
}
}
示例2: testRemoveLikeStephanImproved
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/45812696/pdfbox-delete-comment-maintain-strikethrough">
* PDFBox delete comment maintain strikethrough
* </a>
* <br/>
* <a href="https://expirebox.com/files/3d955e6df4ca5874c38dbf92fc43b5af.pdf">
* only_fields.pdf
* </a>
* <a href="https://file.io/DTvqhC">
* (alternative download)
* </a>
* <p>
* The OP only wanted the comment removed, not the strike-through. Thus, we must
* not remove the annotation but merely the comment building attributes.
* </p>
*/
@Test
public void testRemoveLikeStephanImproved() throws IOException {
final COSName POPUP = COSName.getPDFName("Popup");
try (InputStream resource = getClass().getResourceAsStream("only_fields.pdf")) {
PDDocument document = PDDocument.load(resource);
List<PDAnnotation> annotations = new ArrayList<>();
PDPageTree allPages = document.getDocumentCatalog().getPages();
List<COSObjectable> objectsToRemove = new ArrayList<>();
for (int i = 0; i < allPages.getCount(); i++) {
PDPage page = allPages.get(i);
annotations = page.getAnnotations();
for (PDAnnotation annotation : annotations) {
if ("StrikeOut".equals(annotation.getSubtype()))
{
COSDictionary annotationDict = annotation.getCOSObject();
COSBase popup = annotationDict.getItem(POPUP);
annotationDict.removeItem(POPUP);
annotationDict.removeItem(COSName.CONTENTS); // plain text comment
annotationDict.removeItem(COSName.RC); // rich text comment
annotationDict.removeItem(COSName.T); // author
if (popup != null)
objectsToRemove.add(popup);
}
}
annotations.removeAll(objectsToRemove);
}
document.save(new File(RESULT_FOLDER, "only_fields-removeImproved.pdf"));
}
}
示例3: testRender4700198773
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/42032729/render-type3-font-character-as-image-using-pdfbox">
* Render Type3 font character as image using PDFBox
* </a>
* <br/>
* <a href="https://drive.google.com/file/d/0B0f6X4SAMh2KRDJTbm4tb3E1a1U/view">
* 4700198773.pdf
* </a>
* from
* <a href="http://stackoverflow.com/questions/37754112/extract-text-with-custom-font-result-non-readble">
* extract text with custom font result non readble
* </a>
* <p>
* This test shows how one can render individual Type 3 font glyphs as bitmaps.
* Unfortunately PDFBox out-of-the-box does not provide a class to render contents
* of arbitrary XObjects, merely for rendering pages; thus, we simply create a page
* with the glyph in question and render that page.
* </p>
* <p>
* As the OP did not provide a sample PDF, we simply use one from another
* stackoverflow question. There obviously might remain issues with the
* OP's files.
* </p>
*/
@Test
public void testRender4700198773() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("4700198773.pdf"))
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getPage(0);
PDResources pageResources = page.getResources();
COSName f1Name = COSName.getPDFName("F1");
PDType3Font fontF1 = (PDType3Font) pageResources.getFont(f1Name);
Map<String, Integer> f1NameToCode = fontF1.getEncoding().getNameToCodeMap();
COSDictionary charProcsDictionary = fontF1.getCharProcs();
for (COSName key : charProcsDictionary.keySet())
{
COSStream stream = (COSStream) charProcsDictionary.getDictionaryObject(key);
PDType3CharProc charProc = new PDType3CharProc(fontF1, stream);
PDRectangle bbox = charProc.getGlyphBBox();
if (bbox == null)
bbox = charProc.getBBox();
Integer code = f1NameToCode.get(key.getName());
if (code != null)
{
PDDocument charDocument = new PDDocument();
PDPage charPage = new PDPage(bbox);
charDocument.addPage(charPage);
charPage.setResources(pageResources);
PDPageContentStream charContentStream = new PDPageContentStream(charDocument, charPage);
charContentStream.beginText();
charContentStream.setFont(fontF1, bbox.getHeight());
charContentStream.getOutput().write(String.format("<%2X> Tj\n", code).getBytes());
charContentStream.endText();
charContentStream.close();
File result = new File(RESULT_FOLDER, String.format("4700198773-%s-%s.png", key.getName(), code));
PDFRenderer renderer = new PDFRenderer(charDocument);
BufferedImage image = renderer.renderImageWithDPI(0, 96);
ImageIO.write(image, "PNG", result);
charDocument.save(new File(RESULT_FOLDER, String.format("4700198773-%s-%s.pdf", key.getName(), code)));
charDocument.close();
}
}
}
}
示例4: getName
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
private COSName getName (final PDColorSpace colorSpace)
{
if (colorSpace instanceof PDDeviceGray || colorSpace instanceof PDDeviceRGB || colorSpace instanceof PDDeviceCMYK)
{
return COSName.getPDFName (colorSpace.getName ());
}
return resources.add (colorSpace);
}
示例5: getFilter
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
@Override
protected COSName getFilter(PAdESSignatureParameters parameters) {
if (Utils.isStringNotEmpty(parameters.getTimestampFilter())) {
return COSName.getPDFName(parameters.getTimestampFilter());
}
return PDSignature.FILTER_ADOBE_PPKLITE;
}
示例6: getSubFilter
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
@Override
protected COSName getSubFilter(PAdESSignatureParameters parameters) {
if (Utils.isStringNotEmpty(parameters.getTimestampSubFilter())) {
return COSName.getPDFName(parameters.getTimestampSubFilter());
}
return SUB_FILTER_ETSI_RFC3161;
}
示例7: getFilter
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
protected COSName getFilter(PAdESSignatureParameters parameters) {
if (Utils.isStringNotEmpty(parameters.getSignatureFilter())) {
return COSName.getPDFName(parameters.getSignatureFilter());
}
return PDSignature.FILTER_ADOBE_PPKLITE;
}
示例8: getSubFilter
import org.apache.pdfbox.cos.COSName; //导入方法依赖的package包/类
protected COSName getSubFilter(PAdESSignatureParameters parameters) {
if (Utils.isStringNotEmpty(parameters.getSignatureSubFilter())) {
return COSName.getPDFName(parameters.getSignatureSubFilter());
}
return PDSignature.SUBFILTER_ETSI_CADES_DETACHED;
}