`

a4纸标签自定义打印排版

    博客分类:
  • RUBY
 
阅读更多
class PrintBase
  # 默认现在只有a4纸大小
  PaperType = {1=>[210,297]}
  # 标签尺寸
  TagType = {0=>[100,40],1=>[60,40],2=>[150,60]}

  attr_accessor :id,:tag_type_x,:tag_type_y,:print_size,:print_x_size,:print_y_size,:print_page

  def initialize(tag_type=0, obj_size=nil , paper_type=1)
    @paper_type_x = PaperType[paper_type][0]
    @paper_type_y = PaperType[paper_type][1]
    @tag_type_x = TagType[tag_type][0]
    @tag_type_y = TagType[tag_type][1]
    @id = tag_type
    
    # 纸张可用面积
    @paper_type_area = @paper_type_x * @paper_type_y 
    # 标签面积
    @tag_type_area = @tag_type_x * @tag_type_y
    # 每行打印张数
    @print_x_size = @paper_type_x / @tag_type_x
    # 每列打印张数
    @print_y_size = @paper_type_y / @tag_type_y

    # 每页纸打印标签张数
    @print_size = @paper_type_area / @tag_type_area
    @print_size = @print_x_size * @print_y_size < @print_size ? @print_x_size * 
    @print_y_size : @print_size
    # 需打印纸张数
    @print_page = obj_size ? ( obj_size / @print_size + (obj_size % @print_size == 0 ? 0 : 1) ) : 1
  end

end    


class Admin::Print::WhmallTagsController <  Admin::BaseController
    layout:false
	def print
      @tag = PrintBase.new(params[:tag_id].to_i)
      @chemical = ::Chemical.find(params[:chemical_id]|| 25)
	end
end



<style type="text/css" media="print">
.noprint{display : none }
.pageBreak{ page-break-after:always;}
</style>

[align=center]

   <div style="width:100%">
     <div>
       <% (1..@tag.print_size).each do |i|%>
          <%if i == 1 %>
            <!--首行行头!-->
            <div> 
            <div id="print_<%= i %>" style="width:<%= 98/@tag.print_x_size %>%;height:<%= 100/@tag.print_y_size %>%;margin-right: 10px;float: left;"> 
               <div style="width:100%;height:100%;" id="show_note<%= i %>" ><button class="show_note" id="show_button<%= i %>"><%= image_tag "4-10cm.jpg", style: 'width: 100%;height: 100%; ' %></button>[/align]
               <div style="width:100%;height:100%;display: none;" class="noprint" id="hidde_note<%= i %>"><button class="hidde_note" id="hidde_button<%= i %>"><%= image_tag "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494828228049&di=7219b7547575eadb65d32b7ba61af822&imgtype=0&src=http%3A%2F%2Fico.ooopic.com%2Ficonset02%2F6%2Fgif%2F53757.gif", style: 'width: 100%;height: 100%; ' %></button></div>
            </div> 
          <% elsif i  == @tag.print_size %>
            <!--末行行尾!-->
            <div id="print_<%= i %>" style="width:<%= 98/@tag.print_x_size %>%;height:<%= 100/@tag.print_y_size %>%;float: left;">
              <%= render :partial => "print" , :locals => { :i => i }%> 
              <div style="width:100%;height:100%;" class="noprint" id="hidde_note<%= i %>"><button class="hidde_note" id="hidde_button<%= i %>"><%= image_tag "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494828228049&di=7219b7547575eadb65d32b7ba61af822&imgtype=0&src=http%3A%2F%2Fico.ooopic.com%2Ficonset02%2F6%2Fgif%2F53757.gif", style: 'width: 100%;height: 100%; ' %></button></div>
            </div>   
          <% elsif i % @tag.print_x_size == 0 %>
            <!--每行行尾!-->
            <div id="print_<%= i %>" style="width:<%= 98/@tag.print_x_size %>%;height:<%= 100/@tag.print_y_size %>%;float: left;">
             <div style="width:100%;height:100%;display: none;" id="show_note<%= i %>" ><button class="show_note" id="show_button<%= i %>"><%= image_tag "4-10cm.jpg", style: 'width: 100%;height: 100%; ' %></button></div>
               <div style="width:100%;height:100%;" class="noprint" id="hidde_note<%= i %>"><button class="hidde_note" id="hidde_button<%= i %>"><%= image_tag "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494828228049&di=7219b7547575eadb65d32b7ba61af822&imgtype=0&src=http%3A%2F%2Fico.ooopic.com%2Ficonset02%2F6%2Fgif%2F53757.gif", style: 'width: 100%;height: 100%; ' %></button></div>
            </div> 
            </div> 
            </br> <div> 
          <% else %>
            <div id="print_<%= i %>" style="width:<%= 98/@tag.print_x_size %>%;height:<%= 100/@tag.print_y_size %>%;margin-right: 10px;float: left;">
              <div style="width:100%;height:100%;display: none;" id="show_note<%= i %>" ><button class="show_note" id="show_button<%= i %>"><%= image_tag "4-10cm.jpg", style: 'width: 100%;height: 100%; ' %></button></div>
               <div style="width:100%;height:100%;" class="noprint" id="hidde_note<%= i %>"><button class="hidde_note" id="hidde_button<%= i %>"><%= image_tag "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494828228049&di=7219b7547575eadb65d32b7ba61af822&imgtype=0&src=http%3A%2F%2Fico.ooopic.com%2Ficonset02%2F6%2Fgif%2F53757.gif", style: 'width: 100%;height: 100%; ' %></button></div>
            </div>         
          <% end %>
       <% end %>
     </div>
   </div>

   <div class="pageBreak"></digv>

</div>


<script type="text/javascript">
  $(".show_note").on('click',function(){
    var id = this.id.replace ( /[^\d.]/g, '' )
    $('#show_note'+ id).hide();
    $('#hidde_note'+ id).show();
  });
  $(".hidde_note").on('click',function(){
    var id = this.id.replace ( /[^\d.]/g, '' )
    $('#hidde_note'+ id).hide();
    $('#show_note'+ id).show();
  });

  // 打印触发
  $("#btnPrint").on('click',function(){
    $(".noprint").css("display", "")
    window.print();
  })

  // 切换标签
  $("#tag_id").on('change',function(){
    var tag_id = $("#tag_id").val();
    window.location.href = '/admin/print/whmall_tags/print?tag_id='+tag_id+"&chemical_id="+"<%= @chemical.id %>" ;
  })

  // 快速选择
  $("#select_tag").on('change',function(){
    var select_tag = $("#select_tag").val();
    if(select_tag==0){
     <% (1..@tag.print_size).each do |i|%>
       var id = "<%= i %>"
       $('#hidde_note'+ id).hide();
       $('#show_note'+ id).show();
     <% end %>
    }else if(select_tag==1){
     <% (1..@tag.print_size).each do |i|%>
       var id = "<%= i %>"
       $('#show_note'+ id).hide();
       $('#hidde_note'+ id).show();
     <% end %>
    }else if(select_tag==2){
     <% (1..(@tag.print_size/2)).each do |i|%>
       var id = "<%= i %>"
       $('#hidde_note'+ id).hide();
       $('#show_note'+ id).show();
     <% end %> 
    }
  })
</script>
  • 大小: 226.3 KB
  • 大小: 209.1 KB
  • 大小: 154.4 KB
0
1
分享到:
评论

相关推荐

    易语言自定义打印

    自定义打印则允许用户通过编程控制打印过程,包括选择纸张大小、设置页边距、调整打印方向、控制打印内容的排版等。这对于生成报告、报表或者设计复杂的打印输出尤为重要。 在易语言中实现自定义打印,通常需要以下...

    LBS条码标签设计软件 v2.2.zip

    LBS条码标签设计软件让您告别高价条码标签打印机,使用普通的A4喷墨/激光打印机和A4不干胶贴纸,便可打印条码价格标签,完全媲美专业高档标签打印机打出的效果,使用更加方便。将打出的不干胶贴标签贴在服装吊牌上,...

    VB关于打印文字的演示,可设置大小,粗体等.rar

    至于【标签】"VB源码-报表打印",这意味着这个程序可能不仅限于简单的文字打印,还可能涉及到了报表生成。在VB6中,报表通常通过报表控件(如Microsoft Report Viewer)或自定义设计的界面来实现,允许用户根据数据...

    房租收据打印专家V2.6.1.zip

    《房租收据打印专家》能够自动生成符合标准格式的房租收据,用户只需要输入必要的信息,如租户姓名、租赁单元、租金金额、付款日期等,软件便会自动排版并打印出清晰、专业的收据。此外,该软件支持自定义收据模板,...

    word高级排版技巧

    - 支持标准纸张尺寸,如A4、A5,也允许自定义非标准尺寸。 **调整页边距:** - 页边距指文本与纸张边缘的距离,通过“文件”菜单下的“页面设置”进行调整,确保文本排列美观且易于阅读。 **不同页设置不同方向:*...

    教你用Word制作自己的标签(有详图).pdf

    8. 打印设置:设置打印机,选择正确的纸张类型(如标签纸),并进行打印。 9. 调整与修正:如果打印结果不符合预期,可根据需要进行页面设置或内容调整,并重新打印。 以上知识点涵盖了使用Microsoft Word制作标签...

    2010日历(农历节气节日都显示) Excel格式

    5. **打印和自定义**:日历的A4排版适应了打印需求,用户可以根据个人喜好调整颜色、字体、页边距等设置,以达到最佳的打印效果。 综合以上信息,我们可以得出这个压缩包文件提供了一个全面的日历系统,融合了东西...

    A4信头样机

    在IT行业中,样机设计是...综上所述,"A4信头样机"及其相关的标签和文件,为我们提供了一个深入了解和应用平面设计样机的机会。通过这样的工具,设计师可以更加自信地呈现其创意,确保设计作品在视觉传达上的完美呈现。

    vue使用html2canvas生成图片.rar

    // 这里可以创建一个a标签下载图片或者做其他操作 }); }); } } ``` 4. **选择要转换的元素**:在`html2canvas`中,你需要指定要转换的DOM元素。在上面的代码中,`#yourElementId`是你要转换的元素的ID。确保...

    毕业论文系列2021-毕业论文排版5.doc

    一般来说,文字方向从左到右,页边距普通,纸张方向横向,纸张大小 A4。在「视图」中,将「导航窗格」选上,方便不同的章节跳转导航。 封面与页眉页脚 首先,需要设置封面。可以插入表格,插入文档部件——文档...

    office办公软件word最实用的操作步骤

    在“页面设置”对话框的“纸张”标签下,用户可以根据实际需求选择不同的纸张类型,如A4、Letter等,或者自定义纸张的宽度和高度。这一步骤对于确保文档打印时的适配性至关重要。 ##### 1.3 页面垂直对齐方式 页面...

    Quite Imposing Plus 3.0f中文版

    同时,调整页面大小的功能则允许你在不改变内容的情况下,将PDF适应不同的纸张尺寸,无论是A4、A3还是自定义尺寸,都能应对自如。 在 Quite Imposing Plus 中,用户还可以进行更细致的页面设置。比如,你可以设定...

    (完整版)latex初学者模板.pdf

    1. **页面设置**:在LaTeX中,我们可以定义文档的纸张大小,如`a4paper`表示A4尺寸。`11pt`定义了字体大小,`twoside`设置双面打印,`openany`允许新章节在任何一页开始。此外,还有对页边空白的调整,例如`\...

    overleaf笔记(1)

    在LaTeX文档中,可以使用\includegraphics{}指令插入图像,并通过可选参数为图像添加标题(\caption{})、标签(\label{})以及通过\ref{}指令对图像进行引用。 9. 列表的创建: LaTeX支持创建无序列表、有序列表、...

    尺寸概括

    在给定的标签"TeX"中,我们可以将其关联到文本排版系统,特别是对于处理复杂的数学公式和科学文献时,尺寸概括可能涉及到如何在不同大小的输出设备上保持内容的清晰度和可读性。 TeX是由Donald Knuth开发的一种排版...

    一组超级高端的设计师极简主义简历_docx&indd模版下载.zip

    InDesign提供了强大的版面设计功能,包括精确的尺寸控制、专业的排版工具、自定义图形和颜色管理,以及与Adobe其他创意软件(如Photoshop和Illustrator)的无缝集成,使得设计者可以创建出极具视觉冲击力和个性化的...

    艺术复古的旅游指南杂志画册模板_INDD素材下载.zip

    另外两个文件,“US Letter Size Template”和“A4 Size Template”,分别对应的是美国标准信纸尺寸(8.5 x 11英寸)和国际标准A4尺寸(210 x 297毫米)。这两种尺寸的选择,确保了无论用户在哪个国家,都能找到合适...

Global site tag (gtag.js) - Google Analytics