-
Notifications
You must be signed in to change notification settings - Fork 0
/
2020-02-04-Gitbook-tool-Chinese-font-in-PDF.html
498 lines (356 loc) · 15 KB
/
2020-02-04-Gitbook-tool-Chinese-font-in-PDF.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>
Gitbook生成PDF字体不正确的问题及解决方案 | Sprial Up Life
</title>
<meta name="generator" content="hexo-theme-yilia-plus">
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="/css/style.css">
<script src="/js/pace.min.js"></script>
</head>
</html>
<body>
<div id="app">
<main class="content">
<section class="outer">
<article id="post-Gitbook-tool-Chinese-font-in-PDF" class="article article-type-post" itemscope
itemprop="blogPost" data-scroll-reveal>
<div class="article-inner">
<header class="article-header">
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
Gitbook生成PDF字体不正确的问题及解决方案
</h1>
</header>
<div class="article-meta">
<a href="/2020-02-04-Gitbook-tool-Chinese-font-in-PDF.html" class="article-date">
<time datetime="2020-02-04T17:35:57.000Z" itemprop="datePublished">2020-02-04</time>
</a>
<div class="word_count">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="ri-quill-pen-line"></i>
<span class="post-meta-item-text"> 字数统计:</span>
<span class="post-count">155字</span>
</span>
</span>
<span class="post-time">
|
<span class="post-meta-item-icon">
<i class="ri-book-open-line"></i>
<span class="post-meta-item-text"> 阅读时长≈</span>
<span class="post-count">1分钟</span>
</span>
</span>
</div>
</div>
<div class="article-entry" itemprop="articleBody">
<p>采用gitbook pdf转换中文markdown 文件到PDF时发现部分字符加粗显示,部分显示正常,但是无法辨识正确的系统字体。<br>最终发现解决办法为:</p>
<ol>
<li>增加book.json文件到文件夹的根目录(可参考默认文件作为模板)</li>
<li><p>增加以下element到json文件:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"pdf"</span>: {</span><br><span class="line"> <span class="string">"pageNumbers"</span>: <span class="literal">true</span>,</span><br><span class="line"> <span class="string">"fontSize"</span>: <span class="number">12</span>,</span><br><span class="line"> <span class="string">"paperSize"</span>: <span class="string">"a4"</span>,</span><br><span class="line"> <span class="string">"fontFamily"</span>:<span class="string">"Microsoft YaHei"</span>,</span><br><span class="line"> <span class="string">"margin"</span>: {</span><br><span class="line"> <span class="string">"right"</span>: <span class="number">30</span>,</span><br><span class="line"> <span class="string">"left"</span>: <span class="number">30</span>,</span><br><span class="line"> <span class="string">"top"</span>: <span class="number">30</span>,</span><br><span class="line"> <span class="string">"bottom"</span>: <span class="number">50</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>其中fontFamily最为重要,同样的中文字体,例如雅黑,fontFamily可以是 <code>Microsoft YaHei</code>,也可以是中文的<code>微软雅黑</code>。推荐采用英文。</p>
</li>
<li><p>执行 <code>gitbook pdf . ./target.pdf</code></p>
</li>
</ol>
<!-- 打赏 -->
<div id="reward-btn">
打赏
</div>
</div>
<footer class="article-footer">
<a data-url="http://blackumbrella.github.io/2020-02-04-Gitbook-tool-Chinese-font-in-PDF.html" data-id="ck69suyqk00025ch5bbmiw4nj"
class="article-share-link">分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/gitbook-pdf/">gitbook, pdf</a></li></ul>
</footer>
</div>
<nav class="article-nav">
<a href="/2020-02-05-enhance-Win-10-preview-functionality.html" class="article-nav-link">
<strong class="article-nav-caption">上一篇</strong>
<div class="article-nav-title">
enhance Win 10 preview functionality
</div>
</a>
<a href="/2014-02-13-Font-How-to-make-logo-with-some-special-chinese-fonts.html" class="article-nav-link">
<strong class="article-nav-caption">下一篇</strong>
<div class="article-nav-title">Font-How to make logo with some special chinese fonts.</div>
</a>
</nav>
<!-- valine评论 -->
<div id="vcomments-box">
<div id="vcomments">
</div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/Valine.min.js'></script>
<script>
new Valine({
el: '#vcomments',
notify: false,
verify: '',
app_id: '',
app_key: '',
path: window.location.pathname,
avatar: 'mp',
placeholder: '给我的文章加点评论吧~',
recordIP: true
});
const infoEle = document.querySelector('#vcomments .info');
if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
infoEle.childNodes.forEach(function (item) {
item.parentNode.removeChild(item);
});
}
</script>
<style>
#vcomments-box {
padding: 5px 30px;
}
@media screen and (max-width: 800px) {
#vcomments-box {
padding: 5px 0px;
}
}
#vcomments-box #vcomments {
background-color: #fff;
}
.v .vlist .vcard .vh {
padding-right: 20px;
}
.v .vlist .vcard {
padding-left: 10px;
}
</style>
</article>
</section>
<footer class="footer">
<div class="outer">
<ul class="list-inline">
<li>
©
2015-2020
Scott Wu
</li>
<li>
Powered by
<a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
</li>
</ul>
<ul class="list-inline">
<li>
<ul class="list-inline">
<li>PV:<span id="busuanzi_value_page_pv"></span></li>
<li>UV:<span id="busuanzi_value_site_uv"></span></li>
</ul>
</li>
<li>
<!-- cnzz统计 -->
<script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&web_id=1278069914'></script>
</li>
</ul>
</div>
</footer>
<div class="to_top">
<div class="totop" id="totop">
<i class="ri-arrow-up-line"></i>
</div>
</div>
</main>
<aside class="sidebar">
<button class="navbar-toggle"></button>
<nav class="navbar">
<div class="logo">
<a href="/"><img src="/images/ayer-side.svg" alt="Sprial Up Life"></a>
</div>
<ul class="nav nav-main">
<li class="nav-item">
<a class="nav-item-link" href="/">主页</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/archives">归档</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/categories">分类</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/tags">Tags</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/about">关于我</a>
</li>
</ul>
</nav>
<nav class="navbar navbar-bottom">
<ul class="nav">
<li class="nav-item">
<a class="nav-item-link nav-item-search" title="Search">
<i class="ri-search-line"></i>
</a>
<a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
<i class="ri-rss-line"></i>
</a>
</li>
</ul>
</nav>
<div class="search-form-wrap">
<div class="local-search local-search-plugin">
<input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
<div id="local-search-result" class="local-search-result"></div>
</div>
</div>
</aside>
<div id="mask"></div>
<!-- #reward -->
<div id="reward">
<span class="close"><i class="ri-close-line"></i></span>
<p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
<div class="reward-box">
<div class="reward-item">
<img class="reward-img" src="/images/alipay.jpg">
<span class="reward-type">支付宝</span>
</div>
<div class="reward-item">
<img class="reward-img" src="/images/wechat.jpg">
<span class="reward-type">微信</span>
</div>
</div>
</div>
<script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.justifiedGallery.min.js"></script>
<script src="/js/lazyload.min.js"></script>
<script src="/js/busuanzi-2.3.pure.min.js"></script>
<script src="/fancybox/jquery.fancybox.min.js"></script>
<script>
try {
var typed = new Typed("#subtitle", {
strings: ['面朝大海,春暖花开','愿你一生努力,一生被爱','想要的都拥有,得不到的都释怀'],
startDelay: 0,
typeSpeed: 200,
loop: true,
backSpeed: 100,
showCursor: true
});
} catch (err) {
}
</script>
<script src="/js/tocbot.min.js"></script>
<script>
// Tocbot_v4.7.0 http://tscanlin.github.io/tocbot/
tocbot.init({
tocSelector: '.tocbot',
contentSelector: '.article-entry',
headingSelector: 'h1, h2, h3, h4, h5, h6',
hasInnerContainers: true,
scrollSmooth: true,
scrollContainer:'main',
positionFixedSelector: '.tocbot',
positionFixedClass: 'is-position-fixed',
fixedSidebarOffset: 'auto',
onClick: (e) => {
$('.toc-link').removeClass('is-active-link');
$(`a[href=${e.target.hash}]`).addClass('is-active-link');
$(e.target.hash).scrollIntoView();
return false;
}
});
</script>
<script>
var ayerConfig = {
mathjax: false
}
</script>
<script src="/js/ayer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.css">
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe-ui-default.min.js"></script>
<script>
function viewer_init() {
let pswpElement = document.querySelectorAll('.pswp')[0];
let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))
$imgArr.forEach(($em, i) => {
$em.onclick = () => {
// slider展开状态
// todo: 这样不好,后面改成状态
if (document.querySelector('.left-col.show')) return
let items = []
$imgArr.forEach(($em2, i2) => {
let img = $em2.getAttribute('data-idx', i2)
let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
let title = $em2.getAttribute('alt')
// 获得原图尺寸
const image = new Image()
image.src = src
items.push({
src: src,
w: image.width || $em2.width,
h: image.height || $em2.height,
title: title
})
})
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
index: parseInt(i)
});
gallery.init()
}
})
}
viewer_init()
</script>
<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
</div>
</body>
</html>