本文整理汇总了Java中com.itextpdf.text.Document.setPageSize方法的典型用法代码示例。如果您正苦于以下问题:Java Document.setPageSize方法的具体用法?Java Document.setPageSize怎么用?Java Document.setPageSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.Document
的用法示例。
在下文中一共展示了Document.setPageSize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public Document createDocument(File pdfFile) throws DocumentException, IOException{
Document document = new Document(new Rectangle(pageWidth, pageHeight));
document.setPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
//写入页尾
this.setFooter(writer);
writer.setFullCompression();
writer.setPdfVersion(PdfWriter.VERSION_1_4);
document.open();
// //加入二维码图片
// Image image = Image.getInstance(System.getProperty(appConfig.getValue("app.root"))+"/images/logoqrcode.png");
// image.scaleAbsolute(40,40);//控制图片大小
// image.setAlignment(Image.LEFT);
// document.add(image);
return document;
}
示例2: makePDF
import com.itextpdf.text.Document; //导入方法依赖的package包/类
private static void makePDF(Bitmap bmp, File file) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(file));
document.addAuthor(FullscreenActivity.mAuthor.toString());
document.addTitle(FullscreenActivity.mTitle.toString());
document.addCreator("OpenSongApp");
if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
document.setPageSize(PageSize.A4.rotate());
} else {
document.setPageSize(PageSize.A4);
}
document.addTitle(FullscreenActivity.mTitle.toString());
document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
Font TitleFontName = new Font(urName, 14);
Font AuthorFontName = new Font(urName, 10);
document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
addImage(document,bmp);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: 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);
}
}
示例4: testCreateLandscapeDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/47209312/i-have-a-trouble-with-lowagie-pdf-and-report-making-i-cant-include-headerfooter">
* I have a trouble with lowagie pdf and Report Making. I cant include headerfooter on the first page
* </a>
* <p>
* This example shows how to generate a PDF with page level
* settings (page size, page margins) customized already on
* the first page.
* </p>
*/
@Test
public void testCreateLandscapeDocument() throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "landscape.pdf")));
document.setPageSize(PageSize.A4.rotate());
document.setMargins(60, 30, 30, 30);
document.open();
document.add(new Paragraph("Test string for a landscape PDF."));
document.close();
}
示例5: 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");
}
}
示例6: testGradientOnRotatedPage
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/39072316/itext-gradient-issue-in-landscape">
* iText gradient issue in landscape
* </a>
* <p>
* The problem is that while itext content adding functionalities <b>do</b> take the page
* rotation into account (they translate the given coordinates so that in the rotated page
* <em>x</em> goes right and <em>y</em> goes up and the origin is in the lower left), the
* shading pattern definitions (which are <em>not</em> part of the page content but
* externally defined) <b>don't</b>.
* </p>
* <p>
* Thus, you have to make the shading definition rotation aware, e.g. like this.
* </p>
*/
@Test
public void testGradientOnRotatedPage() throws FileNotFoundException, DocumentException
{
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "gradientProblem.pdf")));
doc.open();
drawSexyTriangle(writer, false);
doc.setPageSize(PageSize.A4.rotate());
doc.newPage();
drawSexyTriangle(writer, true);
doc.close();
}
示例7: writeChartsToPDF
import com.itextpdf.text.Document; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void writeChartsToPDF(List<JFreeChart> charts, int width, int height, OutputStream outputStream, String hostname, Date date) {
PdfWriter writer = null;
Document document = new Document();
try {
writer = PdfWriter.getInstance(document, outputStream);
writer.setPageEmpty(false);
document.open();
document.setPageSize(PageSize.A4);
document.add(new Paragraph("Aggregates Report generated by " + hostname + " on " + date.toString()));
document.newPage();
writer.newPage();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template;
Graphics2D graphics2d;
int position = 0;
Rectangle2D rectangle2d;
for (JFreeChart chart : charts){
LOG.debug("Writing chart to PDF");
if (writer.getVerticalPosition(true)-height+(height*position) < 0){
position = 0;
document.newPage();
writer.newPage();
}
template = contentByte.createTemplate(width, height);
graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
rectangle2d = new Rectangle2D.Double(0, 0, width, height);
chart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 38, writer.getVerticalPosition(true)-height+(height*position));
position--;
}
} catch (Exception e) {
e.printStackTrace();
}
document.close();
}