why wkhtmltopdf header and footer are applied only on the table of contents page (toc)? - wkhtmltopdf

I want to apply the header and the footer to all pages but what I got is that they only appear on the toc (table of content) page. How to solve this problem?
I'm using this command.
wkhtmltopdf --encoding 'UTF-8' toc --xsl-style-sheet /Users/Documents/toc.xsl --header-html /Users/Documents/header.html --header-spacing 10 --footer-html /Users/Documents/footer.html --footer-spacing 10 /Users/Documents/draft-11.html /Users/Documents/content-draft.pdf

This fix is to provide the header and the footer twice once for TOC and once for the contents themselves
wkhtmltopdf --encoding 'UTF-8' toc --xsl-style-sheet /Users/Documents/toc.xsl --header-html /Users/Documents/header.html --header-spacing 10 --footer-html /Users/Documents/footer.html --footer-spacing 10 /Users/Documents/draft-11.html --header-html /Users/Documents/header.html --header-spacing 10 --footer-html /Users/Documents/footer.html --footer-spacing 10 /Users/Documents/content-draft.pdf

Related

Setting image width in table vs main text is not the same in RMarkdown

I have an image I'm putting in a table and the size is completely different for the HTML version compared to the PDF. I prefer the PDF version but don't know how to make the HTML get the same size as the image in the main text (the image in table is oto small).
---
title: "Untitled"
output:
pdf_document: default
html_document: default
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
| Icônes | Explications | Exemple |
|:-------------|:-----------------------|:--------------------------|
| ![](../../../images/icones_Rstudio/cancel_2x.png){width="5%"} | `R` est en exécution | NA |
main
![](../../../images/icones_Rstudio/cancel_2x.png){width="5%"}
The image I used is here. How to make the image size in the table the same without changing the width parameter? I output both HTML and PDF from the same RMarkdown and I don't want to have 2 different files to set the size of these images... so in the end, the images in the HTML should be like the one in the PDF.

HexaPDF add font when importing other document's page

I have app that adding texts for original pdf and generate new pdf.
All is good until I have page that contain different font, then target pdf have no glyphs(boxes instead of characters), when source_doc saved, it displays font properly.
Perhaps something to do with how .import method work but i did not found way :/
Here is part of code:
target_doc = HexaPDF::Document.new
source_doc = HexaPDF::Document.open("source.pdf")
page = source_doc.pages[0]
canvas = page.canvas(type: :overlay)
# ... some code filling the doc with the text
font_file = "new_font.ttf"
source_doc.fonts.add(font_file)
canvas.font font_file
canvas.text(text, at: [x, y])
# back to default font
canvas.font(FONT_FAMILY, size: FONT_SIZE)
source_doc.pages.each { |page| target_doc.pages << target_doc.import(page) }
target_doc.write(output_file)
I have tried to .add font to target_doc but it did not added(tried before and after import)
In the target_doc.fonts I can see font loaded in loaded_fonts_cache and in glyphs.
Anyone has any clue how can I import pages including font used in it ?
Document used: https://hexapdf.gettalong.org/examples/merging.html
In order to import page with missing information(like new fonts), need to call this method before importing pages to a new pdf, after source_doc.fonts.add(font_file) because this info available only after all glyps are known to the source document.
source_doc.dispatch_message(:complete_objects)
Thanks to Thomas, author of HexaPDF <3
https://github.com/gettalong/hexapdf/issues/214

How do I put a stamp on the upper right corner?

I'm trying to put a stamp on the top right corner of a PDF file. I have a PS file created from Excel using driver for HP Color LaserJet 4500 printed to file.
I am using GhostScript to create a PDF.
GSWIN32C.EXE #S:\Temp\PS\Options.txt
Here is the contents of the Options.txt file:
-sDEVICE=pdfwrite -q -dSAFER -dNOPAUSE
-sOUTPUTFILE="S:\Temp\PS\Sample.pdf" -dBATCH
"S:\Temp\PS\Stamp.txt"
"S:\Temp\PS\Sample.ps"
Here is the contents of Stamp.txt modified from here:
<<
/EndPage
{
2 eq { pop false }
{
gsave
/Helvetica_Bold 15 selectfont
0 setgray
475 767 moveto
(STATE COPY) show
grestore
true
} ifelse
} bind
>> setpagedevice
The PDF is created just fine, but the stamp is causing me problems. The stamp shows very tiny on the upper left but flipped vertically.
Here is a section with the tiny stamp upper left:
Here is the stamp enlarged 800%
On a multi-page PDF I want the stamp on all pages. I understand that using the /EndPage should let me do that.
So how do I get my stamp on the upper right corner?
I assume the problem with the stamp resides in the previous transformations. So I used scale to flip the stamp upright and adjusted until I got it in the right place.
<<
/EndPage
{
2 eq { pop false }
{
gsave
/Helvetica_Bold 15 selectfont
0 setgray
10 10 scale
375 17 moveto
1 -1 scale
(STATE COPY) show
grestore
true
} ifelse
} bind
>> setpagedevice
I didn't test it but I assume using a different print driver to produce the PS file would give different results.

What's the best approach to generate image based on user submitted text on server side like Rails

