Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
trismegisto-services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
trismegisto-services
Commits
39ad33ec
Commit
39ad33ec
authored
Mar 04, 2026
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] PDF REST AHORA ACEPTA TAMBIEN FORM DATA
parent
52b19f6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
21 deletions
+35
-21
pdfRest.java
.../java/web/multitask/trismegistoservices/rest/pdfRest.java
+35
-19
PDFService.java
...eb/multitask/trismegistoservices/services/PDFService.java
+0
-2
No files found.
src/main/java/web/multitask/trismegistoservices/rest/pdfRest.java
View file @
39ad33ec
...
...
@@ -10,6 +10,8 @@ import lombok.AllArgsConstructor;
import
web.multitask.trismegistoservices.services.PDFService
;
import
web.multitask.trismegistoservices.utils.CommonUtils
;
import
java.util.Map
;
@RestController
@CrossOrigin
(
origins
=
"*"
)
@RequestMapping
(
"/pdf"
)
...
...
@@ -19,34 +21,48 @@ public class pdfRest {
PDFService
pdfService
;
CommonUtils
commonUtils
;
@PostMapping
(
"/public/html"
)
public
ResponseEntity
<?>
htmlToPdf
(
@Request
Body
String
json
)
{
@PostMapping
(
value
=
"/public/html"
,
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
,
MediaType
.
MULTIPART_FORM_DATA_VALUE
,
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
}
)
public
ResponseEntity
<?>
htmlToPdf
(
@Request
Param
Map
<
String
,
String
>
params
,
@RequestBody
(
required
=
false
)
String
json
)
{
try
{
String
html
;
String
fileName
;
boolean
isBase64
;
if
(
json
!=
null
&&
!
json
.
isEmpty
())
{
JSONObject
jsonBody
=
new
JSONObject
(
json
);
html
=
jsonBody
.
getString
(
"html"
);
fileName
=
jsonBody
.
optString
(
"file_name"
,
"pdf.pdf"
);
isBase64
=
jsonBody
.
optBoolean
(
"base64"
);
}
else
{
html
=
params
.
get
(
"html"
);
fileName
=
params
.
getOrDefault
(
"file_name"
,
"pdf.pdf"
);
isBase64
=
Boolean
.
parseBoolean
(
params
.
get
(
"base64"
));
}
JSONObject
jsonBody
=
new
JSONObject
(
json
);
byte
[]
bytes
=
pdfService
.
generatePdf
(
jsonBody
.
getString
(
"html"
));
byte
[]
bytes
=
pdfService
.
generatePdf
(
html
);
if
(
jsonBody
.
optBoolean
(
"base64"
))
{
if
(
isBase64
)
{
String
base64
=
commonUtils
.
byteToBase64
(
bytes
);
return
ResponseEntity
.
ok
().
body
(
new
JSONObject
()
.
put
(
"base64"
,
base64
)
.
put
(
"file_name"
,
jsonBody
.
optString
(
"file_name"
,
"pdf.pdf"
))
.
put
(
"status"
,
true
)
.
put
(
"message"
,
"OK"
)
new
JSONObject
()
.
put
(
"base64"
,
base64
)
.
put
(
"file_name"
,
fileName
)
.
put
(
"status"
,
true
)
.
put
(
"message"
,
"OK"
)
.
toString
()
);
}
else
{
Resource
resource
=
commonUtils
.
byteToResource
(
bytes
,
jsonBody
.
optString
(
"file_name"
,
"no_name.pdf"
)
);
}
else
{
Resource
resource
=
commonUtils
.
byteToResource
(
bytes
,
fileName
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
jsonBody
.
optString
(
"file_name"
,
"no_name.pdf"
)
);
headers
.
add
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
fileName
);
return
ResponseEntity
.
ok
()
.
headers
(
headers
)
.
contentLength
(
bytes
.
length
)
.
contentType
(
MediaType
.
APPLICATION_PDF
)
.
body
(
resource
);
.
headers
(
headers
)
.
contentLength
(
bytes
.
length
)
.
contentType
(
MediaType
.
APPLICATION_PDF
)
.
body
(
resource
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
getMessage
()
);
return
ResponseEntity
.
internalServerError
().
body
(
e
.
getMessage
());
}
}
...
...
src/main/java/web/multitask/trismegistoservices/services/PDFService.java
View file @
39ad33ec
...
...
@@ -3,8 +3,6 @@ package web.multitask.trismegistoservices.services;
import
com.itextpdf.html2pdf.ConverterProperties
;
import
com.itextpdf.html2pdf.HtmlConverter
;
import
com.itextpdf.html2pdf.resolver.font.DefaultFontProvider
;
import
org.json.JSONArray
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment