Блог пользователя accidentallygivenfuck

Автор accidentallygivenfuck, 10 лет назад, По-английски

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 - Interesting Array 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.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

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

»
10 лет назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

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

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

thanks

  • »
    »
    10 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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?