Guys,
I see ImageMagick is capable to generate image using Pango formatted text, which looks like quite a good approach.
Just want to know if there's anything else out there, what's the most recommended way of doing this.
imagemagick is probably the easiest, but ghostscript can also be used to render images with text.
Here's a little postscript program that displays some text.
%!
5 5 moveto
/Palatino-Roman 20 selectfont
(Some Text) show
showpage
Using ps2eps will calculate the Bounding-Box and add this information as a comment conforming to the Document Structuring Conventions.
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 5 5 97 20
%%HiResBoundingBox: 5.500000 5.000000 97.000000 19.500000
%%EndComments
% EPSF created by ps2eps 1.64
%%BeginProlog
save
countdictstack
mark
newpath
/showpage {} def
/setpagedevice {pop} def
%%EndProlog
%%Page 1 1
5 5 moveto
/Palatino-Roman 20 selectfont
(Some Text) show
showpage
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
%%EOF
Then imagemagick's convert utility can render this as an image.
The ps2eps is necessary so the final image is cropped to the interesting part, rather than at the bottom of a page-sized image.
Here's a typescript of the whole sequence. 0> is the command prompt.
0> cat > t.ps
%!
5 5 moveto
/Palatino-Roman 20 selectfont
(Some Text) show
showpage
0> ps2eps t.ps
Input files: t.ps
Processing: t.ps
Calculating Bounding Box...ready. %%BoundingBox: 5 5 97 20
Creating output file t.eps...** Warning **: Weird heading line -- %! -- ready.
0> convert t.eps t.png

Excel VBA Footer Image

Is there a way to use Excel-VBA code in order to make a picture object in a sheet, so as to insert it as a footer image. I have tried to do so by creating a chart object and pasting it in a picture-format, and then exporting the chart to an image file and setting the image as the footer. Is there a better way to insert a picture object as a footer image, and if so, how do I do it?
I started the macro recorder. I clicked Page Setup then Header/Footer then Custom Footer. I clicked the centre section and then Format Picture (button with image of sun over mountains). I browsed for an image and clicked Insert. "&[Picture]" appeared in the centre section. I clicked OK twice. I switched the macro recorder off.
I printed the page and the selected image appeared at the bottom.
The important code saved by the macro recorder was:
ActiveSheet.PageSetup.CenterFooterPicture.Filename = _
"C:\Users\Public\Pictures\Sample Pictures\Desert Landscape.jpg"
Replace "C:\Users\Public\Pictures\Sample Pictures\Desert Landscape.jpg" with filename of your choice.
The macro recorder is usually the easiest way of discovering statements like this.
For anybody viewing this in the future, I'll share my code to copy a range and save it as a file on your computer, which can then be added to the footer. You can eliminate whatever bits you don't want =)
Dim objPic As Shape
Dim objChart As Chart
Dim strTimeStamp As String
Dim strFileDest As String
20 Sheets(2).Activate
30 Sheets(2).Columns("R:T").AutoFit
40 Sheets(2).Rows("17:21").AutoFit
50 ActiveWindow.DisplayGridlines = False
60 Call Sheets(2).Range("S17", "U21").CopyPicture(xlScreen, xlPicture)
70 ActiveWindow.DisplayGridlines = True
80 Sheets(2).Shapes.AddChart
90 Sheets(2).Activate
100 Sheets(2).Shapes.Item(1).Select
110 Set objChart = ActiveChart
120 ActiveChart.Parent.Name = "FooterChart"
' For some reason, Excel occasionally tries to make an actual chart out of these strings.
' It's just a nonsensical chart that messes the footer up but I'm having trouble duplicating the issue and figuring out what causes it.
' This should always work. Don't use .Clear, it crashes.
130 ActiveChart.ChartArea.ClearContents
140 objChart.Paste
150 Selection.Name = "FooterImage"
160 ActiveSheet.ChartObjects("FooterChart").Activate
170 Sheets(2).Shapes.Item(1).Line.Visible = msoFalse
180 Sheets(2).Shapes.Item(1).Height = Range("S17", "U21").Height
190 Sheets(2).Shapes.Item(1).Width = Range("S17", "U21").Width
200 ActiveChart.Shapes.Range(Array("FooterImage")).Height = Range("S17", "U21").Height
210 ActiveChart.Shapes.Range(Array("FooterImage")).Width = Range("S17", "U21").Width
220 Sheets(2).Shapes.Item(1).Height = Sheets(2).Shapes.Item(1).Height * 1.25
230 Sheets(2).Shapes.Item(1).Width = Sheets(2).Shapes.Item(1).Width * 1.25
240 ActiveChart.Shapes.Range(Array("FooterImage")).Height = ActiveChart.Shapes.Range(Array("FooterImage")).Height * 1.2
250 ActiveChart.Shapes.Range(Array("FooterImage")).Width = ActiveChart.Shapes.Range(Array("FooterImage")).Width * 1.2
260 strTimeStamp = CStr(Format(Now(), "yyyymmddHhNnSs"))
270 strFileDest = "D:\Temp" & strTimeStamp & ".jpg"
280 objChart.Export strFileDest
290 InsertPicture strFileDest
300 If Len(Dir$(strFileDest)) > 0 Then
310 Kill strFileDest
320 End If
330 Sheets(2).Shapes.Item(1).Delete
Try this:
Dim ws as Worksheet
Set ws = Worksheets("YourWorksheetName")
With ws.PageSetup
.CenterFooterPicture = "&G" 'Specifies that you want an image in your footer
.CenterFooterPicture.Filename = "C:\Pictures\MyFooterImage.jpg" 'specifies the image file you want to use
End With
The code generated by the macro recorder will get you part of the way there, but as is often the case, it doesn't provide the whole or most appropriate solution. It also sounds like you are trying to insert an image generated by Excel (such as a chart) into the footer? if that's the case, I believe you will have to same the object as an image and then reference that image file.

Resources