Refine search
PdfDocument pdf = new PdfDocument(); PdfWriter writer = PdfWriter.getInstance(pdf, outputStream); pdf.addWriter(writer); int w = (int) (pageSize.getWidth() * 0.9); int h = (int) (pageSize.getHeight() * 0.95); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h);
PdfDocument doc = new PdfDocument(); // Read the image as BufferedImage object BufferedImage bufImg = ImageIO.read(new File( "SampleImage.PNG")); // Create PdfImage object using the above BufferedImage object PdfImage img = PdfImage.create(bufImg); // Create a PdfPage of image size (image width x image Height) PdfPage page1 = new PdfPage(img.width(), img.height()); // draw the image at 0, 0 page1.drawImage(img, 0, 0); // add the page to the document object doc.add(page1); // save the document to the output file doc.save("PNGImageToPDF.pdf"); doc.close();
/** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. * * @return a new <CODE>PdfWriter</CODE> * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>OutputStream</CODE> the writer has to write to. * @param listener A <CODE>DocListener</CODE> to pass to the PdfDocument. * @throws DocumentException on error */ public static PdfWriter getInstance(final Document document, final OutputStream os, final DocListener listener) throws DocumentException { PdfDocument pdf = new PdfDocument(); pdf.addDocListener(listener); document.addDocListener(pdf); PdfWriter writer = new PdfWriter(pdf, os); pdf.addWriter(writer); return writer; }
using BitMiracle.Docotic.Pdf; namespace JavascriptInPdf { public static class Demo { public static void Main(string[] args) { PdfDocument pdf = new PdfDocument(); pdf.OnOpenDocument =pdf.CreateJavaScriptAction("app.alert(\"Hello CodeProject!\", 3);"); pdf.Save("Hello world.pdf"); } } }
PdfDocument doc = new PdfDocument(); doc.load("Input_Docs\\input_doc.pdf"); // Obtain all website addresses in page 2 ArrayList lstSearchResults = (ArrayList) doc.search("http://{1}", // regular expression 2, // page number PdfSearchMode.REGEX, PdfSearchOptions.NONE);
flushFloatingElements(); break; case Element.LANGUAGE: setLanguage(((Meta)element).getContent()); break; case Element.PRODUCER: carriageReturn(); carriageReturn(); boolean newlineSplit = chunk.isNewlineSplit(); chunk = overflow; newPage(); String url = anchor.getReference(); leading = anchor.getLeading(); pushLeading(); if (url != null) { anchorAction = new PdfAction(url); popLeading(); break; carriageReturn(); rect = new Rectangle(annot.llx(indentRight() - line.widthLeft()), annot.ury(indentTop() - currentHeight - 20), annot.urx(indentRight() - line.widthLeft() + 20), annot.lly(indentTop() - currentHeight)); PdfAnnotation an = PdfAnnotationsImp.convertAnnotation(writer, annot, rect);
if (isTagged(writer)) { graphics = writer.getDirectContentUnder().getDuplicate(); writer.getDirectContent().duplicatedFrom = graphics; } else { graphics = new PdfContentByte(writer); setNewPageSizeAndMargins(); imageEnd = -1; indentation.imageIndentRight = 0; || pageSize.hasBorders() || pageSize.getBorderColor() != null) { add(pageSize); add(imageWait); imageWait = null; carriageReturn(); PdfPageEvent pageEvent = writer.getPageEvent(); if (pageEvent != null) { if (firstPageEvent) {
throw new RuntimeException("The page " + pageReferences.size() + " was requested but the document has only " + (currentPageNumber - 1) + " pages."); pdf.close(); try { addSharedObjectsToBody(); for (PdfOCG layer : documentOCG) { addToBody(layer.getPdfObject(), layer.getRef()); PdfDictionary catalog = getCatalog(rootRef); if (!documentOCG.isEmpty()) PdfWriter.checkPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_LAYER, OCProperties);
PdfDocument document = new PdfDocument(); PdfDocument.Page page = document.startPage(pageInfo); document.finishPage(page); PdfDocument.Page page = document.startPage(pageInfo); document.finishPage(page); fos = new FileOutputStream(fileNameWithPath, false); document.writeTo(fos); document.close();
super(new PdfDocument(), os); if (!reader.isOpenedWithFullPermissions()) throw new BadPasswordException(MessageLocalization.getComposedMessage("pdfreader.not.opened.with.owner.password")); } else { if (pdfVersion == 0) super.setPdfVersion(reader.getPdfVersion()); else super.setPdfVersion(pdfVersion); super.open(); pdf.addWriter(this); if (append) { body.setRefnum(reader.getXrefSize());
PdfCopyFieldsImp(OutputStream os, char pdfVersion) throws DocumentException { super(new PdfDocument(), os); pdf.addWriter(this); if (pdfVersion != 0) super.setPdfVersion(pdfVersion); nd = new Document(); nd.addDocListener(pdf); }
public static ExtendedPdfWriter getInstance( Document document, OutputStream os ) throws DocumentException { PdfDocument pdf = new PdfDocument(); document.addDocListener( pdf ); ExtendedPdfWriter writer = new ExtendedPdfWriter( pdf, os ); pdf.addWriter( writer ); return writer; } }
/** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. * * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>OutputStream</CODE> the writer has to write to. * @return a new <CODE>PdfWriter</CODE> * * @throws DocumentException on error */ public static PdfWriter getInstance(final Document document, final OutputStream os) throws DocumentException { PdfDocument pdf = new PdfDocument(); document.addDocListener(pdf); PdfWriter writer = new PdfWriter(pdf, os); pdf.addWriter(writer); return writer; }
PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdf); document.add(createTable(rohit)); document.add(createTable(bruno)); document.close();
/** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>OutputStream</CODE> the writer has to write to. * @param listener A <CODE>DocListener</CODE> to pass to the PdfDocument. * @param conformanceLevel PDF/A conformance level of a new PDF document * @return a new <CODE>PdfWriter</CODE> * @throws DocumentException on error */ public static PdfAWriter getInstance(final Document document, final OutputStream os, final DocListener listener, final PdfAConformanceLevel conformanceLevel) throws DocumentException { PdfDocument pdf = new PdfDocument(); pdf.addDocListener(listener); document.addDocListener(pdf); PdfAWriter writer = new PdfAWriter(pdf, os, conformanceLevel); pdf.addWriter(writer); return writer; }
// create a new document PdfDocument document = new PdfDocument(); // crate a page description PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create(); // start a page Page page = document.startPage(pageInfo); // draw something on the page View content = getContentView(); content.draw(page.getCanvas()); // finish the page document.finishPage(page); . . . // add more pages . . . // write the document content document.writeTo(getOutputStream()); // close the document document.close();
protected void setNewPageSizeAndMargins() { pageSize = nextPageSize; if (marginMirroring && (getPageNumber() & 1) == 0) { marginRight = nextMarginLeft; marginLeft = nextMarginRight; } else { marginLeft = nextMarginLeft; marginRight = nextMarginRight; } if (marginMirroringTopBottom && (getPageNumber() & 1) == 0) { marginTop = nextMarginBottom; marginBottom = nextMarginTop; } else { marginTop = nextMarginTop; marginBottom = nextMarginBottom; } if (!isTagged(writer)) { text = new PdfContentByte(writer); text.reset(); } else { text = graphics; } text.beginText(); // we move to the left/top position of the page text.moveText(left(), top()); if (isTagged(writer)) textEmptySize = text.size(); }
public static float getAvailableHeight(PdfDocument pdfDocument) { Float indentBottom = pdfDocument.bottomMargin(); try { Method method = pdfDocument.getClass().getDeclaredMethod("indentBottom"); method.setAccessible(true); indentBottom = (Float) method.invoke(pdfDocument); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } float offset = pdfDocument.top() - pdfDocument.getVerticalPosition(false); return pdfDocument.getPageSize().getHeight() - offset - pdfDocument.topMargin() - indentBottom - pdfDocument.bottomMargin(); }
/** * Signals that the <CODE>Document</CODE> was closed and that no other * <CODE>Elements</CODE> will be added. * <P> * The pages-tree is built and written to the outputstream. * A Catalog is constructed, as well as an Info-object, * the reference table is composed and everything is written * to the outputstream embedded in a Trailer. */ @Override public void close() { if (open) { pdf.close(); super.close(); // Users are responsible for closing PdfReader // if (ri != null) { // try { // ri.getReader().close(); // ri.getReaderFile().close(); // } // catch (IOException ioe) { // // empty on purpose // } // } } }
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC)); PdfObject obj; for (int i = 1; i <= pdfDoc.getNumberOfPdfObjects(); i++) { obj = pdfDoc.getPdfObject(i); if (obj != null && obj.isStream()) { byte[] b; try { b = ((PdfStream) obj).getBytes(); } catch (PdfException exc) { b = ((PdfStream) obj).getBytes(false); } FileOutputStream fos = new FileOutputStream(String.format(DEST, i)); fos.write(b); fos.close(); } } pdfDoc.close();