英文:
Manual creation of pdf files without using third party libs
问题
我想手动创建一个PDF文件,而不使用任何第三方库。我需要创建一个示例发票格式,其中包括一些文本、一个表格和一个图像,使用原始PDF对象。我查看了一些页面,但没有提供适当的数据,并建议使用第三方库。如果有一些信息的话,将会非常有帮助。
规范链接:https://archive.org/details/pdf320002008/page/n3/mode/2up
我已经查看了规范的一些部分。我可以使用提供的示例创建包含小文本的PDF。需要一些帮助来将表格和图像添加到PDF中。在PDF示例中使用了编码,所以我无法理解表格的创建。我需要在文件中使用没有任何编码的原始对象格式。
英文:
I would like to create a pdf file manually without using any third-party libraries. I need to create a sample invoice format which will have some text, a table and an image with raw pdf objects. I looked into few pages but there is no proper data provided and suggesting using third party libs. It will be really helpful if is some information.
Specification link: https://archive.org/details/pdf320002008/page/n3/mode/2up
I gone through some sections in specification. I am able to create pdf with small text using provided example. Need some help in adding a table and an image into the pdf. In the pdf examples encoding is used so I am not able to understand the table creation. I need raw objects format without any encoding in the file.
答案1
得分: 0
Programming PDF in a console is easy, but first you need to write your PDF Header, so for a Single Page that should be simple enough in MS NotePad IDE and to Compile simply press Ctrl+S while using a real-time view alongside.
For your starter I would use a CMD to simply write the basics then add logos and Images later as they are binary and need more maths, such as using DIR to get their filesize. HOWEVER I am going to say that to make a "Basic" File.pdf acceptable for clients, either needs a parse through Printing or other PDF Lib to tidy up to a compliant level (any single CLI.exe may do).
1 0 obj <</Pages 2 0 R/Type/Catalog>>endobj
2 0 obj <</Type/Pages/Count 2/Kids [3 0 R 5 0 R]>>endobj
3 0 obj <</Type/Page/Contents 4 0 R/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/BaseFont/Helvetica/Subtype/Type1>>>>>>/MediaBox[0 0 595 842]>>endobj
4 0 obj <</Length 100>>
stream
BT
/F1 20 Tf 30 700 Td (Dear Customer) Tj
ET
BT
/F1 12 Tf 30 640 Td (Here is your Invoice!) Tj
ET
BT
/F1 11 Tf 30 620 Td
(See Page 2 for T & C) Tj
ET
1.00 g
30 550 m 565 550 l S
30 500 m 565 500 l S
30 550 m 30 50 l S
500 550 m 500 50 l S
565 550 m 565 50 l S
endstream
endobj
5 0 obj <</Type/Page/Contents 6 0 R/Parent 2 0 R>>endobj
6 0 obj <</Length 100>>
stream
0.5 g
100 600 50 75 re f S
100 600 m 500 600 l S
endstream
endobj
trailer
<</Root 1 0 R/Size 7>>
%%EOF
PDF is mainly XY coordinates (like on a graph) so 30 550 m 565 550 l says go to start at 30,550 then moving to 565,550 draw a line, the final S is the command to strike as a stroke so each line is defined exactly where needed from origin at lower left in the page's units (normally at points as 1/72" but accepts decimals) a graph paper sheet with units at say 10/72 " can help draft a template.
英文:
Programming PDF in a console is easy, but first you need to write your PDF Header, so for a Single Page that should be simple enough in MS NotePad IDE and to Compile simply press Ctrl+S while using a real time view alongside.
For your starter I would use a CMD to simply write the basics then add logos and Images later as they are binary and need more maths, such as using DIR to get their filesize. HOWEVER I am going to say that to make a "Basic" File.pdf acceptable for clients, either needs a parse through Printing or other PDF Lib to tidy up to a compliant level (any single CLI.exe may do).
%PDF-1.1
1 0 obj <</Pages 2 0 R/Type/Catalog>>endobj
2 0 obj <</Type/Pages/Count 2/Kids [3 0 R 5 0 R]>>endobj
3 0 obj <</Type/Page/Contents 4 0 R/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/BaseFont/Helvetica/Subtype/Type1>>>>>>/MediaBox[0 0 595 842]>>endobj
4 0 obj <</Length 100>>
stream
BT
/F1 20 Tf 30 700 Td (Dear Customer) Tj
ET
BT
/F1 12 Tf 30 640 Td (Here is your Invoice!) Tj
ET
BT
/F1 11 Tf 30 620 Td
(See Page 2 for T & C) Tj
ET
1.00 g
30 550 m 565 550 l S
30 500 m 565 500 l S
30 550 m 30 50 l S
500 550 m 500 50 l S
565 550 m 565 50 l S
endstream
endobj
5 0 obj <</Type/Page/Contents 6 0 R/Parent 2 0 R>>endobj
6 0 obj <</Length 100>>
stream
0.5 g
100 600 50 75 re f S
100 600 m 500 600 l S
endstream
endobj
trailer
<</Root 1 0 R/Size 7>>
%%EOF
PDF is mainly XY co-ordinates (like on a graph) so 30 550 m 565 550 l says go to start at 30,550 then moving to 565,550 draw a line the final S is the command to strike as a stroke so each line is defined exactly where needed from origin at lower left in the pages units (normally at points as 1/72" but accepts decimals) a graph paper sheet with units at say 10/72 " can help draft a template.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论