给PDF添加书签的通解-姜萍同款《偏微分方程》改造手记

发布于:2024-06-25 ⋅ 阅读:(56) ⋅ 点赞:(0)

背景

网上找了一本姜萍同款的《偏微分方程》,埃文斯,英文版,可惜没有书签,洋洋七百多页,没有书签,怎么读?用福昕编辑器自然能手工一个个加上,可是劳神费力,非程序员所为。

实现

采用pdfbox即可完成,关键是要准备好目录文件。目录文件每行最后一个数字为页码。

package com.icool.command;

import java.io.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PageMode;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.auto.service.AutoService;
import com.icool.core.Command;
import lombok.extern.slf4j.Slf4j;


import static com.icool.command.CLI.MODIFY_CMD;

/**
 * @Author: 西山口小老头

 * @Date: 2023/8/4 21:17
 */

class Bookmark {
    int pageNo;
    String title;

    public Bookmark(int pageNo, String title){
        this.pageNo = pageNo;
        this.title = title;
    }
}

@AutoService(Command.class)
@Parameters(
        commandNames = {MODIFY_CMD},
        commandDescription = "fetch some articles from website."
)
@Slf4j
public class ModifyCommand implements Command{

    @Parameter(names = { "--pdfFile", "-i" })
    public String pdfFile;

    @Parameter(names = { "--output", "-o" })
    public String outputFile;

    @Parameter(names = { "--toc", "-t" })
    public String toc;

    public List<Bookmark> bookmarks;

    public ModifyCommand() {
        bookmarks = new ArrayList<>();
    }

