File size: 1,409 Bytes
c49c88b
328255c
4638a07
328255c
4638a07
 
328255c
4638a07
328255c
4638a07
 
328255c
c49c88b
0913d83
c49c88b
4638a07
c49c88b
0913d83
 
 
4638a07
0913d83
 
 
 
 
 
 
4638a07
0913d83
4638a07
c49c88b
4638a07
c49c88b
 
 
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
import fitz  # PyMuPDF

def scale_vector_text(input_pdf, output_pdf, scale_factor=1.2, thickness_factor=1.2):
    """
    Scale and adjust thickness of vector-based text in a PDF.

    Args:
        input_pdf (str): Path to the input PDF.
        output_pdf (str): Path to save the modified PDF.
        scale_factor (float): Factor to scale the size of text.
        thickness_factor (float): Factor to adjust the thickness of text.
    """
    doc = fitz.open(input_pdf)

    for page in doc:
        # Process vector paths for size and thickness adjustments
        try:
            for shape in page.get_drawings():
                for path in shape["items"]:
                    if "bbox" in path:
                        # Scale bounding box for size
                        x0, y0, x1, y1 = path["bbox"]
                        path["bbox"] = (
                            x0 * scale_factor,
                            y0 * scale_factor,
                            x1 * scale_factor,
                            y1 * scale_factor,
                        )
                    # Adjust stroke thickness
                    if "line_width" in path:
                        path["line_width"] *= thickness_factor
        except Exception as e:
            print(f"Error processing vector paths on page {page.number + 1}: {e}")

    doc.save(output_pdf)
    print(f"Modified PDF saved to {output_pdf}")