Showing posts with label PDF. Show all posts
Showing posts with label PDF. Show all posts

Friday, March 17, 2017

Converting SVG to PDF on Linux Command Line

A number of tools available for converting a SVG to a PDF file on Linux command line, for instances,
  • rsvg-convert
    
           $ sudo apt-get install librsvg2-bin
           $ rsvg-convert -f pdf -o mygraph.pdf mygraph.svg
        
  • ImageMagick
    
           $ sudo apt-get install imagemagick
           $ convert mygraph.svg mygraph.pdf
        
  • Inkscape
    
           $ sudo apt-get install inkscape
           $ inkscape mygraph.svg --export-pdf=mygraph.pdf
        

A few others include GhostPDL and CairoSVG. Each of these tools has its own limitations, particularly, supported SVG features. My limited use points to that Inkspace appears to have the most supported features.

Friday, August 5, 2016

Installing Adobe Reader in Ubuntu 16.04 LTS

For those who like Adobe Reader to read PDF files, you may find it difficult to install Adobe Reader on Ubuntu 16.04 LTS systems. Assembling information from a few posts, here is the solution that worked for me,
 

sudo apt-get clean all
sudo add-apt-repository "deb http://archive.canonical.com/ precise partner"
sudo apt-get update
sudo apt-get install adobereader-enu
sudo add-apt-repository -r "deb http://archive.canonical.com/ precise partner"
sudo apt-get clean all
sudo apt-get update

If you are on a x64 system, you may see many annoying warning messages when you run acroreader, such as,

......
(acroread:19366): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
......
Gtk-Message: Failed to load module "canberra-gtk-module"
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"


To get rid of the warning messages, install these four packages gtk2-engines-murrine, libcanberra-gtk-module, libatk-adaptor, and libgail-commonfor i386 as follows,

sudo apt-get install gtk2-engines-murrine:i386 libcanberra-gtk-module:i386 libatk-adaptor:i386 libgail-common:i386

If you are running Gnome like I do, then the last step is to set up default application for open PDF files. This is to edit the /etc/gnome/defaults.list file.

sudo gedit /etc/gnome/defaults.list
The editing is to find and replace the line

application/pdf=evince.desktop

by

application/pdf=acroread.desktop
and add the following lines to the end of the file,

application/fdf=acroread.desktop
application/xdp=acroread.desktop
application/xfdf=acroread.desktop
application/pdx=acroread.desktop

Finally, run nautilus to apply change if you do not wish to log out and log back in.

nautilus -q


Thursday, September 17, 2015

Improving Windows Desktop Search for PDF and Other Binary Files

Windows Search, formerly Windows Desktop Search, may not index content and metadata of binary files, such as, those of PDF files without assistance of some additional software although it does index the files based on their names.

To enable Windows Search to index content and metadata of binary files, we need to install some additional software to help the Windows Search. Windows Search supports iFilter. With the matching iFilter add-in installed, Windows Search can index content and metadta of binary files of certain types. The iFilter.org site lists a number of iFilter add-ins for a few types of binary files, e.g., ZIP, CAB, CHM, DjVu, and PDF files.

Below we show how we can enable indexing content and metadata of  PDF files.

First, we can check whether PDF iFilter exists. The following steps are carried out on a Windows 10 host.
  1. Open "Windows Control Panel"
  2. Search and open "Indexing Options"
  3. Open "Advanced" from "Indexing Options" 
  4. Choose "File Types"
  5. Locate the "pdf" file type.



    Above figure shows that "Registered iFILTER is not found", which means that iFilter add-in is not installed and Windows Search do not index content and metadata of PDF files.
To enable indexing content and metadata of PDF files, we can choose and install Adobe PDF iFilter. If the PDF iFilter is installed, repeating the above step, Windows will indicate that the iFilter is intalled as illustrated in the figure below.



 To force Windows Search to index content and metadata of PDF files immediately upon the  installation of the PDF iFilter, we can check and uncheck PDF file types from the "File Types" tab of the "Advanced Options" of the "Indexing Options" as follows,
  1. Open "Control Panel", "Indexing Option", then "Advanced Option", and finally, the "File Types" tab
  2. Locate the "pdf" file type
  3. Uncheck the "pdf" file type
  4. Click "OK"
  5. Window pops up a dialogue window stating "Rebuilding the index might take a long time to complete. Some views and search results might be incomplete until rebuilding is finished." Click "Cancel" on this dialogue window.
  6. Windows will return to "Indexing Option". Now click on "Advanced" again to open the "Advanced Options"
  7. On the Advanced Options, choose "File Types"
  8. Locate the "pdf" file type again
  9. Check the "pdf" file type
  10. Click on "OK" to confirm
  11. Window now pops up again the dialogue window stating "Rebuilding the index might take a long time to complete. Some views and search results might be incomplete until rebuilding is finished." Click "OK" on this dialogue window to confirm. Windows starts rebuilding the index. Depending on the amount files on the disk, it may take a long time to rebuild the index. 
  12. You can safely close the "Indexing Option". Windows index continues to rebuild the index in background.


