Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, August 31, 2020 3:29:15 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

Hi all,
I have a source PDF document with a few text lines.
For each line I have to append a bitmap (QRcode) according to the text content.

At the moment I am able to enumerate the text lines using PDFDocument.ParsePages as described in LeadTools examples.

But I have no idea how to generate a new document with the text lines followed by the bitmaps.
I have very small experience with LeadTools SDK so any example and/or architecture indication will be highly appreciated.

Best regards,
PaoloC
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, August 31, 2020 3:17:10 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

Hello,

I believe you can use the LEADTOOLS Virtual Document framework to handle this. There's a code snippet on the documentation page.
https://www.leadtools.co...umentfactory-create.html

Here's some additional information on writing barcodes:
https://www.leadtools.co...writer-writebarcode.html

You can load your initial document in memory and add the pages in it to a new Virtual Document. Then, the RasterImage containing the barcode image can be saved out as well.

After the Virtual Document has been created, you can use the DocumentConverter to save it back to disk.
https://www.leadtools.co...document-converters.html

Edited by moderator Tuesday, September 1, 2020 7:59:44 AM(UTC)  | Reason: Not specified

Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
thanks 1 user thanked Nick for this useful post.
Paolo Cazzola on 9/1/2020(UTC)
 
#3 Posted : Tuesday, September 1, 2020 8:52:38 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

Hi Nick,
thanks a lot for your suggestions.
Now I am able to clone pages from old to new document.
Anyway I cannot see the barcode on the new document.
I presume I have to do something to update the RasterImage on the document page but I don't know which method should be invoked.
Hereafter the code snippet I am using:

newDocument.Pages.Add(childDocument.Pages[0]);

RasterImage pageImage = newDocument.Pages[0].GetImage();
BarcodeEngine engine = new BarcodeEngine();
BarcodeWriter writer = engine.Writer;
BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, "01234567890");
data.Bounds = new LeadRect(0, 0, 400, 200);
writer.WriteBarcode(pageImage, data, null);

Best regards,
PaoloC
 
#4 Posted : Tuesday, September 1, 2020 4:11:45 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

Apologies--could you clarify your development needs? Does the barcode need to be on the same page as the text, or on a subsequent follow-up one?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#5 Posted : Wednesday, September 2, 2020 2:35:12 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

On the same page of text.
Original document:

Text1
Text2
Text3

New document:

Text1 Barcode1
Text2 Barcode2
Text3 Barcode3
 
#6 Posted : Wednesday, September 2, 2020 6:39:38 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

As an experiment I tried to replace the raster image to the page adding SetImage() function but I got the following exception when SetImage() is invoked :-(

Invalid URI: The format of the URI could not be determined.

newDocument.Pages.Add(childDocument.Pages[0]);

RasterImage pageImage = newDocument.Pages[0].GetImage();
BarcodeEngine engine = new BarcodeEngine();
BarcodeWriter writer = engine.Writer;
BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, "01234567890");
data.Bounds = new LeadRect(100, 100, 400, 200);
writer.WriteBarcode(pageImage, data, null);


newDocument.Pages[0].SetImage(pageImage); // Throws URI exception


 
#7 Posted : Wednesday, September 2, 2020 9:21:05 AM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

Note if you want the barcode on the same page as the text itself, it'll be necessary to rasterize the page first, which will in effect convert the page to a flat image without any searchable text. This may not necessarily be ideal for your development needs, though.
https://www.leadtools.co...o/rastercodecs-load.html

Once the input is loaded as a RasterImage, it can be used as a target for the barcodewriter. You can specify the area to which the barcode is written in the RasterImage via the BarcodeData.Bounds property of the passed parameter.
https://www.leadtools.co...writer-writebarcode.html
https://www.leadtools.co.../barcodedata-bounds.html

You can save the resulting RasterImage to disk via RasterCodecs.Save(). Note this will save as a RasterImage without any searchable or text-based information.
https://www.leadtools.co...o/rastercodecs-save.html

