org.apache.pdfbox.pdmodel.PDDocument.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中org.apache.pdfbox.pdmodel.PDDocument.<init>()方法的一些代码示例,展示了PDDocument.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDDocument.<init>()方法的具体详情如下:
包路径:org.apache.pdfbox.pdmodel.PDDocument
类名称:PDDocument
方法名:<init>

PDDocument.<init>介绍

[英]Creates an empty PDF document. You need to add at least one page for the document to be valid.
[中]创建一个空的PDF文档。您需要至少添加一页才能使文档有效。

代码示例

代码示例来源:origin: stackoverflow.com

PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage( page );

PDPageContentStream contentStream = new PDPageContentStream(doc, page);

String[][] content = {{"a","b", "1"}, 
           {"c","d", "2"}, 
           {"e","f", "3"}, 
           {"g","h", "4"}, 
           {"i","j", "5"}} ;

drawTable(page, contentStream, 700, 100, content);
contentStream.close();
doc.save("test.pdf" );

代码示例来源:origin: stackoverflow.com

String title = "This is my wonderful title!"; // Or whatever title you want.
int marginTop = 30; // Or whatever margin you want.

PDDocument document = new PDDocument();
PDPage page = new PDPage()
PDPageStreamContent stream = new PDPageContentStream(document, page);
PDFont font = PDType1Font.HELVETICA_BOLD; // Or whatever font you want.

int fontSize = 16; // Or whatever font size you want.
float titleWidth = font.getStringWidth(title) / 1000 * fontSize;
float titleHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * fontSize;

stream.beginText();
stream.setFont(font, fontSize);
stream.moveTextPositionByAmount((page.getMediaBox().getWidth() - titleWidth) / 2, page.getMediaBox().getHeight - marginTop - titleheight);
stream.drawString(title);
stream.endText();
stream.close();

代码示例来源:origin: stackoverflow.com

try
  doc = new PDDocument();
  PDPage page = new PDPage();
  doc.addPage(page);

代码示例来源:origin: stackoverflow.com

try
  doc = new PDDocument();
  PDPage page = new PDPage();
  doc.addPage(page);

代码示例来源:origin: apache/pdfbox

/**
 * This will write the pdf document.
 *
 * @throws IOException If an error occurs while generating the data.
 * @param doc The document to write.
 */
public void write(COSDocument doc) throws IOException
{
  PDDocument pdDoc = new PDDocument( doc );
  write( pdDoc );
}

代码示例来源:origin: apache/pdfbox

/**
 * Create a PDF document with some text.
 *
 * @param text The stream of text data.
 *
 * @return The document with the text in it.
 *
 * @throws IOException If there is an error writing the data.
 */
public PDDocument createPDFFromText( Reader text ) throws IOException
{
  PDDocument doc = new PDDocument();
  createPDFFromText(doc, text);
  return doc;
}

代码示例来源:origin: stackoverflow.com

PDDocument doc=new PDDocument();        
PDStream ps=new PDStream(doc);
InputStream is=ps.createInputStream();

代码示例来源:origin: stackoverflow.com

PDDocument document = new PDDocument();
InputStream in = new FileInputStream(someImage);
BufferedImage bimg = ImageIO.read(in);
float width = bimg.getWidth();
float height = bimg.getHeight();
PDPage page = new PDPage(new PDRectangle(width, height));
document.addPage(page); 
PDXObjectImage img = new PDJpeg(document, new FileInputStream(someImage));
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.drawImage(img, 0, 0);
contentStream.close();
in.close();

document.save("test.pdf");
document.close();

代码示例来源:origin: apache/pdfbox

/**
 * Creates a PDDocument and adds the page parameter to it and keeps this as a template in the
 * PDF template Structure.
 *
 * @param page
 * @throws IOException
 */
@Override
public void createTemplate(PDPage page) throws IOException
{
  PDDocument template = new PDDocument();
  template.addPage(page);
  pdfStructure.setTemplate(template);
}

