-
Notifications
You must be signed in to change notification settings - Fork 47
/
png-to-pdf-converter.html
276 lines (259 loc) · 12.1 KB
/
png-to-pdf-converter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
---
title: PNG Image to PDF Converter | Developer Tools
layout: post
---
<html>
<head>
<!-- Meta tags common for website -->
{% include common-meta %}
<title>{{ page.title }}</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<meta name="description"
content="This is easy to use open source tool to convert PNG Image to PDF online." />
<meta name="keywords" content="online,tool,PNG,PDF,convert,converter,web,opensource" />
<!-- CSS for the site theme -->
{% include theme-css %}
<!-- Annoying IE fixes -->
{% include ie-fixes %}
</head>
<body class="hold-transition skin-green sidebar-mini">
<!-- Site wrapper -->
<div class="wrapper">
<!-- header tag from theme -->
{% include theme-header %}
<!-- Sidebar for the whole website -->
{% include theme-sidebar %}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-6">
<div class="box box-success">
<div class="box-header with-border">
<h1 class="box-title">Convert PNG Image To PDF Format</h1>
</div>
<!-- /.box-header -->
<!-- form start -->
<div class="box-body">
<form role="form">
<div class="form-group">
<label for="myFile">Upload Image File From Your Computer</label>
<input type="file" id="myFile" name="filename" accept=".png">
</div>
<div class="form-group">
<p id="error" class="text-red"></p>
</div>
</form>
</div>
<!-- /.box-body -->
<div class="box-footer">
<div class="row">
<div class="col-xs-3">
<button type="button" class="btn btn-info" id="convert">Convert<i
class="fa fa-fw fa-arrow-right"></i></button>
</div>
</div>
</div>
<!-- /.box-footer -->
</div>
</div>
<div class="col-md-6">
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Download Your Converted PDF From Here</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="form-group">
<div id="target"></div>
</div>
</div>
<div class="box-footer" id="download-div" style="display:none">
<div class="btn-group">
<a class="btn btn-info" target="_blank" id="download" href="#"> <i class="fa fa-download"></i> Download Converted PDF File</a>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="content">
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">About PNG Image to PDF Converter Tool</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<img class="img-responsive" src="images/jpg-to-pdf.png"
alt="PNG Image to PDF format converter tool"
title="PNG Image to PDF format converter tool">
<p>This is a free online tool to convert a PNG format image file into PDF format.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">What Is PNG Encoding Format?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>PNG (Portable Network Graphics) encoding format is a raster graphics file format that uses lossless compression. It supports transparency and a wide range of colors, making it ideal for web graphics. PNG uses the Deflate compression algorithm to reduce file sizes without losing image quality. It supports various color depths, including grayscale, indexed color, and truecolor, and can store metadata like gamma correction and color profiles. PNG is widely used for its balance of quality and file size.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Why should we convert PNG to PDF?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>Converting PNG to PDF is beneficial because PDF files maintain consistent formatting across devices, support multiple images or pages in a single document, and offer advanced features like text search, annotations, and encryption. PDFs are widely used for sharing and printing due to their portability and reliability, while PNG files are better suited for individual images with transparency. Converting to PDF enhances document management and presentation.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">What is the difference between .PNG and .PDF file?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>PNG (Portable Network Graphics) is a raster image format known for lossless compression, supporting transparency and various color depths. It's ideal for individual images with high quality and no compression artifacts.</p>
<p>PDF (Portable Document Format) is a versatile file format used to present documents consistently across devices. PDFs can contain text, images, vectors, and interactive elements like links and forms. They support multiple pages, advanced features like encryption, and are optimized for sharing and printing.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Can I download converted PDF File?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>Yes, this tool is completely free to use. You can download converted PDF file using the download button that appears after conversion.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Are my photos converted on client side or server side?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>The tool converts a PNG to PDF on the client side using the jsPDF library. Here's how it works:</p>
<ol>
<li><strong>File Selection:</strong> User selects a PNG file via an HTML file input.</li>
<li><strong>File Reading:</strong> A FileReader object reads the file and converts it to a data URL.</li>
<li><strong>PDF Creation:</strong> jsPDF creates a new PDF document and adds the PNG image using the <code>addImage</code> method.</li>
<li><strong>Download:</strong> The PDF is generated and automatically downloaded.</li>
</ol>
<h2>Benefits:</h2>
<ul>
<li><strong>Privacy:</strong> No need to upload files to a server, preserving user privacy.</li>
<li><strong>Speed:</strong> Immediate conversion without server communication.</li>
<li><strong>Simplicity:</strong> Easy to implement and use directly in the browser.</li>
</ul>
<h2>Limitations:</h2>
<ul>
<li><strong>Browser Dependency:</strong> Relies on browser capabilities, may not work on all browsers.</li>
<li><strong>Performance:</strong> Large files can cause performance issues or browser crashes.</li>
<li><strong>Functionality:</strong> Limited to basic conversions without advanced PDF features like text extraction or complex formatting.</li>
</ul>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">How PNG image file is converted to PDF file?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>PNG to PDF conversion involves reading a PNG file, embedding it into a new PDF document using a library like jsPDF, specifying image dimensions and position, then saving the resulting PDF. This process retains image quality and supports multiple pages or annotations in the PDF output.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">What is PDF Format?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>PDF (Portable Document Format) is a versatile file format used for documents. It preserves layout, fonts, images, and can embed text, graphics, and interactive elements. PDFs are platform-independent, secure, and support features like annotations, forms, and digital signatures, ideal for sharing and archiving documents.</p>
</div>
<!-- /.box-body -->
</div>
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Can this tool work on a mobile browser?</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>Yes, the conversion from PNG to PDF using libraries like jsPDF can work on mobile browsers that support JavaScript and the necessary APIs (like FileReader). However, performance and memory limitations on mobile devices might affect larger file conversions. It's important to test across different mobile browsers and consider optimizing for performance where necessary.</p>
</div>
<!-- /.box-body -->
</div>
</section>
{% include addthis %}
</div>
<!-- /.content-wrapper -->
{% include theme-footer %}
</div>
<!-- ./wrapper -->
{% include theme-bottom-js %}
</body>
<script src="/plugins/selectOnFocus/jquery.selectOnFocus.min.js"></script>
<script src="/plugins/jspdf/2.4.0/jspdf.umd.min.js"></script>
<script>
async function convertToPDF() {
const { jsPDF } = window.jspdf;
// Get the uploaded file
const input = document.getElementById('myFile');
const file = input.files[0];
if (!file) {
alert('Please upload a PNG file.');
return;
}
showInProgress();
const fileName = file.name.split('.').slice(0, -1).join('.');
// Read the file as a data URL
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(event) {
const imgData = event.target.result;
// Create a new PDF document
const pdf = new jsPDF();
pdf.addImage(imgData, 'PNG', 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight());
const pdfDataUrl = pdf.output('dataurlstring');
const context = {
filename: `${fileName}.pdf`,
url: pdfDataUrl,
};
showPDF(context);
};
reader.onerror = function() {
alert('Failed to read file.');
};
};
const showPDF = (context) => {
$("#target").html("<i class='fa fa-check'> Conversion Completed</i>");
$('#download').attr('download', context.filename);
$('#download').attr('href', context.url);
$('#download-div').show();
};
const showInProgress = () => {
$('#error').text('');
$("#target").html("<i class='fa fa-refresh fa-spin'> Converting...</i>");
$('#download-div').hide();
};
$(document).ready(function () {
$("#convert").click(function () {
convertToPDF();
});
$("#myFile").selectOnFocus();
$("#base64").selectOnFocus();
$('#converters-category').addClass('active');
$('.markdown-body').attr('style', 'max-width:100%;');
});
</script>
</html>