Could you clarify your pipeline--are you preparing these for printing?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#8 Posted : Wednesday, September 2, 2020 10:48:12 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

Hi Nick,
thanks for your support.

1) Note if you want the barcode on the same page as the text itself, it'll be necessary to rasterize the page first,

How can I get the RasterImage using RasterCodecs.Load starting from a DocumentPage info ?

2) This may not necessarily be ideal for your development needs, though.

I suppose to search text string and their bounds before rasterizing the image

3) You can save the resulting RasterImage to disk via RasterCodecs.Save()

Is it possible to update the image in the DocumentPage via SetImage or create a new Page from scratch using the modified RasterImage ?

4) Could you clarify your pipeline--are you preparing these for printing?

My goal is to start from a PDF file and create a new PDF file

Best regards,
Paolo






 
#9 Posted : Thursday, September 3, 2020 4:35:21 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

The Uri exception is likely being thrown because a relative path is being used for the cache. When instantating the DocumentFactory, enable a cache (you can use our default FileCache) and set the CacheDirectory structure to an absolute path on disk:

Code:
DocumentFactory.Cache = new FileCache() { CacheDirectory = workDir };

"workDir" would be this location. This should prevent the Uri exception from raising.

After you've finished the barcode logic with the DocumentPage.GetImage() -> barcode writing -> DocumentPage.SetImage() the LEADDocument.SaveToFile() method can be used to write this to a raster format where the modifications to the page image will persist.
https://www.leadtools.co...document-savetofile.html

Is it necessary for your development needs for the files created in this way to still be searchable afterward?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#10 Posted : Monday, September 7, 2020 9:01:32 AM(UTC)
Paolo Cazzola

Groups: Registered
Posts: 7

Thanks: 1 times

Hi Nick,
your suggestion to use an absolute path for the CacheDirectory has solved the issue of newDocument.Pages[0].SetImage(pageImage) throwing exception.
Thanks a lot !!!

Now I am able to save the document with both original text and the new barcode as a raster image using the following code:

var jobData = DocumentConverterJobs.CreateJobData(newDocument, outputFileName, RasterImageFormat.RasPdfLzw);
jobData.JobName = "conversion job";

using (DocumentConverter documentConverter = new DocumentConverter())
{
var job = documentConverter.Jobs.CreateJob(jobData);
documentConverter.Jobs.RunJob(job);

if (job.Status == DocumentConverterJobStatus.Success)


On the other hand SaveToFile throws {"Specified method is not supported."} exception when invoked in the following way:

var saveOptions = new SaveDocumentOptions();
saveOptions.Format = RasterImageFormat.RasPdfLzw;
saveOptions.BitsPerPixel = 0;
newDocument.SaveToFile(outputFileName, saveOptions);

Hereafter the stack trace:

at Leadtools.Document.VirtualDocument.InternalSaveToFile(String documentFileName, String annotationsFileName, SaveDocumentOptions options)
at Leadtools.Document.LEADDocument.DoSave(Uri uri, String fileName, SaveDocumentOptions options)
at Leadtools.Document.LEADDocument.SaveToFile(String fileName, SaveDocumentOptions options)
at TestSvg.Program.testSave(String sourceFile) in C:\DevTools\LeadTools\Test\VirtualPrintTest\TestSvg\Program.cs:line 88
at TestSvg.Program.Main(String[] args) in C:\DevTools\LeadTools\Test\VirtualPrintTest\TestSvg\Program.cs:line 39

I cannot understand why one method succeeds while the other fails; anyway I can survive using DocumentConverter solution :-)

Best regards
PaoloC

 
#11 Posted : Wednesday, September 9, 2020 3:22:30 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

I wasn't able to reproduce the error condition using SaveToFile(), however, given saving using the DocumentConverter functions as expected I'll close out this case.

Glad you were able to arrive at a solution.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.332 seconds.