private void addContent(PdfWriter writer) throws DocumentException, PdfFormatierungsException { Anchor anchor = new Anchor("Lernentwicklungsbericht", lernentwicklungsberichtUeberschriftFont); Chapter chapterLEB = new Chapter(new Paragraph(anchor), 1); chapterLEB.setNumberDepth(0); Paragraph paragraphHeader = new Paragraph(); paragraphHeader.setLeading(FIXED_LEADING_TEXT, 1); sectionCount += 1; Section headerSection = chapterLEB.addSection(paragraphHeader); headerSection.setNumberDepth(0); paragraphHeader.add(Chunk.NEWLINE); paragraphHeader.add(PdfFormatHelper.buildHeaderNameLine(lebData.getSchuelername() , headerFont)); paragraphHeader.add(Chunk.NEWLINE); paragraphHeader.add(PdfFormatHelper.buildHeaderKlassendatenLine(lebData, headerFont)); headerSection.add(Chunk.NEWLINE); headerSection.add(Chunk.NEWLINE); document.add(chapterLEB); insertDummyLineIfNecessary(writer); addKlassenbrief(chapterLEB, writer); addIndividuelleEinschaetzung(chapterLEB, writer); addFacheinschaetzungen(chapterLEB, writer); }
@Override public void process(int level, Node node, InvocationContext context) { ExpLinkNode linkNode = (ExpLinkNode) node; String url = context.variableResolver().resolve(linkNode.url); Font anchorFont = new FontCopier(context.peekFont()) .style(Font.UNDERLINE) .color(Colors.DARK_RED) .get(); context.pushFont(anchorFont); List<Element> subs = context.collectChildren(level, node); context.popFont(); Phrase p = new Phrase(); p.addAll(subs); Anchor anchor = new Anchor(p); anchor.setReference(url); context.append(anchor); }
/** * Footer of the document Adds table, new line Adds company web address */ private void documentFooter(Document doc, PdfPTable table) { try { //add the PDF table to the paragraph Paragraph paragraph = new Paragraph(); paragraph.add(table); // add the paragraph to the document doc.add(paragraph); //this paragraph contains table Paragraph line = new Paragraph("\n\n"); doc.add(line); //insert anchor tag in pdf Paragraph anchorPara = new Paragraph(); anchorPara.add(new Phrase("our website : ")); Anchor anchor = new Anchor("http://yourwebsite.com"); anchor.setReference("http://yourwebsite.com"); anchorPara.add(anchor); doc.add(anchorPara); } catch (DocumentException ex) { Logger.getLogger(ReportController.class .getName()).log(Level.SEVERE, null, ex); } }
private void renderTextToContainer(final String text) { String str = ctx.stringTransform(ITextUtil.normalizeSpaces(text)); final Chunk c = new Chunk(str); c.setFont(ctx.getFont(Font.NORMAL)); if (ctx.isMustAddAnchor()) { Anchor a = new Anchor(c); a.setFont(ctx.getFont(Font.NORMAL)); a.setName(ctx.getCurrentId()); ctx.addToContainer(a); ctx.setMustAddAnchor(false); } else { ctx.addToContainer(c); } }
/** * <a href="http://stackoverflow.com/questions/34408764/create-local-link-in-rotated-pdfpcell-in-itextsharp"> * Create local link in rotated PdfPCell in iTextSharp * </a> * <p> * This is the equivalent Java code for the C# code in the question. Indeed, this code * also gives rise to the broken result. The cause is simple: Normally iText does not * touch the current transformation matrix. So the chunk link creation code assumes the * current user coordinate system to be the same as used for positioning annotations. * But in case of rotated cells iText does change the transformation matrix and * consequently the chunk link creation code positions the annotation at the wrong * location. * </p> */ @Test public void testCreateLocalLinkInRotatedCell() throws IOException, DocumentException { Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "local-link.pdf"))); doc.open(); PdfPTable linkTable = new PdfPTable(2); PdfPCell linkCell = new PdfPCell(); linkCell.setHorizontalAlignment(Element.ALIGN_CENTER); linkCell.setRotation(90); linkCell.setFixedHeight(70); Anchor linkAnchor = new Anchor("Click here"); linkAnchor.setReference("#target"); Paragraph linkPara = new Paragraph(); linkPara.add(linkAnchor); linkCell.addElement(linkPara); linkTable.addCell(linkCell); PdfPCell linkCell2 = new PdfPCell(); Anchor linkAnchor2 = new Anchor("Click here 2"); linkAnchor2.setReference("#target"); Paragraph linkPara2 = new Paragraph(); linkPara2.add(linkAnchor2); linkCell2.addElement(linkPara2); linkTable.addCell(linkCell2); linkTable.addCell(new PdfPCell(new Phrase("cell 3"))); linkTable.addCell(new PdfPCell(new Phrase("cell 4"))); doc.add(linkTable); doc.newPage(); Anchor destAnchor = new Anchor("top"); destAnchor.setName("target"); PdfPTable destTable = new PdfPTable(1); PdfPCell destCell = new PdfPCell(); Paragraph destPara = new Paragraph(); destPara.add(destAnchor); destCell.addElement(destPara); destTable.addCell(destCell); destTable.addCell(new PdfPCell(new Phrase("cell 2"))); destTable.addCell(new PdfPCell(new Phrase("cell 3"))); destTable.addCell(new PdfPCell(new Phrase("cell 4"))); doc.add(destTable); doc.close(); }
public PDFAnchor(boolean decapitalize, String text, PDFFont font) { super(decapitalize, text, font); m_anchor = new Anchor(text, font.getFont()); }
public Anchor getAnchor() { return m_anchor; }
public static Chapter createChapter(String chapterName, int chapterNumber) { Anchor anchor = new Anchor(chapterName, HEADER_FONT); anchor.setName(chapterName); Chapter chapter = new Chapter(new Paragraph(chapterName, CAT_FONT), chapterNumber); return chapter; }
/** * generate iText-PDF-Contents for the title page * * @return * @throws ImageOpException * @throws IOException */ public Element getPageContents() throws IOException, ImageOpException{ Paragraph content = new Paragraph(); content.setAlignment(Element.ALIGN_CENTER); // add vertical whitespace for(int i=0; i<8; i++){ content.add(Chunk.NEWLINE); } // add logo content.add(getLogo()); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add title Anchor title = new Anchor(new Paragraph(getTitle(),FontFactory.getFont(FontFactory.HELVETICA,16))); String burl = job_info.getImageJobInformation().getAsString("base.url"); title.setReference(burl+"digilib.html?fn="+job_info.getImageJobInformation().getAsString("fn")); content.add(title); content.add(Chunk.NEWLINE); // add author if(getDate()!=" ") content.add(new Paragraph(getAuthor()+" ("+getDate()+")",FontFactory.getFont(FontFactory.HELVETICA,14))); else content.add(new Paragraph(getAuthor(),FontFactory.getFont(FontFactory.HELVETICA,14))); content.add(Chunk.NEWLINE); // add page numbers content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12))); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add digilib version content.add(new Paragraph(getDigilibVersion(),FontFactory.getFont(FontFactory.HELVETICA,10))); for(int i=0; i<8; i++){ content.add(Chunk.NEWLINE); } Anchor address = new Anchor( new Paragraph(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9)) ); address.setReference(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn")); content.add(address); return content; }