puppeteer_pdf 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 82beba0d28c5441e6b25dda0cdf77d2ee7819968685b9f67fce19e4432e4a8be
4
+ data.tar.gz: 1b5b21f360ad5751bedcbb6d20ff27358e35cf08e55ff4cc0f1ef1eaf643266f
5
+ SHA512:
6
+ metadata.gz: e266f9ed00c832e6717d1769a548dd2341a31abbe431f6d2d333333498e7a77508ebb23bbca3cc326046665eb387ae122d372ef3a8796391c0e9a91a06b2294c
7
+ data.tar.gz: a9673cf07a8e0cb9833b83e345c245c676aad1eea40bffd337eea5a9988bcc4db3fcf383a43be9fea9142a71837344ecf0a36af9eb4d720c8ca3284914a02b8b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build puppeteer_pdf-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install puppeteer_pdf-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install puppeteer_pdf-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push puppeteer_pdf-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" addBOMForNewFiles="with NO BOM" />
4
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.5.3" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/puppeteer_pdf.iml" filepath="$PROJECT_DIR$/.idea/puppeteer_pdf.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.1, rbenv: 2.5.3) [gem]" level="application" />
11
+ </component>
12
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,210 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="dba716aa-5da0-418b-bf83-12361d0e012a" name="Default Changelist" comment="">
5
+ <change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
6
+ <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
7
+ <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
8
+ <change beforePath="$PROJECT_DIR$/puppeteer_pdf.gemspec" beforeDir="false" afterPath="$PROJECT_DIR$/puppeteer_pdf.gemspec" afterDir="false" />
9
+ </list>
10
+ <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
11
+ <option name="SHOW_DIALOG" value="false" />
12
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
13
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
14
+ <option name="LAST_RESOLUTION" value="IGNORE" />
15
+ </component>
16
+ <component name="FileEditorManager">
17
+ <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
18
+ <file pinned="false" current-in-tab="true">
19
+ <entry file="file://$PROJECT_DIR$/README.md">
20
+ <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
21
+ <state split_layout="SPLIT">
22
+ <first_editor relative-caret-position="414">
23
+ <caret line="37" lean-forward="true" selection-start-line="37" selection-end-line="37" />
24
+ </first_editor>
25
+ <second_editor />
26
+ </state>
27
+ </provider>
28
+ </entry>
29
+ </file>
30
+ <file pinned="false" current-in-tab="false">
31
+ <entry file="file://$PROJECT_DIR$/.gitignore">
32
+ <provider selected="true" editor-type-id="text-editor">
33
+ <state relative-caret-position="120">
34
+ <caret line="8" column="5" selection-start-line="8" selection-start-column="5" selection-end-line="8" selection-end-column="5" />
35
+ </state>
36
+ </provider>
37
+ </entry>
38
+ </file>
39
+ <file pinned="false" current-in-tab="false">
40
+ <entry file="file://$PROJECT_DIR$/lib/puppeteer_pdf.rb">
41
+ <provider selected="true" editor-type-id="text-editor">
42
+ <state relative-caret-position="165">
43
+ <caret line="11" selection-start-line="10" selection-end-line="11" />
44
+ </state>
45
+ </provider>
46
+ </entry>
47
+ </file>
48
+ <file pinned="false" current-in-tab="false">
49
+ <entry file="file://$PROJECT_DIR$/puppeteer_pdf.gemspec">
50
+ <provider selected="true" editor-type-id="text-editor">
51
+ <state relative-caret-position="225">
52
+ <caret line="15" selection-start-line="15" selection-end-line="15" />
53
+ </state>
54
+ </provider>
55
+ </entry>
56
+ </file>
57
+ </leaf>
58
+ </component>
59
+ <component name="Git.Settings">
60
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
61
+ </component>
62
+ <component name="IdeDocumentHistory">
63
+ <option name="CHANGED_PATHS">
64
+ <list>
65
+ <option value="$PROJECT_DIR$/lib/puppeteer_pdf.rb" />
66
+ <option value="$PROJECT_DIR$/puppeteer_pdf.gemspec" />
67
+ <option value="$PROJECT_DIR$/.gitignore" />
68
+ <option value="$PROJECT_DIR$/README.md" />
69
+ </list>
70
+ </option>
71
+ </component>
72
+ <component name="ProjectFrameBounds">
73
+ <option name="y" value="23" />
74
+ <option name="width" value="1280" />
75
+ <option name="height" value="721" />
76
+ </component>
77
+ <component name="ProjectView">
78
+ <navigator proportions="" version="1">
79
+ <foldersAlwaysOnTop value="true" />
80
+ </navigator>
81
+ <panes>
82
+ <pane id="ProjectPane">
83
+ <subPane>
84
+ <expand>
85
+ <path>
86
+ <item name="puppeteer_pdf" type="b2602c69:ProjectViewProjectNode" />
87
+ <item name="puppeteer_pdf" type="462c0819:PsiDirectoryNode" />
88
+ </path>
89
+ <path>
90
+ <item name="puppeteer_pdf" type="b2602c69:ProjectViewProjectNode" />
91
+ <item name="puppeteer_pdf" type="462c0819:PsiDirectoryNode" />
92
+ <item name="lib" type="462c0819:PsiDirectoryNode" />
93
+ </path>
94
+ </expand>
95
+ <select />
96
+ </subPane>
97
+ </pane>
98
+ <pane id="Scope" />
99
+ </panes>
100
+ </component>
101
+ <component name="PropertiesComponent">
102
+ <property name="WebServerToolWindowFactoryState" value="false" />
103
+ <property name="last_opened_file_path" value="$PROJECT_DIR$" />
104
+ <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
105
+ <property name="nodejs_npm_path_reset_for_default_project" value="true" />
106
+ </component>
107
+ <component name="RunDashboard">
108
+ <option name="ruleStates">
109
+ <list>
110
+ <RuleState>
111
+ <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
112
+ </RuleState>
113
+ <RuleState>
114
+ <option name="name" value="StatusDashboardGroupingRule" />
115
+ </RuleState>
116
+ </list>
117
+ </option>
118
+ </component>
119
+ <component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" />
120
+ <component name="SvnConfiguration">
121
+ <configuration />
122
+ </component>
123
+ <component name="TaskManager">
124
+ <task active="true" id="Default" summary="Default task">
125
+ <changelist id="dba716aa-5da0-418b-bf83-12361d0e012a" name="Default Changelist" comment="" />
126
+ <created>1559202765845</created>
127
+ <option name="number" value="Default" />
128
+ <option name="presentableId" value="Default" />
129
+ <updated>1559202765845</updated>
130
+ <workItem from="1559202767218" duration="4297000" />
131
+ <workItem from="1559209819753" duration="276000" />
132
+ </task>
133
+ <servers />
134
+ </component>
135
+ <component name="TimeTrackingManager">
136
+ <option name="totallyTimeSpent" value="4573000" />
137
+ </component>
138
+ <component name="ToolWindowManager">
139
+ <frame x="0" y="23" width="1280" height="721" extended-state="0" />
140
+ <editor active="true" />
141
+ <layout>
142
+ <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.16962843" />
143
+ <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
144
+ <window_info id="Favorites" order="2" side_tool="true" />
145
+ <window_info anchor="bottom" id="Message" order="0" />
146
+ <window_info anchor="bottom" id="Find" order="1" />
147
+ <window_info anchor="bottom" id="Run" order="2" />
148
+ <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
149
+ <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
150
+ <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
151
+ <window_info anchor="bottom" id="TODO" order="6" />
152
+ <window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
153
+ <window_info anchor="bottom" id="Database Changes" order="8" />
154
+ <window_info anchor="bottom" id="Version Control" order="9" />
155
+ <window_info anchor="bottom" id="Terminal" order="10" />
156
+ <window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
157
+ <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
158
+ <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
159
+ <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
160
+ <window_info anchor="right" id="Database" order="3" />
161
+ </layout>
162
+ </component>
163
+ <component name="TypeScriptGeneratedFilesManager">
164
+ <option name="version" value="1" />
165
+ </component>
166
+ <component name="editorHistoryManager">
167
+ <entry file="file://$PROJECT_DIR$/CODE_OF_CONDUCT.md">
168
+ <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
169
+ <state split_layout="SPLIT">
170
+ <first_editor />
171
+ <second_editor />
172
+ </state>
173
+ </provider>
174
+ </entry>
175
+ <entry file="file://$PROJECT_DIR$/Gemfile">
176
+ <provider selected="true" editor-type-id="text-editor" />
177
+ </entry>
178
+ <entry file="file://$PROJECT_DIR$/lib/puppeteer_pdf.rb">
179
+ <provider selected="true" editor-type-id="text-editor">
180
+ <state relative-caret-position="165">
181
+ <caret line="11" selection-start-line="10" selection-end-line="11" />
182
+ </state>
183
+ </provider>
184
+ </entry>
185
+ <entry file="file://$PROJECT_DIR$/puppeteer_pdf.gemspec">
186
+ <provider selected="true" editor-type-id="text-editor">
187
+ <state relative-caret-position="225">
188
+ <caret line="15" selection-start-line="15" selection-end-line="15" />
189
+ </state>
190
+ </provider>
191
+ </entry>
192
+ <entry file="file://$PROJECT_DIR$/.gitignore">
193
+ <provider selected="true" editor-type-id="text-editor">
194
+ <state relative-caret-position="120">
195
+ <caret line="8" column="5" selection-start-line="8" selection-start-column="5" selection-end-line="8" selection-end-column="5" />
196
+ </state>
197
+ </provider>
198
+ </entry>
199
+ <entry file="file://$PROJECT_DIR$/README.md">
200
+ <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
201
+ <state split_layout="SPLIT">
202
+ <first_editor relative-caret-position="414">
203
+ <caret line="37" lean-forward="true" selection-start-line="37" selection-end-line="37" />
204
+ </first_editor>
205
+ <second_editor />
206
+ </state>
207
+ </provider>
208
+ </entry>
209
+ </component>
210
+ </project>
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at muneeb@ginzametrics.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in puppeteer_pdf.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Muneeb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # PuppeteerPdf
2
+
3
+ PuppeteerPdf is using Puppeteer library organized by Google. It's a lightest gem to generate PDF's using
4
+ URL. PuppeteerPdf is using Headless to open webpage and then simply convert it into PDF.
5
+
6
+ ## Installation
7
+
8
+ Before installing puppeteer_pdf gem, syste, must have puppeteer library installed, it can be installed by
9
+
10
+ ```
11
+ npm i puppeteer
12
+ # or "yarn add puppeteer"
13
+ ```
14
+ or visit https://developers.google.com/web/tools/puppeteer/
15
+
16
+ Once it's installed sdd this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'puppeteer_pdf'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install puppeteer_pdf
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ require 'puppeteer_pdf'
34
+ url = 'https://developers.google.com/web/tools/puppeteer'
35
+ output_path = '/system_path/test.pdf'
36
+ PuppeteerPdf.generate_pdf(url, output_path) # '/system_path/test.pdf'
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/muneeb0011/puppeteer_pdf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the PuppeteerPdf project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/puppeteer_pdf/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "puppeteer_pdf"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module PuppeteerPdf
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ require "puppeteer_pdf/version"
2
+ require 'securerandom'
3
+
4
+ module PuppeteerPdf
5
+ class Error < StandardError; end
6
+
7
+ def self.generate_pdf(url, output_file_path ,opts = {})
8
+ random_string = generate_random_string
9
+ raise "INVALID PATH, Hint : (/path/file.pdf)" unless output_file_path.include?('.pdf')
10
+ temp_path = output_file_path.reverse.split('/',2)[1].reverse
11
+ tmp_js_file_name = "#{temp_path}/puppeteer_#{random_string}.js"
12
+ js_code = "const puppeteer = require('puppeteer');
13
+ (async () => {
14
+ const browser = await puppeteer.launch();
15
+ const page = await browser.newPage();
16
+ await page.setViewport({ width: 1125, height: 600 })
17
+ await page.goto('#{url}', {waitUntil: 'networkidle2'});
18
+ await page.pdf({path: '#{output_file_path}', width: '1125px', height: '700px', layout: 'Landscape' , printBackground: true, displayHeaderFooter: true,
19
+ margin: {top: 10, bottom: 40}, headerTemplate: '<span></span>' });
20
+ await browser.close();
21
+ })();"
22
+ file = File.open(tmp_js_file_name, "w")
23
+ file.puts js_code
24
+ file.close
25
+ system("node #{tmp_js_file_name}") # GENERATE EXPORT
26
+ system("rm -rf #{tmp_js_file_name}")
27
+ puts "############################################################################################################"
28
+ puts "PDF IS GENERATED : #{output_file_path}"
29
+ puts "############################################################################################################"
30
+ output_file_path
31
+ end
32
+
33
+ def self.generate_random_string
34
+ SecureRandom.alphanumeric[0..5]
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "puppeteer_pdf/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "puppeteer_pdf"
8
+ spec.version = PuppeteerPdf::VERSION
9
+ spec.authors = ["Muneeb"]
10
+ spec.email = ["muneebahmadfarooqi@gmail.com"]
11
+
12
+ spec.summary = "A ruby gem to create PDF from URL"
13
+ spec.description = "Puppeteer uses headless to create PDF from public URL"
14
+ spec.homepage = "https://github.com/muneeb0011/puppeteer_pdf"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppeteer_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Muneeb
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Puppeteer uses headless to create PDF from public URL
42
+ email:
43
+ - muneebahmadfarooqi@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".idea/.rakeTasks"
50
+ - ".idea/encodings.xml"
51
+ - ".idea/misc.xml"
52
+ - ".idea/modules.xml"
53
+ - ".idea/puppeteer_pdf.iml"
54
+ - ".idea/vcs.xml"
55
+ - ".idea/workspace.xml"
56
+ - CODE_OF_CONDUCT.md
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/console
62
+ - bin/setup
63
+ - lib/puppeteer_pdf.rb
64
+ - lib/puppeteer_pdf/version.rb
65
+ - puppeteer_pdf.gemspec
66
+ homepage: https://github.com/muneeb0011/puppeteer_pdf
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A ruby gem to create PDF from URL
89
+ test_files: []