forked from LibrePDF/OpenPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix LibrePDF/OpenPDF5#7: LineSeparator prints out OBJECT_REPLACEMENT_…
…CHARACTER
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
openpdf/src/test/java/com/lowagie/text/pdf/ColumnTextSeparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Author: alesky78 <alessandro.dottavio@gmail.com> | ||
*/ | ||
|
||
package com.lowagie.text.pdf; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.lowagie.text.Chunk; | ||
import com.lowagie.text.Document; | ||
import com.lowagie.text.Element; | ||
import com.lowagie.text.PageSize; | ||
import com.lowagie.text.Phrase; | ||
import com.lowagie.text.pdf.ColumnText; | ||
import com.lowagie.text.pdf.PdfContentByte; | ||
import com.lowagie.text.pdf.PdfWriter; | ||
import com.lowagie.text.pdf.draw.LineSeparator; | ||
|
||
public class ColumnTextSeparator { | ||
|
||
private String filePath; | ||
|
||
public static final float[][] COLUMNS = {{ 36, 36, 296, 806 } , { 299, 36, 559, 806 }}; | ||
|
||
@Test | ||
public void test_columnTextSeparator() throws Exception{ | ||
filePath = System.getProperty("user.dir")+"/src/test/resources"; | ||
|
||
File RESULT = new File(filePath+"/columnTextSeparator.pdf"); | ||
// step 1 | ||
Document document = new Document(PageSize.A4); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
PdfWriter pdfWriter = PdfWriter.getInstance(document, baos); | ||
|
||
document.open(); | ||
PdfContentByte wrote = pdfWriter.getDirectContent(); | ||
|
||
ColumnText ct = new ColumnText(wrote); | ||
Phrase p = null; | ||
|
||
for (int i = 0; i < 3; i++) { | ||
p = new Phrase(); | ||
p.add(new LineSeparator(0.3f, 100, null, Element.ALIGN_CENTER, -2)); | ||
p.add("test"); | ||
ct.addText(p); | ||
ct.addText(Chunk.NEWLINE); | ||
} | ||
|
||
ct.setAlignment(Element.ALIGN_JUSTIFIED); | ||
ct.setExtraParagraphSpace(6); | ||
ct.setLeading(0, 1.2f); | ||
ct.setFollowingIndent(27); | ||
int linesWritten = 0; | ||
int column = 0; | ||
int status = ColumnText.START_COLUMN; | ||
while (ColumnText.hasMoreText(status)) { | ||
ct.setSimpleColumn(COLUMNS[column][0], COLUMNS[column][1],COLUMNS[column][2], COLUMNS[column][3]); | ||
ct.setYLine(COLUMNS[column][3]); | ||
status = ct.go(); | ||
linesWritten += ct.getLinesWritten(); | ||
column = Math.abs(column - 1); | ||
if (column == 0) | ||
document.newPage(); | ||
} | ||
|
||
document.close(); | ||
|
||
FileOutputStream fos = new FileOutputStream(RESULT); | ||
fos.write(baos.toByteArray()); | ||
fos.close(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |