PDF output from MATLAB and inclusion in LaTeX - matlab

I'm printing some figures in MATLAB in PDF form, and can view them fine with the Evince PDF viewer on Fedora 16.
When I try to include them in LaTeX (TeXLive 2011), however, I get an error
!pdfTeX error: /usr/local/texlive/2011/bin/x86_64-linux/pdflatex (file ./caroti
d_amp_mod_log.pdf): xpdf: reading PDF image failed
However, I can take an example PDF image generated in Mathematica and include it just fine, which tells me that the problem is with the PDF's generated by MATLAB and not with PDF's in general.
Might it have something to do with the set(0,'defaultfigurepaperpositionmode','auto')I put in my startup.m file so that pages would auto-fit the images?
EDIT: I just tried using saveas(figure(1), 'filename.pdf') instead of print(figure(1), 'filename.pdf') and it worked fine, but the PaperPositionMode property is ignored. Any way around this?

Finally found the problem. The correct way to print images is to use the print(handle, '-dformat', 'filename') syntax.
So, for PDF's, we need print(figure(1), '-dpdf', 'myfigure'). See MATLAB documentation on graphics file formats for more information.
Using print(figure(1), 'filename.pdf') still produces a valid PDF for viewing, but it can't be included in LaTeX.

You can try using
pdfpages
or
pgf
to include pdf files. However, you need to use pdflatex only, as you are doing right now.

Related

How to export a PDF with figures on multiple pages?

I am trying to export a larger number of Matlab figures that are generated in for loop to a single PDF file. Right now the best thing I could come up with is to all print them to a PostScrip file using the -append option like this:
print('Temp_Plots','-dpsc','-append')
After that I could convert the PS file to a PDF file. This workflow was okay until I started to use plots with 2 y axis. Unfortunately it seems like Matlab's PS export cannot properly handle this situation and does not color the lines appropriately.
As there is no -append option for the direct PDF export what other methods do I have to append all my plots to a single file without losing the assigned colors or other hickups?
I would recommend trying out the publish command and push that to its limits first.
Following the documentation:
options = struct('format','pdf','outputDir','C:\myPublishedOutput');`
publish('myCode.m',options);
Take a look at Publishing Markup to see how to get the look you want.
This search brings up some possibly related posts, but none that I saw that directly match your issue.
References:
1. Publishing Markup (Mathworks)
2. Output Preferences for Publishing (Mathworks)
3. Publishing M-Files in MATLAB
4. Publish Your Work in Matlab

How to Export Graphics in MATLAB with exportdlg.m to SVG with embedding fonts?

Hello last_hope_community, ;)
I have tried several options of exporting, the standard export. Works well to SVG.
load patients
figure
tbl = table(LastName,Age,Gender,SelfAssessedHealthStatus,...
Smoker,Weight,Location);
h = heatmap(tbl,'Smoker','SelfAssessedHealthStatus');
saveas(gcf,["test_heatp_save_svg.svg"],'svg') %no export style-> fonts gets embedded
%print(gcf,["test_heatp_print_pdf"],'-dpdf','-bestfit','-r0')
Saveas and print, but here is point 1.
For setprinttemplate one can not adopt the styles from the exportsetup (hgexport and so on). Print has the very nicy opportunity of -bestfit which one can use with print to pdf(with print fonts are embedded automatically) and then to import in Inkscape to use as SVG. But when styles are adopted, by export manually to save it then as SVG within the exportdlg or with saveas, all fonts gets vectorpaths.
Is there a way to apply export styles automatically and then get an SVG File in which the fonts are embedded in SVG like in the upper code?
I have already checked if it is just a heatmap issue but it is not. Same with the following code, without export_style everything is great. But with export style everything gets to vector paths.
figure
plot(1:10000)
title('Hallo')
saveas(gcf,["test_simple_save_svg.svg"],'svg')
%print(gcf,["test_simple_print_pdf"],'-dpdf','-bestfit','-r0')
Best would be if anyone knows a way to apply exportstyles programatically and to then save as svg with embedded font, or apply exportstyles programmatically and then print to pdf with -bestfit,export as pdf would just embed the titles and not the TickLabels.
Additional print with bestfit is not always good because the result from the figure window varies from time to time a lot.
Thanks for help, it's annoying that export as svg makes paths from text that one cannot customize with other programms.

How to convert .SFF file format to .BMP or .PNG or .JPG?

I need to convert my SFF file to PDF, then i need verify the document. i.e SFF file and converted file.
For that, I think to convert SFF file to image file and PDF file to image file.
Then comparing the both file using image processing.
To do this method:
Im searching for a program to convert SFF to BMP
Does anyone know such a program or has another idea how to do the job?
Thank you in advance...
Looks like you need reaConvertor. It appears to be a matured tool you can rely on. There is an online version of the tool here
I think:
https://github.com/Sonderstorch/sfftools
will do what you need (convert sff -> tiff/jpeg/..) and then you can use imageMagic (for example) to go to PDF.
Clearly not a current well used image format, however if you have legacy.sff Structured Fax Format, they are similar (not exactly identical) to a Monochrome G4 format.
By far the simplest programmable method to convert is using IrfanView which can Read Modify and Resave as other formats in batches.
Out put can be any other modern image type including Mono.BMP, G4.fax or as PDF (with or without GhostScript)

Perl code for inserting graphs into MS Word

I am using Perl for automation for report generation. Reports are generated in HTML. same report can be opened in MS word format. tables generated in HTML look good in Word too.
Problem:
Ineed to also insert few graphs in the report. For HTML, I am using SVG::TT::Graph::Line Perl module to generate the graphs.
The idea here is to keep single HTML file that contains all tables and graphs.
Currently every thing looks good in HTML. but when i open the same file in Word, the graphs are replaced by data (because I am using SVG Perl module).
Just wondering what would be the best way to generate graphs for Word file that doesn't change my code much.
Any suggestions with the Perl modules to be used would be much appreciated.
I haven't tried this, but the only thing I can think of is to use ImageMagick to convert the SVG to PNG and then use a Data URI to embed the image in the HTML.

How to programmatically convert PostScript to PDF with the fewest steps?

Is there any way to just slap on a header and use a PS file as a PDF, assuming that the PS is very simple and do anything complicated?
I want to do this programmatically, not using ps2pdf.
Thanks.
You can certainly *try" "just slapping on a header" ... but I don't think you'll get too far :-)
Personally, I'd suggest ps2pdf is the best solution (for example, invoke it with ShellExec() or system()).
But if you want a programmatic solution, ps2pdf is just a wrapper around Ghostscript. Have you considered using the Ghostscript libraries?
You cannot wrap a PostScript file into a PDF file.
Although a PDF file looks similar to a PostScript file,
a PDF file must have a special structure, including a cross-reference
table at the end with file offsets to different parts of the PDF file.
To understand the PDF file format you can download the PDF Reference from:
http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf
If your software generates the PostScript file, maybe you can
extend it to write a PDF file too? It takes some time to understand
the PDF file format but it is not especially difficult if you are familiar with PostScript.
If this is too difficult, then use pdf2ps to do the hard work for you.