I try to output the 1st page of pdf to png using “pdf_convert” function present in pdftools-library. I get the png but the output file name having "image(page number).png". how to get the output file exactly same to the input file name Pdf name:- beer&cider_2bay_x_4shelf_londis_cluster1.pdf Png name:- beer&cider_2bay_x_4shelf_londis_cluster1_1.png
How get output file name exactly same to input file name in R. what should be filename formating in pdfconverter in R
711 Views Asked by piya ingole At
2
There are 2 best solutions below
0
On
Adapt this code for your needs to extract all images needed from a pdf to a specific folder in png with the same name as the original pdf file:
library(pdftools)
library(glue)
library(tidyverse)
pdf_file <- "your_pdf.pdf"
output_folder <- "./output"
pdf_info <- pdf_info(pdf_file) # to get number of pages
file_name <- str_remove(string = basename(pdf_file), pattern = '\\.pdf' # basename of the file without extension
folder_name <- glue("{output_folder}/{file_name}")
full_names <- glue("{folder_name}_{1:pdf_info$pages}.png")
pdf_convert(pdf = pdf_file, format = "png", pages = 1:pdf_info$pages, filenames = full_names)
The 'pdftools' package info is avaliable at https://docs.ropensci.org/pdftools and https://github.com/ropensci/pdftools#readme.
This will generate the file in your working directory.
Save the [png] to a specific folder using full file path or
here::here()r pdftools filenames