    public void loadTOC() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(toc)));
            String line = null;
            int offset = 0;
            int pageNo = 0;
            String title = null;
            while ((line = br.readLine()) != null) {
                line = line.trim();
                log.debug(line);
                if (line.length() == 0) continue;
                String pattern = "";
                String[] fields = line.split(" ");
                String lastField = fields[fields.length - 1];
                if (line.startsWith("OFFSET")) {
                    offset = Integer.parseInt(line.split(" ")[1]);
                } else {
                    // 有的页码号在第一位,有的在最后一位
                    if (StringUtils.isNumeric(lastField)) {
                        pageNo = offset + Integer.parseInt(lastField);
                        //title = line.substring(0, line.lastIndexOf(" ")).trim() + "............" + lastField;
                        title = line.substring(0, line.lastIndexOf(" ")).trim();
                    } else {
                        pageNo = offset + Integer.parseInt(fields[0]);
                        title = line.substring(line.indexOf(" ") + 1).trim();
                    }
                    bookmarks.add(new Bookmark(pageNo, title));
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void execute() throws CommandException {
        loadTOC();
        try(PDDocument document = Loader.loadPDF(new File(pdfFile))) {
            PDDocumentOutline documentOutline = document.getDocumentCatalog().getDocumentOutline();
            if (documentOutline == null) {
                documentOutline = new PDDocumentOutline();
                document.getDocumentCatalog().setDocumentOutline(documentOutline);
            }

            for (Bookmark bookmark: bookmarks) {
                PDPageDestination pageDestination = new PDPageFitWidthDestination();
                pageDestination.setPage(document.getPage(bookmark.pageNo));
                PDOutlineItem bm = new PDOutlineItem();
                bm.setDestination(pageDestination);
                bm.setTitle(bookmark.title);
                documentOutline.addLast(bm);
            }

            documentOutline.openNode();
            document.getDocumentCatalog().setPageMode(PageMode.USE_OUTLINES);

            document.save(new File(outputFile));
        }catch (IOException ex) {
            ex.printStackTrace();
        }


    }
}

配套的目录文件如下:

OFFSET 12
Preface to second edition 1
Preface to first edition 3
OFFSET 17
1. Introduction 1
1.1. Partial differential equations 1
1.2. Examples 3
1.2.1. Single partial differential equations 3
1.2.2. Systems of partial differential equations 6 
1.3. Strategies for studying PDE 6
1.3.1. Well-posed problems, classical solutions 7
1.3.2. Weak solutions and regularity 7
1.3.3. Typical difficulties 9 
1.4. Overview 9 
1.5. Problems 12 
1.6. References 13


PART I: REPRESENTATION FORMULAS FOR SOLUTIONS 14
OFFSET 15
2. Four Important Linear PDE 17
2.1. Transport equation 18
2.1.1. Initial-value problem 18
2.1.2. Nonhomogeneous problem 19 
2.2. Laplace's equation 20
2.2.1. Fundamental solution 21 
2.2.2. Mean-value formulas 25
2.2.3. Properties of harmonic functions 26 
2.2.4. Green's function 33
2.2.5. Energy methods 41 
2.3. Heat equation 44
2.3.1. Fundamental solution 45 
2.3.2. Mean-value formula 51 
2.3.3. Properties of solutions 55 
2.3.4. Energy methods 62
2.4. Wave equation 65 
2.4.1. Solution by spherical means 67 
2.4.2. Nonhomogeneous problem 80 
2.4.3. Energy methods 82
2.5. Problems 84
2.6. References 90 
3. Nonlinear First-Order PDE 91
3.1. Complete integrals, envelopes 92 
3.1.1. Complete integrals 92 
3.1.2. New solutions from envelopes 94
3.2. Characteristics 96
3.2.1. Derivation of characteristic ODE 96
3.2.2. Examples 99
3.2.3. Boundary conditions 102 
3.2.4. Local solution 105
3.2.5. Applications 109 
3.3. Introduction to Hamilton-Jacobi equations 114 
3.3.1. Calculus of variations, Hamilton's ODE 115 
3.3.2. Legendre transform, Hopf-Lax formula 120
3.3.3. Weak solutions, uniqueness 128 
3.4. Introduction to conservation laws 135
3.4.1. Shocks, entropy condition 136 
3.4.2. Lax-Oleinik formula 143
3.4.3. Weak solutions, uniqueness 148
3.4.4. Riemann's problem 153
3.4.5. Long time behavior 156 
3.5. Problems 161
3.6. References 165
4. Other Ways to Represent Solutions 167 
4.1. Separation of variables 167
4.1.1. Examples 168
4.1.2. Application: Turing instability 172 
4.2. Similarity solutions 176
4.2.1. Plane and traveling waves, solitons 176
4.2.2. Similarity under scaling 185 
4.3. Transform methods 187
4.3.1. Fourier transform 187 
4.3.2. Radon transform 196 
4.3.3. Laplace transform 203
4.4. Converting nonlinear into linear PDE 206 
4.4.1. Cole-Hopf transformation 206 
4.4.2. Potential functions 208
4.4.3. Hodograph and Legendre transforms 209 
4.5. Asymptotics 211
4.5.1. Singular perturbations 211 
4.5.2. Laplace's method 216 
4.5.3. Geometric optics, stationary phase 218
4.5.4. Homogenization 229 
4.6. Power series 232
4.6.1. Noncharacteristic surfaces 232
4.6.2. Real analytic functions 237
4.6.3. Cauchy-Kovalevskaya Theorem 239 
4.7. Problems 244
4.8. References 249
OFFSET 13
PART II: THEORY FOR LINEAR PARTIAL DIFFERENTIAL EQUATIONS 253
OFFSET 14
5. Sobolev Spaces 253 
5.1. Holder spaces 254
5.2. Sobolev spaces 255 
5.2.1. Weak derivatives 255
5.2.2. Definition of Sobolev spaces 258
5.2.3. Elementary properties 261 
5.3. Approximation 264
5.3.1. Interior approximation by smooth functions . . . 264
5.3.2. Approximation by smooth functions 265
5.3.3. Global approximation by smooth functions .... 266 
5.4. Extensions 268 
5.5. Traces 271 
5.6. Sobolev inequalities 275
5.6.1. Gagliardo-Nirenberg-Sobolev inequality 276 
5.6.2. Morrey's inequality 280 
5.6.3. General Sobolev inequalities 284
5.7. Compactness 286 
5.8. Additional topics 289
5.8.1. Poincare's inequalities 289
5.8.2. Difference quotients 291
5.8.3. Differentiability a.e 295
5.8.4. Hardy's inequality 296 
5.8.5. Fourier transform methods 297
5.9. Other spaces of functions 299
5.9.1. The space Я"1 299
5.9.2. Spaces involving time 301 
5.10. Problems 305
5.11. References 309
OFFSET 13
6. Second-Order Elliptic Equations 311 
6.1. Definitions 311
6.1.1. Elliptic equations 311
6.1.2. Weak solutions 313 
6.2. Existence of weak solutions 315 
6.2.1. Lax-Milgram Theorem 315
6.2.2. Energy estimates 317 
6.2.3. Fredholm alternative 320
6.3. Regularity 326 
6.3.1. Interior regularity 327 
6.3.2. Boundary regularity 334
6.4. Maximum principles 344 
6.4.1. Weak maximum principle 344 
6.4.2. Strong maximum principle 347 
6.4.3. Harnack's inequality 351
6.5. Eigenvalues and eigenfunctions 354 
6.5.1. Eigenvalues of symmetric elliptic operators  354 
6.5.2. Eigenvalues of nonsymmetric elliptic operators  360
6.6. Problems 365
6.7. References 370 
7. Linear Evolution Equations 371 
7.1. Second-order parabolic equations 371
7.1.1. Definitions 372
7.1.2. Existence of weak solutions 375
7.1.3. Regularity 380
7.1.4. Maximum principles 389
7.2. Second-order hyperbolic equations 398 
7.2.1. Definitions 398
7.2.2. Existence of weak solutions 401 
7.2.3. Regularity 408 
7.2.4. Propagation of disturbances 414 
7.2.5. Equations in two variables 418
7.3. Hyperbolic systems of first-order equations 421 
7.3.1. Definitions 421
7.3.2. Symmetric hyperbolic systems 423
7.3.3. Systems with constant coefficients 429 
7.4. Semigroup theory 433
7.4.1. Definitions, elementary properties 434 
7.4.2. Generating contraction semigroups 439 
7.4.3. Applications 441
7.5. Problems 446 
7.6. References 449

OFFSET 10
 PART III: THEORY FOR NONLINEAR PARTIAL DIFFERENTIAL EQUATIONS 453
 OFFSET 11
8. The Calculus of Variations 453 
8.1. Introduction 453 
8.1.1. Basic ideas 453
8.1.2. First variation, Euler-Lagrange equation 454 
8.1.3. Second variation 458
8.1.4. Systems 459 
8.2. Existence of minimizers 465
8.2.1. Coercivity, lower semicontinuity 465 
8.2.2. Convexity 467 
8.2.3. Weak solutions of Euler-Lagrange equation . . . 472 
8.2.4. Systems 475 
8.2.5. Local minimizers 480
8.3. Regularity 482 
8.3.1. Second derivative estimates 483
8.3.2. Remarks on higher regularity 486 
8.4. Constraints 488
8.4.1. Nonlinear eigenvalue problems 488 
8.4.2. Unilateral constraints, variational inequalities . 492 
8.4.3. Harmonic maps 495 
8.4.4. Incompressibility 497
8.5. Critical points 501 
8.5.1. Mountain Pass Theorem 501
8.5.2. Application to semilinear elliptic PDE 507
8.6. Invariance, Noether's Theorem 511
8.6.1. Invariant variational problems 512 
8.6.2. Noether's Theorem 513
8.7. Problems 520
8.8. References 525 

9. Nonvariational Techniques 527 
9.1. Monotonicity methods 527
9.2. Fixed point methods 533 
9.2.1. Banach's Fixed Point Theorem 534
9.2.2. Schauder's, Schaefer's Fixed Point Theorems . . 538 
9.3. Method of subsolutions and supersolutions 543 
9.4. Nonexistence of solutions 547
9.4.1. Blow-up 547
9.4.2. Derrick-Pohozaev identity 551 
9.5. Geometric properties of solutions 554 
9.5.1. Star-shaped level sets 554
9.5.2. Radial symmetry 555 
9.6. Gradient flows 560
9.6.1. Convex functions on Hilbert spaces 560 
9.6.2. Subdifferentials and nonlinear semigroups .... 565 
9.6.3. Applications 571
9.7. Problems 573
9.8. References 577

OFFSET 10
10. Hamilton—Jacobi Equations 579
10.1. Introduction, viscosity solutions 579 
10.1.1. Definitions 581
10.1.2. Consistency 583 
10.2. Uniqueness 586 
10.3. Control theory, dynamic programming 590
10.3.1. Introduction to optimal control theory 591 
10.3.2. Dynamic programming 592 
10.3.3. Hamilton-Jacobi-Bellman equation 594 
10.3.4. Hopf-Lax formula revisited 600
10.4. Problems 603
10.5. References 606

OFFSET 9
11. Systems of Conservation Laws 609 
11.1. Introduction 609
11.1.1. Integral solutions 612
11.1.2. Traveling waves, hyperbolic systems 615 
11.2. Riemann's problem 621 
11.2.1. Simple waves 621 
11.2.2. Rarefaction waves 624
11.2.3. Shock waves, contact discontinuities 625
11.2.4. Local solution of Riemann's problem 632
11.3. Systems of two conservation laws 635 
11.3.1. Riemann invariants 635 
11.3.2. Nonexistence of smooth solutions 639
11.4. Entropy criteria 641 
11.4.1. Vanishing viscosity, traveling waves 642 
11.4.2. Entropy/entropy-flux pairs 646
11.4.3. Uniqueness for scalar conservation laws 649 
11.5. Problems 654 
11.6. References 657

OFFSET 8
12. Nonlinear Wave Equations 659 
12.1. Introduction 659
12.1.1. Conservation of energy 660
12.1.2. Finite propagation speed 660 
12.2. Existence of solutions 663
12.2.1. Lipschitz nonlinearities 663 
12.2.2. Short time existence 666
12.3. Semilinear wave equations 670 
12.3.1. Sign conditions 670 
12.3.2. Three space dimensions 674 
12.3.3. Subcritical power nonlinearities 676
12.4. Critical power nonlinearity 679 
12.5. Nonexistence of solutions 686
12.5.1. Nonexistence for negative energy 687 
12.5.2. Nonexistence for small initial data 689
12.6. Problems 691 
12.7. References 696

OFFSET 8
APPENDICES 697
Appendix A: Notation 697 
A.l. Notation for matrices 697
A.2. Geometric notation 698 
A.3. Notation for functions 699 
A.4. Vector-valued functions 703 
A.5. Notation for estimates 703
A.6. Some comments about notation 704

Appendix B: Inequalities 705 
B.l. Convex functions 705
B.2. Useful inequalities 706

Appendix C: Calculus 710 
C.l. Boundaries 710
C.2. Gauss-Green Theorem 711 
C.3. Polar coordinates, coarea formula 712 
C.4. Moving regions 713 
C.5. Convolution and smoothing 713 
C.6. Inverse Function Theorem 716 
C.7. Implicit Function Theorem 717 
C.8. Uniform convergence 718

Appendix D: Functional Analysis 719 
D.l. Banach spaces 719 
D.2. Hilbert spaces 720 
D.3. Bounded linear operators 721 
D.4. Weak convergence 723 
D.5. Compact operators, Fredholm theory 724 
D.6. Symmetric operators 728

Appendix E: Measure Theory 729 
E.l. Lebesgue measure 729 
E.2. Measurable functions and integration 730 
E.3. Convergence theorems for integrals 731 
E.4. Differentiation 732
E.5. Banach space-valued functions 733

此TOC文件可以从网上获得,也可以直接从PDF文件拷出来,当然不能是扫描版。主要工作是不断校对OFFSET值。


网站公告

今日签到

点亮在社区的每一天
去签到