I am getting an error when using the append_pdfs function

I am simply trying to add two figuress to a single pdf. I can create a sepaprate pdf for each figure but when I try to add them both to one pdf I get the following error: Error using append_pdfs
Unterminated quote in @-file: figure2.pdf". This is quite frustrating as I have downloaded Ghostscript and export_fig from the matlab file exchange. I have also added these directories to my matlab path by clicking 'Set Path' and adding the corresponding folders. I have included my code below. Any help would be much appreciated.
% Create multiple figures
addpath('C:\Users\SCS Engineer\Downloads\github_repo');
figure(1);
plot(rand(1,10));
title('Figure 1');
print('figure1.pdf', '-dpdf')
figure(2);
plot(rand(1,10));
title('Figure 2');
print('figure2.pdf', '-dpdf')
% % Specify the filename for the PDF file
% filename = 'my_figures.pdf';
%
% % Create a PDF file with the two figures
% print(filename, '-dpdf', '-bestfit', '-r300', '-painters', 'figure1', 'figure2');
append_pdfs('all_figures.pdf', 'figure1.pdf', 'figure2.pdf')

8 Comments

Please post a copy of the complete error message. The missing parts might be important.
Use the debugger for further investigamtions:
dbstop if error
When Matlab stops at the error, what are the values of the locally used variables?
Error using append_pdfs
Unterminated quote in @-file: figure2.pdf"
Error in singlepdf (line 21)
append_pdfs('all_figures.pdf', 'figure1.pdf', 'figure2.pdf');
Theres the two full error messages, do you have any idea whats wrong?
I have tried debugging this but it doesnt seem to work. Is there any possibility you can copy and paste my code into Matlab and have a quick look at it yourself? I have tried everything and Ive been looking at the code all day.
addpath('C:\Users\SCS Engineer\Downloads\github_repo');
figure(1);
plot(rand(1,10));
title('Figure 1');
print('figure1.pdf', '-dpdf')
figure(2);
plot(rand(1,10));
title('Figure 2');
print('figure2.pdf', '-dpdf')
append_pdfs("all_figures.pdf", 'figure1.pdf', 'figure2.pdf');
I could guess, where you download append_pdf from, or better you post a link. I cannot know, what the "github_repo" folder contains. Therefore it is not reliable, if I try to debug your code.
Does the error message really not contain any information about the line, where the error occurs?
Maybe this line is included in a TRY CATCH block. Then use:
dbstop if caught error
to stop, when the problem occurs. Then, as said already, inspect the contents of the used variables. One of them contains an unterminated code. You could post what you find there.
The github_repo folder just contains all information relating to export_fig. It is also required to download Ghostscript to use the append_pdfs function. So if you were to have a go at debugging this you would need to download both and set them to your current path in matlab. If you do not want to download export_fig and Ghostscript on your computer then I understand. One other quick question. Where in the code should I put the line 'dbstop if caught error'. Should I put it just before append_pdfs or after it?
"Where in the code should I put the line 'dbstop if caught error'." - Whereever you want, but not after the failing function is called, because then the dbstop command is not reached. I do this in the command window, because debugging is not a part of the computation.
Another option is to set a breakpoint in append_pdfs and step through the code line by line. The debugger is the best tool to debug programs.
The actual problem is that anywhere is one orphaned quote. It should be possible to find out, where and why it is missing.
this seems to be something with the latest realease of Matlab 2023a. It works for me with R2023a Update 1 but not with R2023a Update 3 where I run into the same problem.

Sign in to comment.

Answers (2)

Hi Jack,
As mentioned in the documentation overview of append_pdfs in File Exchange:
This function is now included in the export_fig package:
The version here will not be maintained.
Please prefer using export_fig package, as this package is maintained and updated frequently. Last update being on 23 Mar 2023. Please refer to the below mentioned link to know more about 'export_fig' or to download 'export_fig' through File exchange:
Hope this helps!
same problem:
the code is easy:
out='C:\users\fem\desktop\test.pdf'
in1='C:\users\fem\desktop\1.pdf'
in2='C:\users\fem\desktop\2.pdf'
in3='C:\users\fem\desktop\3.pdf'
append_pdfs(out,in1,in2,in3)
i obtain a test.pdf file with only 2 files appended and the error:
Error using append_pdfs (line_131)
Unterminated quote in @-file: C:\users\fem\desktop\3.pdf"
what i've noticed is:
-the error is obtained always with the last file of the list, no matter which is it or how many are them and the generated files is missing of this last file
-in the error message there is a " at the end of the file name

3 Comments

Same problem and I've noticed the same thing about the last item in the list.
You can fix this by adding in the call a new line at the end before "fclose"
fprintf(fh, '\n');
How is it possible that within an hour of you posting this fix (that works brilliantly btw), I run into the issue for the first time and find this thread first try?
Thank you!

Sign in to comment.

Categories

Asked:

on 13 Mar 2023

Commented:

on 10 Nov 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!