Thursday, March 12, 2015

Converting PDF to EPS Figure for LaTeX

Sometimes we want to convert a figure in PDF format to EPS format and use the figure in a LaTex file. One important item we must take care is the bounding box of the figure. If the bounding box is not generated correctly, we would have a large area of wide space around the figure in final document.

In a Linux system, we have a set of free tools that can help us produce an appropriate bounding box and convert PDF format to EPS format.
On Ubuntu, you may install them using apt-get as follows,

sudo apt-get install \
     pdftk gv texlive-extra-utils \
     poppler-utils ghostscript ps2eps


Assume that PDF file foo.pdf contains an interesting figure in page 2 and we want to extract the figure for inserting it in a LaTex document. We would follow the steps below,
  1. Extract the page from the PDF file that contains the figure we would like to extract

    pdftk foo.pdf cat 2 output page2.pdf
    

    where foo.pdf is the input PDF file, page2.pdf  is the output PDF file, and 2 is the page number in the input PDF file.

  2. Measure roughtly the position and the dimension of a box that contains the figure using gv.
    
    gv page2.pdf
    

    We read the coordinates of the bottom left corner and the top right corner of the box from gv. Assume the readings are (61, 82) and (321, 161), respectivley.

  3. Crop the PDF file based on the box obtained in the above.
    
    pdfcrop --bbox "61 82 321 161" page2.pdf
    

    The output of this step is page2-crop.pdf.

  4. Crop the resulting PDF file from previous step to reduce white space around the figure.
    
    pdfcrop page2-crop.pdf
    

    The result is page2-crop-crop.pdf.

  5. Convert the PDF file to an EPS file.
    
    pdftops -eps page2-crop-crop.pdf page2.eps
    

    We could complete the last step using pdf2ps in Ghostscript instead of pdftops by the Poppler developers as the following two steps approach.
    
    pdf2ps page2-crop-crop.pdf 
    ps2eps page2-crop-crop.ps page2.eps
    

    However, we do not recommend pdf2ps, convinced by the argument made by Stefaan Lippens.

    As indicated by Stefaan Lippens, pdf2ps converts fonts in PDF files to bitmap fonts in resulting PS files. Some may consider this an advantage because the fonts used in the figure will always be "present" in the PDF files generated form the corresponding LaTeX files. However, as we discussed previously, it is not difficult to embedd all fonts in a PDF file.

Wednesday, January 22, 2014

Producing PDF document Compatible to Firefox Build-in PDF Viewer

Sometimes Firefox Build-in PDF Viewer does not render some PDF documents well, in which case, the PDF Viewer complains that the PDF document may not be displayed correctly.

A suggested method to correct it is to use external PDF viewer as suggested at Mozilla.

Web searches yield lots of discussions and the discussions are mostly how to find a way to display it correctly just like the above. Those discussions are on the "consumer" side.

However, if you are the on the side of producing and posting PDF documents online, you are probably more interested from beginning with in producing PDF documents that can be displayed correctly by the Firefox Build-in PDF Viewer.

As I investigate, this is not a trivial task. Generally, when the PDF Viewer does not display the document correctly, it is a result that the document contains certain feature which the viewer does not support. To generate a compatible PDF document to the viewer is not to use any unsupported feature that the viewer does not support. However, I failed to locate any document showing which feature is supported and which is not, including the project site at GitHub.

One method that worked for me at least in a few occasions is to use Firefox's Element Inspector.

When a PDF document is not displayed correctly, locate the element that is not displayed correctly or a nearby element to the element that is invisible as a result of not being displayed correctly, right-click the mouse and select "Inspect Element". Examine the element and elements nearby in the Inspector. If you examine them carefully, you may identify something suspicious. For instance, in FireFox 26.0, a PDF file saved in Microsoft PowerPoint is not displayed correctly. Examining it in the Element Inspector, I found out that the location of the problem and suspected that the font "Verdana" somehow could not be displayed correctly, as shown below.
 

By replacing font "Verdana" by a recognizable font, the problem went away.