代码示例来源:origin: apache/pdfbox

public static void main(String[] args) throws IOException
  {
    if (args.length != 1)
    {
      System.err.println("usage: " + CreateBlankPDF.class.getName() + " <outputfile.pdf>");
      System.exit(1);
    }

    String filename = args[0];

    try (PDDocument doc = new PDDocument())
    {
      // a valid PDF document requires at least one page
      PDPage blankPage = new PDPage();
      doc.addPage(blankPage);
      doc.save(filename);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws IOException, COSVisitorException {
  PDDocument doc = new PDDocument();
  PDPage page = new PDPage();
  doc.addPage( page );
  PDPageContentStream contentStream = new PDPageContentStream(doc, page);

  String[][] content = {
    {"Name"," Time "},
    {"HTC","01:25"},
    {"Samsung Tab2","05:30"}
  } ;

  drawTable(page, contentStream, 700, 100, content);

  contentStream.close();
  doc.save("h:\\test.pdf" );
}

代码示例来源:origin: tabulapdf/tabula-java

public static BufferedImage pageConvertToImage(PDPage page, int dpi, ImageType imageType) throws IOException {
  try (PDDocument document = new PDDocument()) {
    document.addPage(page);
    PDFRenderer renderer = new PDFRenderer(document);
    document.close();
    return renderer.renderImageWithDPI(0, dpi, imageType);
  }
}

代码示例来源:origin: stackoverflow.com

//Using PDFBox library available from http://pdfbox.apache.org/  
//Writes pdf document of specific pages as a new pdf file

//Reads in pdf document  
PDDocument pdDoc = PDDocument.load(file);

//Creates a new pdf document  
PDDocument document = null;

//Adds specific page "i" where "i" is the page number and then saves the new pdf document   
try {   
  document = new PDDocument();   
  document.addPage((PDPage) pdDoc.getDocumentCatalog().getAllPages().get(i));   
  document.save("file path"+"new document title"+".pdf");  
  document.close();  
}catch(Exception e){}

代码示例来源:origin: apache/pdfbox

/**
 * This will get the PD document that was parsed.  When you are done with
 * this document you must call close() on it to release resources.
 *
 * @return The document at the PD layer.
 *
 * @throws IOException If there is an error getting the document.
 */
public PDDocument getPDDocument() throws IOException
{
  PDDocument doc = new PDDocument(getDocument(), source, getAccessPermission());
  doc.setEncryptionDictionary(getEncryption());
  return doc;
}

代码示例来源:origin: tabulapdf/tabula-java

PDDocument document = new PDDocument();
document.addPage(page);

代码示例来源:origin: apache/pdfbox

String ttfPath = args[2];
try (PDDocument doc = new PDDocument())

代码示例来源:origin: apache/pdfbox

String message = args[1];
try (PDDocument doc = new PDDocument())

代码示例来源:origin: apache/pdfbox

/**
 * Create a new document to write the split contents to.
 *
 * @return the newly created PDDocument. 
 * @throws IOException If there is an problem creating the new document.
 */
protected PDDocument createNewDocument() throws IOException
{
  PDDocument document = memoryUsageSetting == null ?
              new PDDocument() : new PDDocument(memoryUsageSetting);
  document.getDocument().setVersion(getSourceDocument().getVersion());
  document.setDocumentInformation(getSourceDocument().getDocumentInformation());
  document.getDocumentCatalog().setViewerPreferences(
      getSourceDocument().getDocumentCatalog().getViewerPreferences());
  return document;
}

代码示例来源:origin: apache/pdfbox

try (PDDocument doc = new PDDocument())

代码示例来源:origin: apache/pdfbox

PDDocument extractedDocument = new PDDocument();
extractedDocument.setDocumentInformation(sourceDocument.getDocumentInformation());
extractedDocument.getDocumentCatalog().setViewerPreferences(

相关文章

微信公众号

最新文章

更多