Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Development and suggestions about third part tool integration.
Cordova, Xamarin, Basic4Android topics are listed here.
  • Page:
  • 1

TOPIC:

Add a line in a PDF 6 years 2 months ago #13411

  • mbious
  • mbious's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Hello,
I use the demo version of Radaee to perform tests. For that I try to add a line annotation (btn_add_line) but it does not appear. Can you help me please ?

What is the Matrix class?

package com.radaee.test;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JToolBar;

import com.radaee.pdf.Document;
import com.radaee.pdf.Matrix;
import com.radaee.pdf.Page;

public class TestRender extends JFrame implements ActionListener {

private Document m_doc;
private int m_pgno;
private JLabel m_iview;
private JButton btn_prev;
private JButton btn_next;
private JButton btn_add_line;
private JButton btn_add_arrow;
private JButton btn_add_circle;
JToolBar m_tbar;

private void renderPage(int pgno) {
m_pgno = pgno;
float pw = m_doc.GetPageWidth(pgno);
float ph = m_doc.GetPageHeight(pgno);
float scale1 = 600.0f / pw;
float scale2 = 800.0f / ph;
if (scale1 > scale2)
scale1 = scale2;
if (pw <= 0 || ph <= 0)
return;
int iw = (int) (pw * scale1);
int ih = (int) (ph * scale1);

Page page = m_doc.GetPage(pgno);
Matrix mat = new Matrix(scale1, -scale1, 0, ih);
BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB);
page.RenderToBuf(bimg, -1, mat);
mat.Destroy();
page.Close();
m_iview.setIcon(new ImageIcon(bimg));
}

private void renderPageAnnotedLine(int pgno) {
m_pgno = pgno;
float pw = m_doc.GetPageWidth(pgno);
float ph = m_doc.GetPageHeight(pgno);
float scale1 = 600.0f / pw;
float scale2 = 800.0f / ph;
if (scale1 > scale2)
scale1 = scale2;
if (pw <= 0 || ph <= 0)
return;
int iw = (int) (pw * scale1);
int ih = (int) (ph * scale1);

Page page = m_doc.GetPage(pgno);
Matrix mat = new Matrix(scale1, -scale1, 0, ih);

float [] pt1 = {new Float(10), new Float(10)};

float [] pt2 = {new Float(15), new Float(10)};

Matrix mat_line = new Matrix(10, 15, 20, 10);
page.AddAnnotLine(mat_line, pt1, pt2, 1, 9, 5, Color.blue.getAlpha(), Color.blue.getAlpha());

BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB);
page.RenderToBuf(bimg, -1, mat);
mat.Destroy();
page.Close();
m_iview.setIcon(new ImageIcon(bimg));
}

public TestRender(Document doc) {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
if (m_doc != null) {
m_doc.Close();
m_doc = null;
}
}
});
m_doc = doc;
m_tbar = new JToolBar();
btn_prev = new JButton("Previous Page");
btn_next = new JButton("Next Page");
btn_add_line = new JButton("Add line");
btn_add_arrow = new JButton("Add arrow");
btn_add_circle = new JButton("Add circle");
m_iview = new JLabel();
m_tbar.add(btn_prev);
m_tbar.add(btn_next);
m_tbar.add(btn_add_line);
m_tbar.add(btn_add_arrow);
m_tbar.add(btn_add_circle);
add("North", m_tbar);
add(m_iview);
btn_prev.addActionListener(this);
btn_next.addActionListener(this);
setTitle("Test PDF Render");
setSize(600, 880);
setVisible(true);
renderPage(0);
}

@Override
public void actionPerformed(ActionEvent e) {
int pgno = m_pgno;
if (e.getSource() == btn_prev) {
if (pgno == 0)
return;
pgno--;
renderPage(pgno);
} else if (e.getSource() == btn_next) {
if (pgno == m_doc.GetPageCount() - 1)
return;
pgno++;
renderPage(pgno);
} else if(e.getSource() == btn_add_line) {
renderPageAnnotedLine(pgno);
} else if(e.getSource() == btn_add_arrow) {
// TODO add an arrow
}else if(e.getSource() == btn_add_circle) {
// TODO add a circle
}
}

}

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum