我对python和编程很新,所以请原谅任何天真。
我想将此网页转换为pdf:http://www.ukmt-resources.org.uk/JMC16.html
我通过终端在我的Mac上使用pdfkit和wkhtmltopdf。它完成了这项工作,但生成的pdf是无用的,因为pdf最终看起来像this
是否有任何方法/是否有任何可以添加的设置将其转换为某种形式的可读格式,其中每页有合理数量的问题?
感谢您的帮助!
答案 0 :(得分:0)
您的网页看起来像是一些
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
struct secure
{
string surname;
string name;
string age;
string placeofbirth;
string tel;
secure(const string& s, const string& n, string a, const string& p, const string& t);
};
secure::secure(const string& s, const string& n, string a, const string& p, const string& t)
:surname{s},
name{n},
age{a},
placeofbirth{p},
tel{t}
{
if(!(find_if(s.cbegin(), s.cend(), [](const char z) {return !isalpha(z) && z != '-';}) == s.cend()))
cout<<"You may not use characters that are not letters nor -."<<endl;
if(!(find_if(n.cbegin(), n.cend(), [](const char x) {return !isalpha(x);}) == n.cend()))
cout<<"You are allowed to only use letters."<<endl;
if(a.find_first_not_of("0123456789"))
cout<<"Age must be a positive integer."<<endl;
if((find_if(p.cbegin(), p.cend(), [](const char c) {return !isspace(c);}) == p.cend()))
cout<<"Spaces are not allowed."<<endl;
if(t.find_first_not_of("1234567890+-"))
cout<<"Telephone numbers consists only of digits, + and -."<<endl;
}
void perfection(struct secure &secure)
{
quest:
ofstream creation;
ifstream created;
cout<<"How many students' info will be entered?: ";
string uservoice;
getline(cin, uservoice);
double enterholder;
int sum = 0;
double average = 0;
int intage;
if(!uservoice.find_first_not_of("1234567890-"))
{
cout<<"You shall enter an integer."<<endl;
goto quest;
}
int replacement = 0;
replacement=stoi(uservoice);
creation.open("knight.txt");
if(replacement>0)
{
enterholder = replacement;
cout<<"Enter data "<<uservoice<<" times."<<endl;
do
{
cout<<"Enter data as follows: "<<endl;
cout<<"Enter surname: ";
getline(cin, secure.surname);
cout<<"Enter name: ";
getline(cin, secure.name);
cout<<"Enter age: ";
getline(cin, secure.age);
intage = stoi(secure.age);
cout<<"Enter place of birth: ";
getline(cin, secure.placeofbirth);
cout<<"Enter telephone number: ";
getline(cin, secure.tel);
creation << secure.surname << '\t' << secure.name << '\t' << intage << '\t' << secure.placeofbirth << '\t' << secure.tel <<endl;
replacement--;
}while(replacement != 0);
}
else
{
cout<<"You shall enter a number bigger than 0."<<endl;
goto quest;
}
creation.close();
bool ensuretodisplay;
stringstream hasstuff;
stringstream abegins;
string s, n, p, t;
int a;
created.open("knight.txt");
while(created >> s >> n >> a >> p >> t)
{
ensuretodisplay = true;
cout << s << '\t' << n << '\t' << a << '\t' << p << '\t' << t <<endl;
hasstuff << s << t << endl;
sum+=a;
average = sum / enterholder;
if(s.find("A") == 0)
{
abegins << s << n << endl;
}
}
if(ensuretodisplay)
{
cout<<"Surnames and telephone numbers of all the students:\n"<<hasstuff.str()<<endl;
cout<<"An average age of all the students is: "<< average<<endl;
cout<<"Surnames and names of those whose surname begins with A:\n"<<abegins.str();
}
created.close();
}
int main()
{
struct secure &exotic;
perfection(exotic);
cin.get();
return 0;
}
标记单个图像。也许您需要预处理页面,在处理之前将其分解为多个页面。
您必须决定页面放置,因为很难让PDF生成器决定如何将没有页面(HTML)的内容分解为页面(PDF)。