本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.getImportedPage方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.getImportedPage方法的具體用法?Java PdfWriter.getImportedPage怎麽用?Java PdfWriter.getImportedPage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfWriter
的用法示例。
在下文中一共展示了PdfWriter.getImportedPage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRotateAndZoomUpperHalfPage
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/35374110/how-do-i-use-itext-to-have-a-landscaped-pdf-on-half-of-a-a4-back-to-portrait-and">
* How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
* </a>
* <p>
* This sample shows how to rotate and enlarge the upper half of an A4 page to fit into a new A4 page.
* </p>
*/
@Test
public void testRotateAndZoomUpperHalfPage() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-upperHalf.pdf")) )
{
PdfReader reader = new PdfReader(resource);
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, result);
document.open();
double sqrt2 = Math.sqrt(2);
Rectangle pageSize = reader.getPageSize(1);
PdfImportedPage importedPage = writer.getImportedPage(reader, 1);
writer.getDirectContent().addTemplate(importedPage, 0, sqrt2, -sqrt2, 0, pageSize.getTop() * sqrt2, -pageSize.getLeft() * sqrt2);
document.close();
}
}
示例2: createMultiUseIndirectTextPdf
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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: createRotatedIndirectTextPdf
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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();
}
示例4: testWithWriter
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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();
}
}