mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 20:58:11 +00:00
Fixes to preserve page image and demo export to html
Signed-off-by: Maksym Lysak <mly@zurich.ibm.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from docling.backend.docling_parse_backend import DoclingParseDocumentBackend
|
||||
from docling.datamodel.base_models import InputFormat
|
||||
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
||||
@@ -9,19 +11,21 @@ from docling.pipeline.vlm_pipeline import VlmPipeline
|
||||
source = "tests/data/2305.03393v1-pg9.pdf"
|
||||
|
||||
pipeline_options = PdfPipelineOptions()
|
||||
pipeline_options.generate_page_images = True
|
||||
pipeline_options.artifacts_path = "model_artifacts"
|
||||
|
||||
from docling_core.types.doc import DocItemLabel, ImageRefMode
|
||||
from docling_core.types.doc.document import DEFAULT_EXPORT_LABELS
|
||||
|
||||
converter = DocumentConverter(
|
||||
format_options={
|
||||
InputFormat.PDF: PdfFormatOption(
|
||||
pipeline_cls=VlmPipeline,
|
||||
pipeline_options=pipeline_options,
|
||||
backend=DoclingParseDocumentBackend,
|
||||
),
|
||||
InputFormat.IMAGE: PdfFormatOption(
|
||||
pipeline_cls=VlmPipeline,
|
||||
pipeline_options=pipeline_options,
|
||||
backend=DoclingParseDocumentBackend,
|
||||
),
|
||||
}
|
||||
)
|
||||
@@ -33,11 +37,11 @@ print("")
|
||||
|
||||
result = converter.convert(source)
|
||||
|
||||
print("------------")
|
||||
print("result:")
|
||||
print("------------")
|
||||
print("")
|
||||
print(result)
|
||||
# print("------------")
|
||||
# print("result:")
|
||||
# print("------------")
|
||||
# print("")
|
||||
# print(result)
|
||||
|
||||
print("------------")
|
||||
print("MD:")
|
||||
@@ -45,6 +49,13 @@ print("------------")
|
||||
print("")
|
||||
print(result.document.export_to_markdown())
|
||||
|
||||
Path("scratch").mkdir(parents=True, exist_ok=True)
|
||||
result.document.save_as_html(
|
||||
filename=Path("scratch/smol_export.html"),
|
||||
image_mode=ImageRefMode.REFERENCED,
|
||||
labels=[*DEFAULT_EXPORT_LABELS, DocItemLabel.FOOTNOTE],
|
||||
)
|
||||
|
||||
print("")
|
||||
print("============")
|
||||
print("done!")
|
||||
|
||||
Reference in New Issue
Block a user