accidentallygivenfuck's blog

By accidentallygivenfuck, 9 years ago, In English

Hi Codeforces,

Does anyone know a way to download problems in a PDF file for later offline use?

I know a somewhat not-so-good way:

  • Open codeforces.com/contest/<contestid>/problems
  • Press ctrl+p
  • Set the correct preferences, so that the result will be readable
  • Print to file

But I remember that I downloaded 482B - Интересный массив in a PDF file at the beginning of the contest, when I tried to open the problem page. I don't know how, but maybe it was because the servers were too busy. That is why, I thought there might be a way to download problems in PDF format.

I still have the file. This file is more convenient than printing the problems page.

| Write comment?
»
9 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

Hello, I think you can use wkhtmltopdf, It justs requires an url as input, and it gives you the required pdf.

»
9 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

I just wrote a code for this C++0x:

Using this you can remove surplus elements from problem and have a clean page instead. You can also change <head> and style the document. It saves the document into saved.html. After saving it, Use your own method to PDFify your new HTML.

//
//  main.cpp
//  CF to PDF
//
//  Created by Hossein Yousefi on 1/11/15.
//  Copyright (c) 2015 IranGeek. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

int main(int argc, const char * argv[]) {
	cout << "Enter URL of problem: ";
	string url;
	cin >> url;
	string download_cmd = "curl " + url + " > _cfprob.html";
	system(download_cmd.c_str());
	ifstream fin("_cfprob.html");
	string tmp, parsed_html;
	while (fin >> tmp) {
		parsed_html = parsed_html + " " + tmp;
	}
	system("rm _cfprob.html");
	
	unsigned long begin, length;
	
	begin = parsed_html.find("<head>");
	length = parsed_html.find("</head>") - begin + 7;
	string head = parsed_html.substr(begin, length);
	
	begin = parsed_html.find("<!-- Frame: ProblemViewFrame.ftl -->");
	length = parsed_html.find("<!-- /Frame: ProblemViewFrame.ftl -->") - begin;
	string problem = parsed_html.substr(begin, length);
	
	string html_to_be_saved = "<HTML> " + head + " <BODY> " + problem + " </BODY> </HTML>";
	ofstream fout("saved.html");
	fout << html_to_be_saved;
	system("open saved.html");
}

TESTED in OS X.

This that problem, converted to PDF using this C++ code: https://drive.google.com/file/d/0B6dkBXoLJA10Q1ZpUTNCejA2T0k/view?usp=sharing

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

thanks

  • »
    »
    9 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    You are welcome. And thanks to you too :P But I didn't mean to be informative. I rather asked a question.

    So can someone please tell if it is possible to download problems in exactly the same format as in this file?