Is it possible to create a thumbnail image from a PDF file with Coldfusion 8? - pdf

Is it possible to create a thumbnail image from a PDF file using Coldfusion 8? (thumbnail of a given page, defaulting to page 1)

Generate thumbnails from pages in a PDF document
<cfpdf
required
action = "thumbnail"
source = "absolute or relative pathname to a PDF file|PDF document variable|
cfdocument variable"
optional
destination = "directory path where the thumbnail images are written"
format = "png|jpeg|tiff"
imagePrefix = "string used as a prefix in the output filename"
overwrite = "yes|no"
password = "PDF source file password"
pages = "page or pages to make into thumbnails"
resolution= "low|high"
scale = "percentage between 1 and 100"
transparent = "yes|no">
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_02.html
http://cfquickdocs.com/cf8/?getDoc=cfpdf#cfpdf

Adobe added quite a lot of support for PDFs in ColdFusion after they took over Macromedia. So you can also print PDFs and manipulate them.

Related

When generating a RMarkdown PDF from Shiny, PDF saving and printing is disabled

I am trying to generate a report from a Shiny app where the user can select either HTML or PDF. I am able to generate a PDF from my .rmd file (LaTex format) and everything looks good with the layout/formatting. However, the PDF is opened (using Foxit PDF Reader) with a filename other than what I specified in my downloadhandler. I am also unable to save or print the PDF through the Foxit Reader window. The file name that is output is RStudio-randomletters.pdf (ex: RStudio-FoZvSx.pdf).
Generating an html report works fine with no issues, generates the correct file name that I specified, and opens a window for me to save or rename the file.
It seems that the PDF is the only issue so I'm not sure if it is just related to reading the PDF in the Foxit Reader or if it is something else?
Update
Using Adobe Acrobat instead of Foxit allows me to now save and print, but I am still having issues with the file name for the PDF.
Here is the code for my downloadhandler
output$downloadReport <- downloadHandler(
filename = function() {
paste('Report', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html'))},
content = function(file) {
out <- if (input$format == 'HTML'){rmarkdown::render('report.Rmd',
params = list(Name = input$Name,
Reference = input$Reference),
switch(input$format,
PDF = pdf_document(), HTML = html_document()),
envir = new.env(parent = globalenv()))}
else if (input$format == 'PDF'){rmarkdown::render('pdfreport2.Rmd',
params = list(Name = input$Name,
Reference = input$Reference),
switch(input$format,
PDF = pdf_document(), HTML = html_document()),
envir = new.env(parent = globalenv()))}
file.rename(out, file)})

how can I show the pdf file content inside from razor file

I created a document file from word and has exported as pdf . i want to show the pdf content inside the Div element in razor page. How can I show the pdf content from razor page. Please can you provide an example code how to show in blazor server side
If you stored your pdf file directly in your documents for example in the folder wwwroot/pdf.
wwwroot/pdf/test.pdf
You can display this PDF with this line of html bellow :
< embed src="pdf/test.pdf" style="width=100%; height=2100px;" />
It will provide you a pdf displayer with printing options !
If you want to go further, upload your file and then display it, I will recommend you to go check this explanation :
https://www.learmoreseekmore.com/2020/10/blazor-webassembly-fileupload.html
The upload for PDF files works the same as Img file, you need to go check IBrowserFile documentation.
You will see that it has a Size obj and a OpenReadStream() function that will help you get the display Url for your file (image or pdf)
If the site abow closes, this is the upload code that is shown on it :
#code{
List<string> imgUrls = new List<string>();
private async Task OnFileSelection(InputFileChangeEventArgs e)
{
foreach (IBrowserFile imgFile in e.GetMultipleFiles(5))
{
var buffers = new byte[imgFile.Size];
await imgFile.OpenReadStream().ReadAsync(buffers);
string imageType = imgFile.ContentType;
string imgUrl = $"data:{imageType};base64,{Convert.ToBase64String(buffers)}";
imgUrls.Add(imgUrl);
}
}
}
This code was written by Naveen Bommidi, author of the blog where I found this usefull code
If you want, as I said, upload a PDF and then display it.
You can use the same html line :
< embed src="#imgUrl" style="width=100%; height=2100px;" />
And your uploaded files will be displaying.
Example

Rename page/tab title of the page that renders PDF in Grails

I'm using Grails. I need to render a PDF in browser. Here is the working code:
response.setContentType("application/pdf")
response.setHeader("Content-disposition", "inline;filename='${fileName}.pdf'")
response.outputStream << pdfFile.newInputStream()
PDF is rendered correctly, but the tab/page title is method name. E.g. for PDF rendering method pdfController/downloadPdf is used. Then the tab/page title is 'downloadPdf'. I'd like it to be the '${fileName}.pdf'. Is it possible?
Thanks in advance
You have to set content disposition as Attachment. My example also forces download in browser instead of opening it in tab.
Document documentInstance = Document.get(id) //get your document from somewhere
response.setContentType("APPLICATION/OCTET-STREAM")
response.setHeader("Content-Disposition", "Attachment;Filename=\"${documentInstance.filename}\"")
def outputStream = response.getOutputStream()
outputStream << documentInstance.filedata outputStream.flush()
outputStream.close() }

How do I figure out the font family and the font size of the words in a pdf document?

