本文整理汇总了Java中com.itextpdf.text.Document.newPage方法的典型用法代码示例。如果您正苦于以下问题:Java Document.newPage方法的具体用法?Java Document.newPage怎么用?Java Document.newPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.Document
的用法示例。
在下文中一共展示了Document.newPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTitlePage
import com.itextpdf.text.Document; //导入方法依赖的package包/类
private static void addTitlePage(Document document,Resolucion res)
throws DocumentException {
Paragraph preface = new Paragraph();
// We add one empty line
addEmptyLine(preface, 1);
// Lets write a big header
preface.add(new Paragraph("Consejo Profesional de Informatica de Santiago del Estero", catFont));
addEmptyLine(preface, 1);
// Will create: Report generated by: _name, _date
preface.add(new Paragraph( "Comision Directiva del Consejo, " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
smallBold));
addEmptyLine(preface, 2);
preface.add(new Paragraph("Resolucion N°"+res.getNumero_resolucion()+"",
smallBold));
addEmptyLine(preface, 3);
preface.add(new Paragraph("Esta Resolucion de tipo "+res.getTipo()+" formulada para notificar al socio con legajo: "+res.getLegajo_socio()+" de su actual estado como socio del Consejo.\n"
+ res.getDescripcion_solicitud()+" "+res.getDescripcion_resolucion()+" en la fecha "+res.getFecha(),
cuerpo));
document.add(preface);
// Start a new page
document.newPage();
}
示例2: createMultiUseIndirectTextPdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
static byte[] createMultiUseIndirectTextPdf() throws DocumentException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfReader reader = new PdfReader(createSimpleTextPdf());
PdfImportedPage template = writer.getImportedPage(reader, 1);
Rectangle pageSize = reader.getPageSize(1);
writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), (pageSize.getTop() + pageSize.getBottom()) / 2);
writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), pageSize.getBottom());
document.newPage();
writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
document.close();
return baos.toByteArray();
}
示例3: addTitlePage
import com.itextpdf.text.Document; //导入方法依赖的package包/类
private void addTitlePage(Document document) throws DocumentException {
addEmptyLine(document, 5);
Paragraph title = new Paragraph("Data Dictionary by Arrah technology");
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
addEmptyLine(document, 1);
Paragraph url = new Paragraph("http://sourceforge.net/projects/dataquality/");
url.setAlignment(Element.ALIGN_CENTER);
document.add(url);
addEmptyLine(document, 3);
Paragraph rtime = new Paragraph("Report generated on: " + new Date());
rtime.setAlignment(Element.ALIGN_CENTER);
document.add(rtime);
document.newPage();
}
示例4: testRowspanWithHeaderRows
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40947306/strange-setrowspan-error-not-working">
* Strange setRowspan error/not working
* </a>
* <p>
* Selecting 1 header row and having a cell in the first row which spans 2 rows
* does not match. iText ignores the row span resulting in the weird appearance.
* </p>
*/
@Test
public void testRowspanWithHeaderRows() throws IOException, DocumentException
{
File file = new File(RESULT_FOLDER, "rowspanWithHeaderRows.pdf");
OutputStream os = new FileOutputStream(file);
Document document = new Document();
/*PdfWriter writer =*/ PdfWriter.getInstance(document, os);
document.open();
document.add(createHeaderContent());
document.newPage();
document.add(createHeaderContent(new int[] {5,5,5,5,5}));
document.close();
}
示例5: testChangingMargins
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/38057241/itextpdf-different-margin-on-specific-page">
* itextpdf different margin on specific page
* </a>
* <p>
* This test shows how to set different margins to separate pages.
* </p>
*/
@Test
public void testChangingMargins() throws IOException, DocumentException
{
StringBuilder builder = new StringBuilder("test");
for (int i = 0; i < 100; i++)
builder.append(" test");
String test = builder.toString();
try ( OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "ChangingMargins.pdf")))
{
Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
PdfWriter.getInstance(pdfDocument, pdfStream);
pdfDocument.open();
for (int m = 0; m < pdfDocument.getPageSize().getWidth() / 2 && m < pdfDocument.getPageSize().getHeight() / 2; m += 100)
{
// pdfDocument.setMargins(m, m, 100, 100);
pdfDocument.setMargins(m, m, m, m);
pdfDocument.newPage();
pdfDocument.add(new Paragraph(test));
}
pdfDocument.close();
}
}
示例6: createSimpleCircleGraphicsPdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
static byte[] createSimpleCircleGraphicsPdf(int radius, int gap, int count) throws DocumentException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
float y = writer.getPageSize().getTop();
for (int i = 0; i < count; i++)
{
Rectangle pageSize = writer.getPageSize();
if (y <= pageSize.getBottom() + 2*radius)
{
y = pageSize.getTop();
writer.getDirectContent().fillStroke();
document.newPage();
}
writer.getDirectContent().circle(pageSize.getLeft() + pageSize.getWidth() * Math.random(), y-radius, radius);
y-= 2*radius + gap;
}
writer.getDirectContent().fillStroke();
document.close();
return baos.toByteArray();
}
示例7: createRotatedIndirectTextPdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
static byte[] createRotatedIndirectTextPdf() throws DocumentException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfReader reader = new PdfReader(createSimpleTextPdf());
PdfImportedPage template = writer.getImportedPage(reader, 1);
Rectangle pageSize = reader.getPageSize(1);
writer.getDirectContent().addTemplate(template, .7f, .7f, -.7f, .7f, 400, -200);
document.newPage();
writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
document.close();
return baos.toByteArray();
}
示例8: writeTree
import com.itextpdf.text.Document; //导入方法依赖的package包/类
private void writeTree(Document document) throws DocumentException, IOException {
if(mTreeReport == null) {
return;
}
Paragraph title = createTitleParagraph();
document.add(title);
addSpace(document);
PdfPTable titleTable = new PdfPTable(new float[]{1f, 3f});
titleTable.setWidthPercentage(100f);
getParagraph(titleTable, MobileRangerApplication.getAppContext().getString(R.string.form_date_title), mTreeReport.getDate(), 0);
getParagraph(titleTable, MobileRangerApplication.getAppContext().getString(R.string.form_reporting_employee_title), mTreeReport.getReportingEmployee(), 0);
document.add(titleTable);
addSpace(document);
if(mTreeReport.getLocations() != null && mTreeReport.getLocations().size() > 0) {
for (TreeLocation location : mTreeReport.getLocations()) {
PdfPTable table = createTableForLocation(location);
document.add(table);
document.newPage();
}
}
}
示例9: render
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void render( PdfWriter writer, Document document ) throws PdfRenderException{
writer.setPageEvent(page);
if( page.getBlocks() == null || page.getBlocks().length == 0 ){
writer.setPageEmpty( false );
writer.newPage();
}else{
document.newPage();
PdfContentByte cb = writer.getDirectContent();
for( BaseElement block : page.getBlocks() ){
block.onRender( cb );
}
}
}
示例10: tiff2Pdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void tiff2Pdf(File singleTifFile, File pdfFile) {
// based on tiff2pdf from itext toolbox 0.0.2
// (cfr.http://itexttoolbox.sourceforge.net/doku.php?id=download&DokuWiki=
// ecde1bfec0b8cca87dd8c6c042183992)
try {
RandomAccessFileOrArray ra = new RandomAccessFileOrArray(
singleTifFile.getAbsolutePath());
// RandomAccessFileOrArray ra = new
// RandomAccessFileOrArray(tempByteArray);
int comps = TiffImage.getNumberOfPages(ra);
Document document = new Document(PageSize.A4);
float width = PageSize.A4.getWidth();
float height = PageSize.A4.getHeight();
Image img = TiffImage.getTiffImage(ra, 1);
document.setPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(pdfFile));
// pdf/a
// from
// http://www.opensubscriber.com/message/[email protected]
// .net/7593470.html
// check that it is really pdf/a:
// http://www.intarsys.de/produkte/pdf-a-live/pdf-a-check-1
// => 2 warnings
// Keine eindeutige ID gefunden
// Kein History-Eintrag vorhanden
writer.setPDFXConformance(PdfWriter.PDFA1B);
document.open();
PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
outi.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(
"sRGB IEC61966-2.1"));
outi.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
outi.put(PdfName.S, PdfName.GTS_PDFA1);
ICC_Profile icc = ICC_Profile.getInstance(Thread.currentThread()
.getContextClassLoader().getResourceAsStream(
"/srgb.profile"));
PdfICCBased ib = new PdfICCBased(icc);
ib.remove(PdfName.ALTERNATE);
outi.put(PdfName.DESTOUTPUTPROFILE, writer.addToBody(ib)
.getIndirectReference());
writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS,
new PdfArray(outi));
PdfContentByte cb = writer.getDirectContent();
for (int c = 0; c < comps; ++c) {
img = TiffImage.getTiffImage(ra, c + 1);
if (img != null) {
document.setPageSize(PageSize.A4);
document.newPage();
img.setAbsolutePosition(0, 0);
img.scaleToFit(width, height);
cb.addImage(img);
logger.debug("Finished page " + (c + 1));
}
}
ra.close();
writer.createXmpMetadata();// pdfa
document.close();
} catch (Throwable e) {
// catch Throwable because we encountere a java.lang.InternalError
// cfr. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503430
// probably better to move to later java version for poller
logger.error("Pdf not created", e);
}
}
示例11: testWithWriter
import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Test
public void testWithWriter() throws DocumentException, IOException
{
InputStream resourceStream = getClass().getResourceAsStream("test.pdf");
try
{
PdfReader reader = new PdfReader(resourceStream);
Rectangle pageSize = reader.getPageSize(1);
Rectangle rect = getOutputPageSize(pageSize, reader, 1);
Document document = new Document(rect, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "test-trimmed-writer.pdf")));
document.open();
PdfImportedPage page;
// Go through all pages
int n = reader.getNumberOfPages();
for (int i = 1; i <= n; i++)
{
document.newPage();
page = writer.getImportedPage(reader, i);
System.out.println("BBox: "+ page.getBoundingBox().toString());
Image instance = Image.getInstance(page);
document.add(instance);
Rectangle outputPageSize = document.getPageSize();
System.out.println(outputPageSize.toString());
}
document.close();
}
finally
{
if (resourceStream != null)
resourceStream.close();
}
}
示例12: testBinaryTransparencyBug
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/39119776/itext-binary-transparency-bug">
* iText binary transparency bug
* </a>
* <p>
* Indeed, there is a bug in {@link Image#getInstance(Image, Color, boolean)},
* the loop which determines whether to use a transparency array or a softmask
* is erroneous and here falsely indicates a transparency array suffices.
* </p>
*/
@Test
public void testBinaryTransparencyBug() throws IOException, DocumentException
{
Document document = new Document();
File file = new File(RESULT_FOLDER, "binary_transparency_bug.pdf");
FileOutputStream outputStream = new FileOutputStream(file);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
addBackground(writer);
document.add(new Paragraph("Binary transparency bug test case"));
document.add(new Paragraph("OK: Visible image (opaque pixels are red, non opaque pixels are black)"));
document.add(com.itextpdf.text.Image.getInstance(createBinaryTransparentAWTImage(Color.red,false,null), null));
document.newPage();
addBackground(writer);
document.add(new Paragraph("Suspected bug: invisible image (both opaque an non opaque pixels have the same color)"));
document.add(com.itextpdf.text.Image.getInstance(createBinaryTransparentAWTImage(Color.black,false,null), null));
document.newPage();
addBackground(writer);
document.add(new Paragraph("Analysis: Aliasing makes the problem disappear, because this way the image is not binary transparent any more"));
document.add(com.itextpdf.text.Image.getInstance(createBinaryTransparentAWTImage(Color.black,true,null), null));
document.newPage();
addBackground(writer);
document.add(new Paragraph("Analysis: Setting the color of the transparent pixels to anything but black makes the problem go away, too"));
document.add(com.itextpdf.text.Image.getInstance(createBinaryTransparentAWTImage(Color.black,false,Color.red), null));
document.close();
}
示例13: createSampleDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
byte[] createSampleDocument() throws IOException, DocumentException
{
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() )
{
Document doc = new Document(new RectangleReadOnly(842,595));
PdfWriter.getInstance(doc, baos);
doc.open();
doc.add(new Paragraph("Test Page 1"));
doc.newPage();
doc.add(new Paragraph("Test Page 2"));
doc.close();
return baos.toByteArray();
}
}
示例14: convertToIMG
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public static void convertToIMG(String[] RESOURCES,String result,String path,int s) throws FileNotFoundException, DocumentException, BadElementException, IOException {
System.out.println(":)");
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result));
// step 3
document.open();
// step 4
// Adding a series of images
Image img;
System.out.println(":) :)");
for (String image:RESOURCES) {
System.out.println(image);
img = Image.getInstance(path+image);
document.setPageSize(img);
document.newPage();
img.setAbsolutePosition(0, 0);
document.add(img);
System.out.println(":(");
}
System.out.println(":) :) :) Pdf is outo");
// step 5
document.close();
if(s==1){
JOptionPane.showMessageDialog(null,"Converted Successfully");
//JOptionPane.showMessageDialog(null, "Finished\nFile save in :\nC:\\DjVu++Task\\ImagestoPDF\\"+RESOURCES[0].substring(0,RESOURCES[0].lastIndexOf("."))+".pdf");
}
}
示例15: doInBackground
import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Override
protected Exception doInBackground(String... photos) {
try {
// Get output Directory
// Create the PDF and set some metadata
Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN);
Resources resources = mContext.getResources();
document.addTitle(mFilename);
document.addAuthor(resources.getString(R.string.app_name));
document.addSubject(resources.getString(R.string.file_subject));
// Open the file that we will write the pdf to.
java.io.File fileContent = new java.io.File(ImageUtils.getAlbumStorageDir(MainActivity.ALBUM_NAME) + mFilename);
OutputStream outputStream = new FileOutputStream(fileContent);
PdfWriter.getInstance(document, outputStream);
document.open();
// Get the document's size
Rectangle pageSize = document.getPageSize();
float pageWidth = pageSize.getWidth() - (document.leftMargin() + document.rightMargin());
float pageHeight = pageSize.getHeight();
//Loop through images and add them to the document
for (String path : photos) {
Image image = Image.getInstance(path);
image.scaleToFit(pageWidth, pageHeight);
document.add(image);
document.newPage();
}
// Cleanup
document.close();
outputStream.close();
// Upload time!
FileContent mediaContent = new FileContent("application/pdf", fileContent);
File body = new File();
if (mFolder != null)
body.setParents(Arrays.asList(new ParentReference().setId(mFolder.getId())));
body.setTitle(mFilename);
body.setDescription(resources.getString(R.string.file_subject));
body.setMimeType("application/pdf");
Drive.Files.Insert insert = mService.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
uploader.setProgressListener(new FileProgressListener());
File file = insert.execute();
Log.d("C2P", "File Id: " + file.getId());
/* Database Code */
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
//file.getFileSize().toString()
String parentFolder = mFolder != null ? mFolder.getId() : "root";
Long size = file.getFileSize();
String fileSizeString = humanReadableByteCount(size);
Upload upload = new Upload(-1, mFilename, mFolderPath, fileSizeString, parentFolder, format.format(date), mService.about().get().execute().getUser().getEmailAddress());
UploadDataAdapter mUploadDataAdapter = new UploadDataAdapter(mContext);
mUploadDataAdapter.open();
mUploadDataAdapter.addUpload(upload);
mUploadDataAdapter.close();
} catch (Exception e) {
Log.d("C2P", "ERROR", e);
return e;
}
return null;
}