내 클라이언트 측 웹 사이트의 표의 이진 열에 HTML 문서를 업로드하는 업 로더 (내부 용)가 있습니다. 클라이언트 대면 사이트에는 사용자가 페이지를 보통 웹 사이트 (send_data h_t.html_code, :type => "html", :disposition => "inline"
사용)로 볼 수있는 색인이 있습니다. 또한 사용자에게 페이지의 PDF를 다운로드 할 수있는 권한을 부여하려고합니다. 이를 위해 wicked_pdf를 사용하고 있습니다.Wicked PDF, 데이터베이스 테이블 이미지 및 스타일 문제에서 PDF 생성
전체적인 문제는 데이터가 데이터베이스에 저장된다는 사실에서 비롯된 것처럼 보입니다. 이상하게 들리지만 사업 운영에서는 필자가 정확히 포맷팅하는 것이 중요합니다. 문제는 이미지를 볼 수 없으며 스타일 시트/스타일 태그가 효과가 없다는 것입니다.
나는 템플레이트
#Controller (above, modified)
html = HtmlTranscript.find(params[:id])
@html_code = html.html_code.gsub('<img src="/images/bwTranscriptLogo.gif" alt="Logo">','<%= wicked_pdf_image_tag "bwTranscriptLogo.gif" %>')
@html_code = @html_code.gsub('<link rel="StyleSheet" href="" type="text/css">','<%= wicked_pdf_stylesheet_link_tag "transcripts.css" %>')
transcript = WickedPdf.new.pdf_from_string(render_to_string(:template => "html_transcripts/show.html.erb", :layout => false))
#view
<!-- tried with stylesheet & image link tags, with wicked_pdf stylesheet & image link tags, with html style & img tags, etc -->
<%= raw(@html_code) %>
를 사용
Gsub-
def show
html = HtmlTranscript.find(params[:id])
html_code = html.html_code.gsub('<img src="/images/bwTranscriptLogo.gif" alt="Logo">','<%= wicked_pdf_image_tag "bwTranscriptLogo.gif" %>')
html_code = html_code.gsub('<link rel="StyleSheet" href="" type="text/css">','<%= wicked_pdf_stylesheet_link_tag "transcripts.css" %>')
transcript = WickedPdf.new.pdf_from_string(html_code)
respond_to do |format|
format.html do
send_data transcript, :type => "pdf", :disposition => "attachment"
end
##### i never could get this part figured out, so if you have a fix for this...
# format.pdf do
# render :pdf => "transcript_for_#{@html.created_at}", :template => "html_transcripts/show.html.erb", :layout => false
# end
end
end
를 점프는 - 시도했습니다 그리고 모두가 transcript-를 생성하지만, 어느 스타일이나 이미지가됩니다 무엇. initializer-
module WickedPdfHelper
def wicked_pdf_stylesheet_link_tag(*sources)
sources.collect { |source|
"<style type='text/css'>#{Rails.application.assets.find_asset("#{source}.css")}</style>"
}.join("\n").gsub(/url\(['"](.+)['"]\)(.+)/,%[url("#{wicked_pdf_image_location("\\1")}")\\2]).html_safe
end
def wicked_pdf_image_tag(img, options={})
image_tag wicked_pdf_image_location(img), options
end
def wicked_pdf_image_location(img)
"file://#{Rails.root.join('app', 'assets', 'images', img)}"
end
def wicked_pdf_javascript_src_tag(source)
"<script type='text/javascript'>#{Rails.application.assets.find_asset("#{source}.js").body}</script>"
end
def wicked_pdf_javascript_include_tag(*sources)
sources.collect{ |source| wicked_pdf_javascript_src_tag(source) }.join("\n").html_safe
end
end
만들기
는절대적으로 아무것도하지 않았다, 나는 다음 시도 무엇인지 전혀 모른다. 다음과 같이 보조 노트로
는, 성적 증명서의 HTML 버전을 볼 수있는 코드는 다음과 같습니다 html로 데이터가 데이터베이스에 저장되어있는 것처럼, 아니보기를 필요로하지
def transcript_data
h_t = HtmlTranscript.find(params[:id])
send_data h_t.html_code, :type => "html", :disposition => "inline"
end
,하지만 이미지를 얻을, 스타일 등 모든 것이 HTML 버전으로 작동합니다. PDF가 아닙니다.
나는 레일 3.0.20이있는 루비 1.8.7을 사용하고 있습니다.