Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1007365 // Make a "Hello World" PDF document using Apache PDFBox [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3888K of libraries. Click here for Pure Java version (844L/6K/20K).

1  
!7
2  
3  
lib 1007364 // Apache PDFBox
4  
lib 1007366 // Apache FontBox
5  
lib 1003619 // Apache Commons Logging
6  
7  
import org.apache.pdfbox.pdmodel.*;
8  
import org.apache.pdfbox.pdmodel.font.*;
9  
10  
p {
11  
  // Create a document and add a page to it
12  
  new PDDocument document;
13  
  new PDPage page;
14  
  document.addPage(page);
15  
  
16  
  // Create a new font object selecting one of the PDF base fonts
17  
  PDFont font = PDType1Font.HELVETICA_BOLD;
18  
  
19  
  // Start a new content stream which will "hold" the to be created content
20  
  PDPageContentStream contentStream = new PDPageContentStream(document, page);
21  
  
22  
  // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
23  
  contentStream.beginText();
24  
  contentStream.setFont(font, 12);
25  
  contentStream.moveTextPositionByAmount( 100, 700 );
26  
  contentStream.drawString("Hello World");
27  
  contentStream.endText();
28  
  
29  
  // Make sure that the content stream is closed:
30  
  contentStream.close();
31  
  
32  
  // Save the results and ensure that the document is properly closed:
33  
  File file;
34  
  document.save(file = prepareProgramFile("Hello World.pdf"));
35  
  document.close();
36  
  
37  
  print("Saved: " + f2s(file) + " (" + file.length() + " bytes)");
38  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1007365
Snippet name: Make a "Hello World" PDF document using Apache PDFBox [WORKS]
Eternal ID of this version: #1007365/6
Text MD5: f2ecea7dc02fde8abeb960dc2afe9d2d
Transpilation MD5: 5a1596d5c7fbbe07f5df9f5761a7a2fd
Author: stefan
Category: javax / pdf
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-16 19:28:55
Source code size: 1230 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 759 / 818
Version history: 5 change(s)
Referenced in: [show references]