diff options
| author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-02-11 08:19:04 +0100 | 
|---|---|---|
| committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-02-11 08:19:04 +0100 | 
| commit | 6d416edf737b9899aef7194aa66c35103dba07ce (patch) | |
| tree | 25507345cd1e66a005c36e4021fba1bb57d56311 | |
| parent | 5ea41481c10aa43ab1df5e0b7ba0c18c3262c9eb (diff) | |
| download | pdf-as-4-6d416edf737b9899aef7194aa66c35103dba07ce.tar.gz pdf-as-4-6d416edf737b9899aef7194aa66c35103dba07ce.tar.bz2 pdf-as-4-6d416edf737b9899aef7194aa66c35103dba07ce.zip | |
Support rotation of the signature block by r attribute in pos string
5 files changed, 70 insertions, 10 deletions
| diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index 076d3ff3..d2944ba1 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -134,7 +134,7 @@ public class Main {  				CLI_ARG_POSITION_SHORT,  				CLI_ARG_POSITION,  				true, -				"Position string: position has the format [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo]"); +				"Position string: position has the format [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo];[r:r_algo]");  		cliOptions.addOption(positionOption);  		Option confOption = new Option(CLI_ARG_CONF_SHORT, CLI_ARG_CONF, true, diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java index da7da772..e0be68ee 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java @@ -156,7 +156,7 @@ public class Positioning {                  {                      page++;                  } -                return new PositioningInstruction(make_new_page, page, pos_x, pos_y); +                return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation);              }              // pos_y is auto              if (make_new_page) @@ -164,7 +164,7 @@ public class Positioning {                  // ignore footer in new page                  page++;                  pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; -                return new PositioningInstruction(make_new_page, page, pos_x, pos_y); +                return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation);              }              // up to here no checks have to be made if Tablesize and Pagesize are fit              // Now we have to getfreespace in page and reguard footerline @@ -188,7 +188,7 @@ public class Positioning {                      // no text --> SIGNATURE_BORDER                      pos_y = page_height - SIGNATURE_MARGIN_VERTICAL;                  } -                return new PositioningInstruction(make_new_page, page, pos_x, pos_y); +                return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation);              }              final float page_length = pre_page_length;              // we do have text take SIGNATURE_MARGIN @@ -206,7 +206,7 @@ public class Positioning {                  // no text --> SIGNATURE_BORDER                  pos_y = page_height - SIGNATURE_MARGIN_VERTICAL;              } -            return new PositioningInstruction(make_new_page, page, pos_x, pos_y); +            return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation);          } finally {              if (pdfDataSource != null) {                  try { diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java index 0fe399c4..d0c1afc1 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java @@ -66,6 +66,11 @@ public class PositioningInstruction     * be placed.
     */
    protected float y = 0.0f;
 +  
 +  /**
 +   * The rotation of the signature block
 +   */
 +  protected float rotation = 0.0f;
    /**
     * 
 @@ -84,12 +89,13 @@ public class PositioningInstruction     *          The y coordinate where the upper left corner of the signature
     *          block should be placed.
     */
 -  public PositioningInstruction(boolean make_new_page, int page, float x, float y)
 +  public PositioningInstruction(boolean make_new_page, int page, float x, float y, float rotation)
    {
      this.make_new_page = make_new_page;
      this.page = page;
      this.x = x;
      this.y = y;
 +    this.rotation = rotation;
    }
    /**
 @@ -135,6 +141,11 @@ public class PositioningInstruction    {
      return this.y;
    }
 +  
 +  public float getRotation()
 +  {
 +    return this.rotation;
 +  }
  	public int hashCode() {
  		final int prime = 31;
 @@ -143,6 +154,7 @@ public class PositioningInstruction  		result = prime * result + page;
  		result = prime * result + Float.floatToIntBits(x);
  		result = prime * result + Float.floatToIntBits(y);
 +		result = prime * result + Float.floatToIntBits(rotation);
  		return result;
  	}
 @@ -162,6 +174,8 @@ public class PositioningInstruction  			return false;
  		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
  			return false;
 +		if (Float.floatToIntBits(rotation) != Float.floatToIntBits(other.rotation))
 +			return false;
  		return true;
  	}
 @@ -175,6 +189,8 @@ public class PositioningInstruction  		buffer.append(x);
  		buffer.append(", y=");
  		buffer.append(y);
 +		buffer.append(", r=");
 +		buffer.append(rotation);
  		buffer.append("]");
  		return buffer.toString();
  	}
 diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java index 92afaf98..7bf2103b 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java @@ -68,6 +68,11 @@ public class TablePos implements Serializable     * The top y position of the footer line.
     */
    public float footer_line = 0.0f;
 +  
 +  /**
 +   * The rotation of the signature block
 +   */
 +  public float rotation = 0.0f;
    /**
     * The y position.
 @@ -134,7 +139,7 @@ public class TablePos implements Serializable     * Constructor.
     * 
     * @param pos_string The pos instruction.
 -   *        format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo]
 +   *        format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo];[r:r_algo]
     *        x_algo:='auto'     ... automatic positioning x
     *                floatvalue ... absolute x
     *        y_algo:='auto'     ... automatic positioning y
 @@ -145,6 +150,7 @@ public class TablePos implements Serializable     *                'new'      ... new page  
     *                intvalue   ... pagenumber
     *        f_algo  floatvalue ... consider footerline (only if y_algo is auto and p_algo is not 'new')
 +   *        r_algo  floatvalue ... rotate the table arround the lower left corner anti clockwise in degree
     * @throws PdfAsException
     */
    public TablePos(String pos_string) throws PdfAsException
 @@ -241,6 +247,15 @@ public class TablePos implements Serializable  	     				this.footer_line = flval;
  	     				break;
  	     			  }
 +	     	case 'r': {
 + 		        		float flval=Float.parseFloat(commandval);
 + 		        		if (flval<0)
 + 		        		{
 + 		        			throw new PdfAsException("Pos string (=" + pos_string + ") is invalid.");
 + 		        		} 	     		        
 + 		        		this.rotation = flval;
 + 		        		break;
 + 			  }
  	     	default : {
  		                throw new PdfAsException("Pos string (=" + pos_string + ") is invalid.");
  	                  }
 @@ -255,7 +270,7 @@ public class TablePos implements Serializable    }
    public String toString()
    {  
 -	 String thatsme = "cmd:"+this.myposstring+" pos_x:"+this.pos_x+" pos_y:"+this.pos_y+" page:"+this.page+" width:"+this.width+" footer:"+this.footer_line+"\n "+" autoX:"+this.autoX+" autoY:"+this.autoY+" autoW:"+this.autoW+" Newpage:"+this.newpage+" autoP:"+this.autoP; 
 +	 String thatsme = "cmd:"+this.myposstring+" pos_x:"+this.pos_x+" pos_y:"+this.pos_y+" page:"+this.page+" width:"+this.width+" footer:"+this.footer_line+" rotation:"+this.rotation+"\n "+" autoX:"+this.autoX+" autoY:"+this.autoY+" autoW:"+this.autoW+" Newpage:"+this.newpage+" autoP:"+this.autoP; 
  	 return thatsme;
    }
  }
 diff --git a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java index 1b026300..afcac94c 100644 --- a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java +++ b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java @@ -35,6 +35,7 @@ import com.lowagie.text.pdf.PdfPCell;  import com.lowagie.text.pdf.PdfPTable;  import com.lowagie.text.pdf.PdfReader;  import com.lowagie.text.pdf.PdfStamper; +import com.lowagie.text.pdf.PdfTemplate;  public class ITextStamper implements IPDFStamper { @@ -501,11 +502,39 @@ public class ITextStamper implements IPDFStamper {              PdfPTable table = object.getTable(); +             +            logger.info("Positioning: X " + positioningInstruction.getX() + " Y " + positioningInstruction.getY()); +            logger.info("Positioning: P " + positioningInstruction.getPage());              logger.info("Visual Object: " + visualObject.getWidth() + " x " + visualObject.getHeight()); -            //PdfTemplate table_template = content.createTemplate(visualObject.getWidth(), visualObject.getHeight()); -            table.writeSelectedRows(0, -1, positioningInstruction.getX(), +            PdfTemplate table_template = content.createTemplate(table.getTotalWidth(), table.getTotalHeight()); +             +           /* table.writeSelectedRows(0, -1, positioningInstruction.getX(),                      positioningInstruction.getY(), content); +            */ +            table.writeSelectedRows(0, -1, 0, +            		table.getTotalHeight(), table_template); +            //table_template. +             +            float rotate = positioningInstruction.getRotation(); +             +            if(rotate != 0) { +            	//set up the affine transform  +                float angle   = (float)(-rotate * (Math.PI / 180));  +                float fxScale = (float)(Math.cos(angle));  +                float fyScale = (float)(Math.cos(angle));  +                float fxRote  = (float)(-Math.sin(angle));  +                float fyRote  = (float)(Math.sin(angle));  +                 +                content.addTemplate(table_template, fxScale, fxRote, fyRote, fyScale,  +                		positioningInstruction.getX(), +                        positioningInstruction.getY() - table.getTotalHeight()); +            } else { +            	content.addTemplate(table_template, positioningInstruction.getX(), +                        positioningInstruction.getY() - table.getTotalHeight()); +            } +             +                          stamper.close(); | 
