當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.setPageSize方法代碼示例

本文整理匯總了Java中com.lowagie.text.Document.setPageSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.setPageSize方法的具體用法?Java Document.setPageSize怎麽用?Java Document.setPageSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.Document的用法示例。


在下文中一共展示了Document.setPageSize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: OscarChartPrinter

import com.lowagie.text.Document; //導入方法依賴的package包/類
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
	this.request = request;
	this.os = os;

	document = new Document();
	// writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
	
    writer = PdfWriter.getInstance(document,os);
	writer.setPageEvent(new EndPage());
	document.setPageSize(PageSize.LETTER);
	document.open();
	//Create the font we are going to print to
       bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
       font = new Font(bf, FONTSIZE, Font.NORMAL);
       boldFont = new Font(bf,FONTSIZE,Font.BOLD);
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:17,代碼來源:OscarChartPrinter.java

示例2: PdfRecordPrinter

import com.lowagie.text.Document; //導入方法依賴的package包/類
public PdfRecordPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
    this.request = request;
    this.os = os;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");

    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriter.getInstance(document,os);
    writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    
    document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:21,代碼來源:PdfRecordPrinter.java

示例3: start

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void start() throws DocumentException,IOException {
    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
    // writer = PdfWriter.getInstance(document,os);
    // writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:17,代碼來源:PdfRecordPrinter.java

示例4: printPdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Prints the consultation request.
 * @throws IOException when an error with the output stream occurs
 * @throws DocumentException when an error in document construction occurs
 */
public void printPdf(LoggedInInfo loggedInInfo) throws IOException, DocumentException {

	// Create the document we are going to write to
	document = new Document();
	// PdfWriter.getInstance(document, os);
	PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

	document.setPageSize(PageSize.LETTER);
	document.addTitle(getResource("msgConsReq"));
	document.addCreator("OSCAR");
	document.open();

	// Create the fonts that we are going to use
	bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
			BaseFont.NOT_EMBEDDED);
	headerFont = new Font(bf, 14, Font.BOLD);
	infoFont = new Font(bf, 12, Font.NORMAL);
	font = new Font(bf, 9, Font.NORMAL);
	boldFont = new Font(bf, 10, Font.BOLD);
	bigBoldFont = new Font(bf, 12, Font.BOLD);

	createConsultationRequest(loggedInInfo);

	document.close();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:31,代碼來源:ConsultationPDFCreator.java

示例5: addDocumentProps

import com.lowagie.text.Document; //導入方法依賴的package包/類
private void addDocumentProps(Document document, String title, Properties props) {
    document.addTitle(title);
    document.addSubject("");
    document.addKeywords("pdf, itext");
    document.addCreator("OSCAR");
    document.addAuthor("");
    
    // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA
    // and FLSE
    // the following shows a temp way to get a print page size
    final String PAGESIZE = "printPageSize";
    Rectangle pageSize = PageSize.LETTER;
    if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.HALFLETTER;
    if ("PageSize.A6".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.A6;
    document.setPageSize(pageSize);
    document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:20,代碼來源:EFormPDFServlet.java

示例6: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
	if (args.length < 3) {
		System.err.println("OddEven needs 3 Arguments.");
		System.out
				.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
		return;
	}
	RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
	RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
	Image img = TiffImage.getTiffImage(odd, 1);
	Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
	for (int c = 0; c < count; ++c) {

		Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
		Image imgEven = TiffImage.getTiffImage(even, count - c);
		document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
		document.newPage();
		imgOdd.setAbsolutePosition(0, 0);
		cb.addImage(imgOdd);
		document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
		document.newPage();
		imgEven.setAbsolutePosition(0, 0);
		cb.addImage(imgEven);

	}
	odd.close();
	even.close();
	document.close();

}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:42,代碼來源:OddEvenTest.java

示例7: start

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void start() throws DocumentException, IOException {
	//Create the font we are going to print to
	bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
	font = new Font(bf, FONTSIZE, Font.NORMAL);
	boldFont = new Font(bf, FONTSIZE, Font.BOLD);

	document = new Document();
	writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
	writer.setStrictImageSequence(true);

	document.setPageSize(PageSize.LETTER);
	document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:14,代碼來源:TicklerPrinter.java

示例8: printRtf

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void printRtf()throws IOException, DocumentException{
	//create an input stream from the rtf string bytes
	byte[] rtfBytes = handler.getOBXResult(0, 0).getBytes();
	ByteArrayInputStream rtfStream = new ByteArrayInputStream(rtfBytes);
	
	//create & open the document we are going to write to and its writer
	document = new Document();
	RtfWriter2 writer = RtfWriter2.getInstance(document,os);
	document.setPageSize(PageSize.LETTER);
	document.addTitle("Title of the Document");
	document.addCreator("OSCAR");
	document.open();
	
    //Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, 11, Font.NORMAL);
    boldFont = new Font(bf, 12, Font.BOLD);
 //   redFont = new Font(bf, 11, Font.NORMAL, Color.RED);
    
    //add the patient information
    addRtfPatientInfo();
    
    //add the results
	writer.importRtfDocument(rtfStream, null);
	
	document.close();
	os.flush();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:29,代碼來源:LabPDFCreator.java

示例9: printPdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void printPdf() throws IOException, DocumentException{

        // check that we have data to print
        if (handler == null)
            throw new DocumentException();

        //response.setContentType("application/pdf");  //octet-stream
        //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\"");

        //Create the document we are going to write to
        document = new Document();
        //PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        // PdfWriter writer = PdfWriter.getInstance(document, os);
        PdfWriter writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

        //Set page event, function onEndPage will execute each time a page is finished being created
        writer.setPageEvent(this);

        document.setPageSize(PageSize.LETTER);
        document.addTitle("Title of the Document");
        document.addCreator("OSCAR");
        document.open();

        //Create the fonts that we are going to use
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 9, Font.NORMAL);
        boldFont = new Font(bf, 10, Font.BOLD);
      //  redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

        // add the header table containing the patient and lab info to the document
        createInfoTable();

        // add the tests and test info for each header
        ArrayList<String> headers = handler.getHeaders();
        for (int i=0; i < headers.size(); i++)
            addLabCategory( headers.get(i) ,null);

        for(MessageHandler extraHandler:handlers) {
        	ArrayList<String> extraHeaders = extraHandler.getHeaders();
            for (int i=0; i < extraHeaders.size(); i++)
                addLabCategory( extraHeaders.get(i) , extraHandler);
        }
        // add end of report table
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setPhrase(new Phrase("  "));
        table.addCell(cell);
        cell.setBorder(15);
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPhrase(new Phrase("END OF REPORT", boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        document.add(table);

        document.close();

        os.flush();
    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:62,代碼來源:LabPDFCreator.java

示例10: generatePDFDataEntryForm

import com.lowagie.text.Document; //導入方法依賴的package包/類
@Override
public void generatePDFDataEntryForm( Document document, PdfWriter writer, String dataSetUid, int typeId,
    Rectangle pageSize, PdfFormFontSettings pdfFormFontSettings, I18nFormat format )
{
    try
    {
        this.pdfFormFontSettings = pdfFormFontSettings;
        this.format = format;

        document.setPageSize( pageSize );

        document.open();

        if ( typeId == PdfDataEntryFormUtil.DATATYPE_DATASET )
        {
            setDataSet_DocumentContent( document, writer, dataSetUid );
        }
        else if ( typeId == PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
        {
            setProgramStage_DocumentContent( document, writer, dataSetUid );
        }
    }
    catch ( Exception ex )
    {
        throw new RuntimeException( ex );
    }
    finally
    {
        document.close();
    }
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:32,代碼來源:DefaultPdfDataEntryFormService.java

示例11: paintToPDF

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void paintToPDF(JEditorPane jep,File file) {
  try {
    jep.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));

    Document document = new Document();
    FileOutputStream fos = new FileOutputStream(file);
    PdfWriter writer = PdfWriter.getInstance(document, fos);

    document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    cb.saveState();
    cb.concatCTM(1, 0, 0, 1, 0, 0);

    DefaultFontMapper mapper = new DefaultFontMapper();
    mapper.insertDirectory("c:/windows/fonts");

    Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);

    AffineTransform at = new AffineTransform();
    at.translate(convertToPixels(20), convertToPixels(20));
    at.scale(pixelToPoint, pixelToPoint);

    g2.transform(at);

    g2.setColor(Color.WHITE);
    g2.fill(jep.getBounds());

    Rectangle alloc = getVisibleEditorRect(jep);
    jep.getUI().getRootView(jep).paint(g2, alloc);

    g2.setColor(Color.BLACK);
    g2.draw(jep.getBounds());

    g2.dispose();
    cb.restoreState();
    document.close();
    fos.flush();
    fos.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
開發者ID:ksaluja24,項目名稱:scratch-bench,代碼行數:45,代碼來源:MainMenu.java

示例12: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Creates a PDF document with pages in portrait/landscape.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4.rotate());

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LandscapePortrait.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some content
	document.add(new Paragraph(
			"To create a document in landscape format, just make the height smaller than the width. For instance by rotating the PageSize Rectangle: PageSize.A4.rotate()"));
	document.setPageSize(PageSize.A4);
	document.newPage();
	document.add(new Paragraph("This is portrait again"));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:29,代碼來源:LandscapePortraitTest.java

示例13: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Creates a PDF document with a certain pagesize
 * 
 * @param args
 *            no arguments needed here
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("DefaultPageSize.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some paragraphs to the document
	document.add(new Paragraph("The default PageSize is DIN A4."));
	document.setPageSize(PageSize.A3);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A3."));
	document.setPageSize(PageSize.A2);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A2."));
	document.setPageSize(PageSize.A1);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A1."));
	document.setPageSize(PageSize.A0);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A0."));
	document.setPageSize(PageSize.A5);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A5."));
	document.setPageSize(PageSize.A6);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A6."));
	document.setPageSize(PageSize.A7);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A7."));
	document.setPageSize(PageSize.A8);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A8."));
	document.setPageSize(PageSize.LETTER);
	document.newPage();
	document.add(new Paragraph("This PageSize is LETTER."));
	document.add(new Paragraph("A lot of other standard PageSizes are available."));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:56,代碼來源:DefaultPageSizeTest.java

示例14: printPdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void printPdf() throws IOException, DocumentException{

        // check that we have data to print
        if (report == null)
            throw new DocumentException();

         //Create the document we are going to write to
        document = new Document();
  
        PdfWriter writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

        //Set page event, function onEndPage will execute each time a page is finished being created
        writer.setPageEvent(this);

        document.setPageSize(PageSize.LETTER);
        document.addTitle("HRM Report");
        document.addCreator("OSCAR");
        document.open();

        //Create the fonts that we are going to use
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 9, Font.NORMAL);
        boldFont = new Font(bf, 10, Font.BOLD);
      //  redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

        
        // add the header table containing the patient and lab info to the document
        createInfoTable();

        // add end of report table
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setPhrase(new Phrase("  "));
        table.addCell(cell);
        cell.setBorder(15);
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPhrase(new Phrase("END OF REPORT", boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        document.add(table);

        document.close();

        os.flush();
    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:49,代碼來源:HrmPDFCreator.java

示例15: printPdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
public void printPdf(LoggedInInfo loggedInInfo) throws IOException, DocumentException{

        EctConsultationFormRequestUtil reqForm = new EctConsultationFormRequestUtil();
        reqForm.estRequestFromId(loggedInInfo, (String) request.getAttribute("reqId"));

        // init req form info
        reqForm.specAddr = request.getParameter("address");
        if (reqForm.specAddr == null){reqForm.specAddr = new String(); }
        reqForm.specPhone = request.getParameter("phone");
        if (reqForm.specPhone == null){ reqForm.specPhone = ""; }
        reqForm.specFax = request.getParameter("fax");
        if (reqForm.specFax == null){ reqForm.specFax = ""; }

        //Create new file to save form to
        String path = OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
        String fileName = path + "ConsultationRequestForm-"+UtilDateUtilities.getToday("yyyy-MM-dd.hh.mm.ss")+".pdf";
        FileOutputStream out = new FileOutputStream(fileName);

        //Create the document we are going to write to
        document = new Document();
        // writer = PdfWriter.getInstance(document,out);
        writer = PdfWriterFactory.newInstance(document, out, FontSettings.HELVETICA_6PT);

        //Use the template located at '/oscar/oscarEncounter/oscarConsultationRequest/props'
        reader = new PdfReader("/oscar/oscarEncounter/oscarConsultationRequest/props/consultationFormRequest.pdf");
        Rectangle pSize = reader.getPageSize(1);
        height = pSize.getHeight();
        document.setPageSize(pSize);

        document.addTitle("Consultation Form Request");
        document.addCreator("OSCAR");
        document.open();

        //Create the font we are going to print to
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        cb = writer.getDirectContent();
        ct = new ColumnText(cb);
        cb.setColorStroke(new Color(0,0,0));

        // start writing the pdf document
        PdfImportedPage page1 = writer.getImportedPage(reader, 1);
        cb.addTemplate(page1, 1, 0, 0, 1, 0, 0);
        // addFooter();
        setAppointmentInfo(reqForm);

        // add the dynamically positioned text elements
        float dynamicHeight = 0;
        dynamicHeight = addDynamicPositionedText("Reason For Consultation: ", reqForm.reasonForConsultation, dynamicHeight, reqForm);
        dynamicHeight = addDynamicPositionedText("Pertinent Clinical Information: ", reqForm.clinicalInformation, dynamicHeight, reqForm);
        dynamicHeight = addDynamicPositionedText("Significant Concurrent Problems: ", reqForm.concurrentProblems, dynamicHeight, reqForm);
        dynamicHeight = addDynamicPositionedText("Current Medications: ", reqForm.currentMedications, dynamicHeight, reqForm);
        dynamicHeight = addDynamicPositionedText("Allergies: ", reqForm.allergies, dynamicHeight, reqForm);

        document.close();
        reader.close();
        writer.close();
        out.close();

        // combine the recently created pdf with any pdfs that were added to the consultation request form
        combinePDFs(loggedInInfo, fileName);

    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:64,代碼來源:EctConsultationFormRequestPrintPdf.java


注:本文中的com.lowagie.text.Document.setPageSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。