How do I figure out the font family and the font size of the words in a pdf document? We are actually trying to generate a pdf document programmatically using iText, but we are not sure how to find out the font family and the font size of the original document which needs to be generated. document properties doesn't seem to contain this information
Fonts are stored in the catalog (I suppose in a sub-catalog of type font). If you open a pdf as a text file, you should be able to find catalog entries (they begin and end with "<<" and ">>" respectively.
On a simple pdf file, i found the following:
<</Type/Font/BaseFont/Helvetica-Bold/Subtype/Type1/Encoding/WinAnsiEncoding>>
thus searching for the prefix should help you (in some pdf files, there are spaces between
the commponents but '/Type /Font' should be ok).
Of course this is a manual process, while you would probably prefer an automatic one.
On another note, we sometime use identifont or what the font to find uncommon fonts that give us problem (logo font).
regards
Guillaume
Edit : the following code will find all font in the pages. To be short, you search the dictionnary of each page for the subdictionnary "ressource" and then the subdictionnary "font". Each entry in the later is a font dictionnary, describing a font.
PdfReader reader = new PdfReader(
new FileInputStream(new File("file.pdf")));
int nbmax = reader.getNumberOfPages();
System.out.println("nb pages " + nbmax);
for (int i = 1; i <= nbmax; i++) {
System.out.println("----------------------------------------");
System.out.println("Page " + i);
PdfDictionary dico = reader.getPageN(i);
PdfDictionary ressource = dico.getAsDict(PdfName.RESOURCES);
PdfDictionary font = ressource.getAsDict(PdfName.FONT);
// we got the page fonts
Set keys = font.getKeys();
Iterator it = keys.iterator();
while (it.hasNext()) {
PdfName name = (PdfName) it.next();
PdfDictionary fontdict = font.getAsDict(name);
PdfObject typeFont = fontdict.getDirectObject(PdfName.SUBTYPE);
PdfObject baseFont = fontdict.getDirectObject(PdfName.BASEFONT);
System.out.println(baseFont.toString());
}
}
The name (variable "name" in the following code) is what is used in the text to change font. In the PDF, you'll have to find it next to a text. The following number is the size. Here for example, it's size 12. (sorry, still no code for this part).
BT
/F13 12 Tf
288 720 Td
the text to find Tj
ET
Depending on the PDF, if it hasn't been outlined you may be able to open it in Adobe Illustrator, double click the text and select some of it to see it's font family, size, etc.
If the text is outlined then use one of those online tools that PATRY suggests to find out the font.
Good luck
If you have Adobe Acrobat you can see the fonts inside and examine the objects and text streams. I wrote a blog post on this at http://pdf.jpedal.org/java-pdf-blog/bid/10479/Viewing-PDF-objects

Adding a dynamic image to a PDF using ColdFusion and iText

I pieced together some code to insert a dynamic image into a PDF using both ColdFusion and iText, while filling in some form fields as well. After I got it working and blogged about it, I couldn't help but think that there might be a better way to accomplish this. I'm using the basic idea of this in a production app right now so any comments or suggestion would be most welcomed.
<cfscript>
// full path to PDF you want to add image to
readPDF = expandpath(”your.pdf”);
// full path to the PDF we will output. Using creatUUID() to create
// a unique file name so we can delete it afterwards
writePDF = expandpath(”#createUUID()#.pdf”);
// full path to the image you want to add
yourimage = expandpath(”dynamic_image.jpg”);
// JAVA STUFF!!!
// output buffer to write PDF
fileIO = createObject(”java”,”java.io.FileOutputStream”).init(writePDF);
// reader to read our PDF
reader = createObject(”java”,”com.lowagie.text.pdf.PdfReader”).init(readPDF);
// stamper so we can modify our existing PDF
stamper = createObject(”java”,”com.lowagie.text.pdf.PdfStamper”).init(reader, fileIO);
// get the content of our existing PDF
content = stamper.getOverContent(reader.getNumberOfPages());
// create an image object so we can add our dynamic image to our PDF
image = createobject(”java”, “com.lowagie.text.Image”);
// get the form fields
pdfForm = stamper.getAcroFields();
// setting a value to our form field
pdfForm.setField(”our_field”, “whatever you want to put here”);
// initalize our image
img = image.getInstance(yourimage);
// centering our image top center of our existing PDF with a little margin from the top
x = (reader.getPageSize(1).width() - img.scaledWidth()) - 50;
y = (reader.getPageSize(1).height() - img.scaledHeight()) / 2 ;
// now we assign the position to our image
img.setAbsolutePosition(javacast(”float”, y),javacast(”float”, x));
// add our image to the existing PDF
content.addImage(img);
// flattern our form so our values show
stamper.setFormFlattening(true);
// close the stamper and output our new PDF
stamper.close();
// close the reader
reader.close();
</cfscript>
<!— write out new PDF to the browser —>
<cfcontent type=”application/pdf” file = “#writePDF#” deleteFile = “yes”>
<cfpdf> + DDX seems possible.
See http://forums.adobe.com/thread/332697
I have made it in another way with itext library
I don´t want overwrite my existing pdf with the image to insert, so just modify the original pdf inserting the image, just insert with itext doesn´t work for me.
So, I have to insert the image into a blank pdf (http://itextpdf.com/examples/iia.php?id=59)
And then join my original pdf and the new pdf-image. Obtaining one pdf with several pages.
(http://itextpdf.com/examples/iia.php?id=110)
After that you can overlay the pdf pages with this cool concept
http://itextpdf.com/examples/iia.php?id=113