Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.sales.quote.report;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfBorderArray;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class PaypalStamper {
public static void main(String[] args) throws Exception {
final PaypalStamper s = new PaypalStamper();
s.addLink(new File("Facture_2018-11-00422.pdf"), new File("paypal.pdf"), 33, 72, "https://www.openconerto.org");
}
/**
* @param x : 0 - 440
* @param y : 0 - 780
*/
public void addLink(File inFile, File outFile, int x, int y, String hyperlink) throws Exception {
if (hyperlink == null) {
throw new IllegalArgumentException("null link");
}
final PdfReader reader = new PdfReader(new FileInputStream(inFile));
final PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile));
final int page = reader.getNumberOfPages();
final Image img = Image.getInstance(this.getClass().getResource("payer-avec-paypal.png"));
final float w = img.getScaledWidth() / 3;
final float h = img.getScaledHeight() / 3;
// Add image on last page
stamper.getOverContent(page).addImage(img, w, 0, 0, h, x, y);
final Rectangle linkLocation = new Rectangle(x, y, x + w, y + h);
final PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), linkLocation, PdfAnnotation.HIGHLIGHT_OUTLINE, new PdfAction(hyperlink));
link.setBorder(new PdfBorderArray(0, 0, 0));
// Add link on last page
stamper.addAnnotation(link, page);
stamper.close();
reader.close();
}
}