mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +01:00 
			
		
		
		
	changing html and book labels
This commit is contained in:
		
							parent
							
								
									22343e507d
								
							
						
					
					
						commit
						96e399a617
					
				@ -77,16 +77,11 @@ public class AppConfig {
 | 
			
		||||
        return Files.exists(Paths.get("/.dockerenv"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Bean(name = "bookFormatsInstalled")
 | 
			
		||||
    public boolean bookFormatsInstalled() {
 | 
			
		||||
        return applicationProperties.getSystem().getCustomApplications().isInstallBookFormats();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Bean(name = "htmlFormatsInstalled")
 | 
			
		||||
    public boolean htmlFormatsInstalled() {
 | 
			
		||||
    @Bean(name = "bookAndHtmlFormatsInstalled")
 | 
			
		||||
    public boolean bookAndHtmlFormatsInstalled() {
 | 
			
		||||
        return applicationProperties
 | 
			
		||||
                .getSystem()
 | 
			
		||||
                .getCustomApplications()
 | 
			
		||||
                .isInstallAdvancedHtmlToPDF();
 | 
			
		||||
                .isInstallBookAndHtmlFormats();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import stirling.software.SPDF.model.ApplicationProperties;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@DependsOn({"bookFormatsInstalled"})
 | 
			
		||||
@DependsOn({"bookAndHtmlFormatsInstalled"})
 | 
			
		||||
public class EndpointConfiguration {
 | 
			
		||||
    private static final Logger logger = LoggerFactory.getLogger(EndpointConfiguration.class);
 | 
			
		||||
    private Map<String, Boolean> endpointStatuses = new ConcurrentHashMap<>();
 | 
			
		||||
@ -24,14 +24,14 @@ public class EndpointConfiguration {
 | 
			
		||||
 | 
			
		||||
    private final ApplicationProperties applicationProperties;
 | 
			
		||||
 | 
			
		||||
    private boolean bookFormatsInstalled;
 | 
			
		||||
    private boolean bookAndHtmlFormatsInstalled;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    public EndpointConfiguration(
 | 
			
		||||
            ApplicationProperties applicationProperties,
 | 
			
		||||
            @Qualifier("bookFormatsInstalled") boolean bookFormatsInstalled) {
 | 
			
		||||
            @Qualifier("bookAndHtmlFormatsInstalled") boolean bookAndHtmlFormatsInstalled) {
 | 
			
		||||
        this.applicationProperties = applicationProperties;
 | 
			
		||||
        this.bookFormatsInstalled = bookFormatsInstalled;
 | 
			
		||||
        this.bookAndHtmlFormatsInstalled = bookAndHtmlFormatsInstalled;
 | 
			
		||||
        init();
 | 
			
		||||
        processEnvironmentConfigs();
 | 
			
		||||
    }
 | 
			
		||||
@ -229,7 +229,7 @@ public class EndpointConfiguration {
 | 
			
		||||
    private void processEnvironmentConfigs() {
 | 
			
		||||
        List<String> endpointsToRemove = applicationProperties.getEndpoints().getToRemove();
 | 
			
		||||
        List<String> groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove();
 | 
			
		||||
        if (!bookFormatsInstalled) {
 | 
			
		||||
        if (!bookAndHtmlFormatsInstalled) {
 | 
			
		||||
            groupsToRemove.add("Calibre");
 | 
			
		||||
        }
 | 
			
		||||
        if (endpointsToRemove != null) {
 | 
			
		||||
 | 
			
		||||
@ -26,12 +26,8 @@ public class PostStartupProcesses {
 | 
			
		||||
    private boolean runningInDocker;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Qualifier("bookFormatsInstalled")
 | 
			
		||||
    private boolean bookFormatsInstalled;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Qualifier("htmlFormatsInstalled")
 | 
			
		||||
    private boolean htmlFormatsInstalled;
 | 
			
		||||
    @Qualifier("bookAndHtmlFormatsInstalled")
 | 
			
		||||
    private boolean bookAndHtmlFormatsInstalled;
 | 
			
		||||
 | 
			
		||||
    private static final Logger logger = LoggerFactory.getLogger(PostStartupProcesses.class);
 | 
			
		||||
 | 
			
		||||
@ -39,15 +35,11 @@ public class PostStartupProcesses {
 | 
			
		||||
    public void runInstallCommandBasedOnEnvironment() throws IOException, InterruptedException {
 | 
			
		||||
        List<List<String>> commands = new ArrayList<>();
 | 
			
		||||
        // Checking for DOCKER_INSTALL_BOOK_FORMATS environment variable
 | 
			
		||||
        if (bookFormatsInstalled) {
 | 
			
		||||
        if (bookAndHtmlFormatsInstalled) {
 | 
			
		||||
            List<String> tmpList = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
            tmpList = new ArrayList<>();
 | 
			
		||||
            tmpList.addAll(Arrays.asList("whoami"));
 | 
			
		||||
            commands.add(tmpList);
 | 
			
		||||
 | 
			
		||||
            tmpList = new ArrayList<>();
 | 
			
		||||
            tmpList.addAll(Arrays.asList("id"));
 | 
			
		||||
            tmpList.addAll(Arrays.asList("apk add --no-cache calibre"));
 | 
			
		||||
            commands.add(tmpList);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -23,21 +23,21 @@ import stirling.software.SPDF.utils.WebResponseUtils;
 | 
			
		||||
public class ConvertBookToPDFController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Qualifier("bookFormatsInstalled")
 | 
			
		||||
    private boolean bookFormatsInstalled;
 | 
			
		||||
    @Qualifier("bookAndHtmlFormatsInstalled")
 | 
			
		||||
    private boolean bookAndHtmlFormatsInstalled;
 | 
			
		||||
 | 
			
		||||
    @PostMapping(consumes = "multipart/form-data", value = "/book/pdf")
 | 
			
		||||
    @Operation(
 | 
			
		||||
            summary =
 | 
			
		||||
                    "Convert a BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) to PDF",
 | 
			
		||||
            description =
 | 
			
		||||
                    "(Requires bookFormatsInstalled flag and Calibre installed) This endpoint takes an BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx)  input and converts it to PDF format.")
 | 
			
		||||
                    "(Requires bookAndHtmlFormatsInstalled flag and Calibre installed) This endpoint takes an BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx)  input and converts it to PDF format.")
 | 
			
		||||
    public ResponseEntity<byte[]> HtmlToPdf(@ModelAttribute GeneralFile request) throws Exception {
 | 
			
		||||
        MultipartFile fileInput = request.getFileInput();
 | 
			
		||||
 | 
			
		||||
        if (!bookFormatsInstalled) {
 | 
			
		||||
        if (!bookAndHtmlFormatsInstalled) {
 | 
			
		||||
            throw new IllegalArgumentException(
 | 
			
		||||
                    "bookFormatsInstalled flag is False, this functionality is not avaiable");
 | 
			
		||||
                    "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (fileInput == null) {
 | 
			
		||||
 | 
			
		||||
@ -30,22 +30,22 @@ import stirling.software.SPDF.utils.WebResponseUtils;
 | 
			
		||||
public class ConvertPDFToBookController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Qualifier("bookFormatsInstalled")
 | 
			
		||||
    private boolean bookFormatsInstalled;
 | 
			
		||||
    @Qualifier("bookAndHtmlFormatsInstalled")
 | 
			
		||||
    private boolean bookAndHtmlFormatsInstalled;
 | 
			
		||||
 | 
			
		||||
    @PostMapping(consumes = "multipart/form-data", value = "/pdf/book")
 | 
			
		||||
    @Operation(
 | 
			
		||||
            summary =
 | 
			
		||||
                    "Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF",
 | 
			
		||||
            description =
 | 
			
		||||
                    "(Requires bookFormatsInstalled flag and Calibre installed) This endpoint Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF")
 | 
			
		||||
                    "(Requires bookAndHtmlFormatsInstalled flag and Calibre installed) This endpoint Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF")
 | 
			
		||||
    public ResponseEntity<byte[]> HtmlToPdf(@ModelAttribute PdfToBookRequest request)
 | 
			
		||||
            throws Exception {
 | 
			
		||||
        MultipartFile fileInput = request.getFileInput();
 | 
			
		||||
 | 
			
		||||
        if (!bookFormatsInstalled) {
 | 
			
		||||
        if (!bookAndHtmlFormatsInstalled) {
 | 
			
		||||
            throw new IllegalArgumentException(
 | 
			
		||||
                    "bookFormatsInstalled flag is False, this functionality is not avaiable");
 | 
			
		||||
                    "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (fileInput == null) {
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 | 
			
		||||
@Tag(name = "Convert", description = "Convert APIs")
 | 
			
		||||
public class ConverterWebController {
 | 
			
		||||
 | 
			
		||||
    @ConditionalOnExpression("#{bookFormatsInstalled}")
 | 
			
		||||
    @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}")
 | 
			
		||||
    @GetMapping("/book-to-pdf")
 | 
			
		||||
    @Hidden
 | 
			
		||||
    public String convertBookToPdfForm(Model model) {
 | 
			
		||||
@ -21,7 +21,7 @@ public class ConverterWebController {
 | 
			
		||||
        return "convert/book-to-pdf";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ConditionalOnExpression("#{bookFormatsInstalled}")
 | 
			
		||||
    @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}")
 | 
			
		||||
    @GetMapping("/pdf-to-book")
 | 
			
		||||
    @Hidden
 | 
			
		||||
    public String convertPdfToBookForm(Model model) {
 | 
			
		||||
 | 
			
		||||
@ -290,31 +290,20 @@ public class ApplicationProperties {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static class CustomApplications {
 | 
			
		||||
            private boolean installBookFormats;
 | 
			
		||||
            private boolean installAdvancedHtmlToPDF;
 | 
			
		||||
            private boolean installBookAndHtmlFormats;
 | 
			
		||||
 | 
			
		||||
            public boolean isInstallBookFormats() {
 | 
			
		||||
                return installBookFormats;
 | 
			
		||||
            public boolean isInstallBookAndHtmlFormats() {
 | 
			
		||||
                return installBookAndHtmlFormats;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public void setInstallBookFormats(boolean installBookFormats) {
 | 
			
		||||
                this.installBookFormats = installBookFormats;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public boolean isInstallAdvancedHtmlToPDF() {
 | 
			
		||||
                return installAdvancedHtmlToPDF;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public void setInstallAdvancedHtmlToPDF(boolean installAdvancedHtmlToPDF) {
 | 
			
		||||
                this.installAdvancedHtmlToPDF = installAdvancedHtmlToPDF;
 | 
			
		||||
            public void setInstallBookAndHtmlFormats(boolean installBookAndHtmlFormats) {
 | 
			
		||||
                this.installBookAndHtmlFormats = installBookAndHtmlFormats;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public String toString() {
 | 
			
		||||
                return "CustomApplications [installBookFormats="
 | 
			
		||||
                        + installBookFormats
 | 
			
		||||
                        + ", installAdvancedHtmlToPDF="
 | 
			
		||||
                        + installAdvancedHtmlToPDF
 | 
			
		||||
                return "CustomApplications [installBookAndHtmlFormats="
 | 
			
		||||
                        + installBookAndHtmlFormats
 | 
			
		||||
                        + "]";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -14,39 +14,4 @@ public class HTMLToPdfRequest extends PDFFile {
 | 
			
		||||
            description = "Zoom level for displaying the website. Default is '1'.",
 | 
			
		||||
            defaultValue = "1")
 | 
			
		||||
    private float zoom;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Width of the page in centimeters.")
 | 
			
		||||
    private Float pageWidth;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Height of the page in centimeters.")
 | 
			
		||||
    private Float pageHeight;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Top margin of the page in millimeters.")
 | 
			
		||||
    private Float marginTop;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Bottom margin of the page in millimeters.")
 | 
			
		||||
    private Float marginBottom;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Left margin of the page in millimeters.")
 | 
			
		||||
    private Float marginLeft;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "Right margin of the page in millimeters.")
 | 
			
		||||
    private Float marginRight;
 | 
			
		||||
 | 
			
		||||
    @Schema(
 | 
			
		||||
            description = "Enable or disable rendering of website background.",
 | 
			
		||||
            allowableValues = {"Yes", "No"})
 | 
			
		||||
    private String printBackground;
 | 
			
		||||
 | 
			
		||||
    @Schema(
 | 
			
		||||
            description =
 | 
			
		||||
                    "Enable or disable the default header. The default header includes the name of the page on the left and the page number on the right.",
 | 
			
		||||
            allowableValues = {"Yes", "No"})
 | 
			
		||||
    private String defaultHeader;
 | 
			
		||||
 | 
			
		||||
    @Schema(
 | 
			
		||||
            description = "Change the CSS media type of the page. Defaults to 'print'.",
 | 
			
		||||
            allowableValues = {"none", "print", "screen"},
 | 
			
		||||
            defaultValue = "print")
 | 
			
		||||
    private String cssMediaType;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,7 @@ system:
 | 
			
		||||
  googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow
 | 
			
		||||
  enableAlphaFunctionality: false # Set to enable functionality which might need more testing before it fully goes live (This feature might make no changes)
 | 
			
		||||
  customApplications:
 | 
			
		||||
    installBookFormats: false # Installs Calibre for book format conversion (For non docker it must be manually downloaded but will need to be true to show in UI)
 | 
			
		||||
    installAdvancedHtmlToPDF: false # DO NOT USE EXTERNALLY, NOT SAFE! Install wkHtmlToPDF (For non docker it must be manually downloaded but will need to be true to show in UI)
 | 
			
		||||
    installBookAndHtmlFormats: false # Installs Calibre for book format conversion (For non docker it must be manually downloaded but will need to be true to show in UI)
 | 
			
		||||
  
 | 
			
		||||
#ui:
 | 
			
		||||
#  appName: exampleAppName # Application's visible name
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user