小编zac*_*987的帖子

Python - ReportLab 和 PyPDF 编辑 PDF 问题

PyPDF我正在尝试使用和编辑现有的 pdf 文件ReportLab。当我尝试放置红色圆圈和红色文本时,它似乎隐藏在白色容器或其他东西后面。如果我把它放在其他地方,它就可以正常工作。是什么原因造成的?

样本 pdf = https://www.puc.nh.gov/regulatory/CASEFILE/2010/10-246/INITIAL%20FILING%20-%20PETITION/10-246%202010-09-13%20BAYRING%20ATT%20TO% 20PET%20FOR%20AUTH%20TO%20CONSTRUCT%20UTILITY%20CABLE%20OVER%20AND%20ACROSS%20SUNCOOK%20RIVER.PDF

WHAT THE ERROR IS:

WHAT THE FINAL RESULT SHOULD BE:

from PyPDF2 import PdfWriter, PdfReader
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.colors import red

def main():
    packet = io.BytesIO()
    can = canvas.Canvas(packet, pagesize=letter)
    can.setFillColorRGB(1, 0, 0)
    can.circle(370,780,20,fill=1)
    can.setFillColor(red)
    can.setFont("Times-Roman", 14)
    can.drawString(352, 785, "Customer Group #22")
    can.save()

    packet.seek(0)
    new_pdf = PdfReader(packet)

    existing_pdf = PdfReader(open("samplePDF.pdf", "rb"))
    output = PdfWriter()

    page = existing_pdf.pages[1]
    page.merge_page(new_pdf.pages[0])
    output.add_page(page)

    outputStream = …
Run Code Online (Sandbox Code Playgroud)

python reportlab pypdf pdf-reader

8
推荐指数
1
解决办法
850
查看次数

Java - 调用 StandardCharsets.UTF-8 时出错

我在 下收到一条错误行StandardCharsets。我已经导入了它,所以我不确定为什么会收到错误StandardCharsets cannot be resolved to a variable。

import java.util.*;
import java.nio.charset.Charset;
import java.nio.file.Path;

public class Training
{
    
    public static void main(String[] args)
    {
        Scanner in = new Scanner(Path.of("text.txt"),StandardCharsets.UTF_8);
        
        System.out.print(in);
    }
}
Run Code Online (Sandbox Code Playgroud)

我期望打印text.txt文件中的数据。

java

2
推荐指数
1
解决办法
318
查看次数

标签 统计

java ×1

pdf-reader ×1

pypdf ×1

python ×1

reportlab ×1