Q:

How can I remove bar boarders in geom_histogram using the pdf device

I only have the problem when I try to make a pdf! Not on the default device or with png!
library(ggplot2)
theme_set(theme_bw())
data(iris)
pdf("test.pdf")
ggplot(iris,aes(x=Sepal.Length)) + geom_histogram()
dev.off()

What I want is what I get if I set the border color equal to the fill color. 
pdf("test2.pdf")
ggplot(iris,aes(x=Sepal.Length)) + geom_histogram(color='grey35')
dev.off()

Of course that solution won't generalize if I change color themes, or use the fill aesthetic. 

A:

Here's a function that makes the border colour the same as the fill colour. It's not ideal, but it seems to work.
# Load package
library(ggplot2)

# Load data
data(iris)

# Define gap filler function
gap_filler <- function(g){
  # Get ggplot object
  p <- ggplot_build(g)

  # Fix colour to match fill
  p$data[[1]]$colour <- p$data[[1]]$fill

  # Return
  grid::grid.draw(ggplot_gtable(p))
}

# Open PDF device
pdf("test.pdf")

# Create plot
g <- ggplot(iris,aes(x=Sepal.Length)) + geom_histogram()
g <- g + theme_bw()

# Fill gaps & plot
gap_filler(g)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Close device
dev.off()
#> png 
#>   2

Created on 2019-06-25 by the reprex package (v0.2.1.9000)
And the PDF looks like this:

