Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple images in one page #1760

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"installGradle": true,
"installMaven": true,
"installAnt": true,
"installGroovy": true,
"version": "17",
"jdkDistro": "ms",
"gradleVersion": "latest",
"mavenVersion": "latest",
"antVersion": "latest",
"groovyVersion": "latest"
},
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"version": "latest"
}
},

"mounts": [
{
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.ssh",
"target": "/home/vscode/.ssh",
"type": "bind"
}]



// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
25 changes: 25 additions & 0 deletions apend_properties_to_lang_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Description: This script appends a multi-line string to the end of all the files in the folder that end with _[A-Za-z][A-Za-z].properties

cd src/main/resources

# The multi-line string to append to the end of the file with EOF
STRING_TO_APPEND=$(cat <<EOF

#Template strings image to pdf

imageToPDF.templates=Templates
imageToPDF.selectLabel.templates=Templates Options (Enabled only when templates are selected in fitOptions)
imageToPDF.selectText.templates.1=1x2
imageToPDF.selectText.templates.2=2x2
imageToPDF.selectText.templates.3=2x3
EOF
)

# Loop through all the files in the folder that end with .properties
for file in *_[A-Za-z][A-Za-z].properties
do
# Append the multi-line string with a newline to the end of the file
echo "$STRING_TO_APPEND" >> "$file"
done
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package stirling.software.SPDF.config.security;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
Expand All @@ -13,6 +17,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;

import stirling.software.SPDF.config.DatabaseBackupInterface;
import stirling.software.SPDF.config.security.session.SessionPersistentRegistry;
import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface;
Expand All @@ -23,10 +28,6 @@
import stirling.software.SPDF.repository.AuthorityRepository;
import stirling.software.SPDF.repository.UserRepository;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class UserService implements UserServiceInterface {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ public ResponseEntity<byte[]> convertToPdf(@ModelAttribute ConvertToPdfRequest r
MultipartFile[] file = request.getFileInput();
String fitOption = request.getFitOption();
String colorType = request.getColorType();
String templateOptions = request.getTemplateOption();
boolean autoRotate = request.isAutoRotate();

// Convert the file to PDF and get the resulting bytes
byte[] bytes = PdfUtils.imageToPdf(file, fitOption, autoRotate, colorType);
byte[] bytes = PdfUtils.imageToPdf(file, fitOption, templateOptions, autoRotate, colorType);
return WebResponseUtils.bytesToWebResponse(
bytes,
file[0].getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_converted.pdf");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import stirling.software.SPDF.model.api.PDFFile;
import stirling.software.SPDF.utils.PdfUtils;
import stirling.software.SPDF.utils.PdfUtils.TemplateOpcions;
import stirling.software.SPDF.utils.WebResponseUtils;

@RestController
Expand Down Expand Up @@ -80,7 +81,13 @@ public ResponseEntity<byte[]> fakeScan(@ModelAttribute PDFFile request) throws I
// PDPageContentStream contentStream = new PDPageContentStream(newDocument, new
// PDPage());
PDImageXObject pdImage = JPEGFactory.createFromImage(newDocument, img);
PdfUtils.addImageToDocument(newDocument, pdImage, "maintainAspectRatio", false);
PdfUtils.addImageToDocument(
newDocument,
pdImage,
"maintainAspectRatio",
false,
1,
TemplateOpcions.TWO_IMAGES);
}

newDocument.save(baos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package stirling.software.SPDF.controller.web;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
Expand All @@ -13,6 +13,14 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.config.security.session.SessionPersistentRegistry;
import stirling.software.SPDF.model.*;
import stirling.software.SPDF.model.ApplicationProperties.Security.OAUTH2;
Expand All @@ -22,11 +30,6 @@
import stirling.software.SPDF.model.provider.KeycloakProvider;
import stirling.software.SPDF.repository.UserRepository;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Controller
@Slf4j
@Tag(name = "Account Security", description = "Account Security APIs")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/stirling/software/SPDF/model/User.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package stirling.software.SPDF.model;

import jakarta.persistence.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.persistence.*;

@Entity
@Table(name = "users")
public class User implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ public class ConvertToPdfRequest {

@Schema(
description = "Option to determine how the image will fit onto the page",
allowableValues = {"fillPage", "fitDocumentToImage", "maintainAspectRatio"})
allowableValues = {
"fillPage",
"fitDocumentToImage",
"maintainAspectRatio",
"Templates"
})
private String fitOption;

@Schema(
description = "The color type of the output image(s)",
allowableValues = {"color", "greyscale", "blackwhite"})
private String colorType;

@Schema(
description = "Option to determine how the image will fit onto the page",
allowableValues = {"1x2", "2x2", "2x3"})
private String templateOption;

@Schema(
description = "Whether to automatically rotate the images to better fit the PDF page",
example = "true")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package stirling.software.SPDF.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import stirling.software.SPDF.model.User;

import java.util.Optional;
import stirling.software.SPDF.model.User;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Expand Down
Loading
Loading