Read content from 'A.pdf' and copy to 'B.pdf'

I have a requirement where I want to copy the contents of a pdf (‘A.pdf’) generated from 3rd party tool to (B.pdf’) using Aspose.PDF

There is a chart in A.pdf which I need to copy to B.pdf

Tried solution 1) I read the contents of the Pdf using TextAbsorber, ImageAbsorber, ParagraphAbsorber I get exception Font not found.

Tried solution 2) If I loop through the contents of the page(page.Contents) from A.pdf and copy to contents of B.pdf, B.pdf when saved has blank pages.

I do not know what is the type of control placed in A.pdf so it is difficult to fetch using TextAbsorber, ImageAbsorber, ParagraphAbsorber .

Tried solution 3) If I copy the pages of A.pdf to B.pdf then the chart is copied to B.pdf but it occupies the whole page. This is problematic as I only want the chart from A.pdf and insert it into paragraph collection of my page in B.pdf.

Please provide a solution at your earlies

@PriyankaShelke

Thanks for contacting support.

You may please convert A.pdf into an image, after trimming white space around the image and add resultant image into paragraph collection of B.pdf. You can also visit following useful links, in order to achieve your requirements:

In case you face any issue while implementing desired functionality, please share your sample PDF documents with us. We will test the scenario in our environment and address it accordingly.

Hello,
Thanks for the solution.
I tried the solution provided. But the pdf converted is again an image, so adding it in B.pdf again gives problem during zooming of PDF.
I need a solution, that the image pdf (A.pdf) is converted to vector image, so that the zooming will have no effect on the image when it is appended in the B.pdf

@PriyankaShelke

Thanks for sharing your concerns.

You can please convert PDF document into a SVG (Scaleable Vector Graphics) Image and add it into second PDF document. In order to add SVG image inside PDF Page, you need to specify image type as follows:

Image highChart = new Image() { FileType = ImageFileType.Svg };
highChart.File = imagePath;

// Create new Document
Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
page.Paragraphs.Add(highChart);

In case you still face any issue, please share your sample PDF documents with us. We will test the scenario in our environment and address it accordingly.

I have already tried with this solution but it doesn’t work.

PFA of PDF file which needs to be converted to SVG
Chart.pdf (12.6 KB)

@PriyankaShelke

Thanks for getting back to us.

We have tested the scenario in our environment and managed to observe that API threw System.ArgumentException Exception, while saving PDF document as SVG image. Hence, we have logged an issue as PDFNET-44963 in our issue tracking system. We will further investigate the reasons behind this issue and keep you informed with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

p1.pdf (30.6 KB)

I have found a solution to fetch the image as SVG using 3rd party tool and using your code mentioned above I am able to add the image to PDF as expected.
The problem which I face now is that when I get the image at the bottom of the page and image cannot fit in that available area on page, the image overflows from that page.

PFA

Request you to ignore PDFNET-44963 and provide solution at your earliest for the above mentioned overflow problem

@PriyankaShelke

Thanks for your inquiry.

You may please try adding SVG image inside a table by following “Add SVG Object in Table Cell” article. In your case, you table would have single column of 100% width and in case this suggestion is still unable to resolve the issue, please share your sample SVG image with us. We will test the scenario in our environment and address it accordingly.

Hello,
Thank you for the reference, I visited the page for "Add SVG Object in Table Cell” article but the code is not present in this section.
PFA of the screenshotNo code available.png (34.8 KB)

The svg image I am trying to embed in the pdf is img.zip (1.7 KB)

The image when added in the pdf should have width = 600, height = 375.

PFA of sample code AddImageToTable.zip (487 Bytes)

@PriyankaShelke

Thanks for getting back to us.

We have tested the scenario in our environment and were able to observe the issue. The API was unable to add image inside PDF with specified Height/Width and raised an Exception (i.e. The rectangle size can not be larger page size). However, when we set width of page as 800, the image was added inside PDF document, but it was being cut at the end of the image. After setting less height and width of the image, the image was overlapped inside PDF and output was not as expected. AddSVGObject_out.pdf (29.1 KB)

Code snippet, used for testing:

Document doc = new Document();
// Create an image instance
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
// Set image type as SVG
img.FileType = Aspose.Pdf.ImageFileType.Svg;
// Path for source file
img.File = dataDir + "img.svg";
// Set width for image instance
img.FixWidth = 50;
// Set height for image instance
img.FixHeight = 50;
// Create table instance
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set width for table cells
table.ColumnWidths = "100%";
table.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;
for (int i = 0; i < 10; i++)
{
  // Create row object and add it to table instance
  Aspose.Pdf.Row row = table.Rows.Add();
  // Create cell object and add it to row instance
  Aspose.Pdf.Cell cell = row.Cells.Add();
  // Add SVG image to paragraphs collection of recently added cell instance
  cell.Paragraphs.Add(img);
}
// Create page object and add it to pages collection of document instance
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
//page.PageInfo.Width = 800;
// Add table to paragraphs collection of page object
page.Paragraphs.Add(table);
dataDir = dataDir + "AddSVGObject_out.pdf";
// Save PDF file
doc.Save(dataDir);

We have logged following issues in our issue tracking system:

PDFNET-45015 - Add SVG inside Table Cell - The rectangle size can not be larger page size
PDFNET-45016 - Add SVG inside Table Cell - Image is cut at the end of each page
PDFNET-42590 - SVG images are not sizing properly

We will further investigate logged issues in details and keep you posted with the status of their resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello,

Can I have a detail look at the item - PDFNET-42590

Depending on the description, I would like to move this item to Paid support so that it is resolved asap.

@PriyankaShelke

Thanks for contacting support.

The earlier logged issue is about sizing of SVG image, while adding it inside PDF page. API was not honoring the specified height and width of SVG image in the PDF. Tried code snippet was as follows:

Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.FileType = Aspose.Pdf.ImageFileType.Svg;
img.File = dataDir + "internet.svg";
img.FixWidth = 50;
img.FixHeight = 50;
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "50";
Aspose.Pdf.Row row = table.Rows.Add();
Aspose.Pdf.Cell cell = row.Cells.Add();
cell.Paragraphs.Add(img);
pdfDocument.Pages[1].Paragraphs.Add(table); 

Furthermore, in your specific case, we tried to add image by specifying the same height and width values that you wanted to set for SVG image (width = 600, height = 375) and API threw an exception i.e. The rectangle size can not be larger page size.

We also tried setting less height and width of image and observed that specified size was not being honored by the API in resultant PDF file. That is why, we linked PDFNET-42590 with your post. However, the issue was originally related to this forum thread. In case of any further inquiry, please feel free to ask.

Request you to move the item PDFNET-42590 to paid support. What would be the expected time for resolution of the problem?
I observe that the issue is created in Apr 2017. What is the status of the issue now?

@PriyankaShelke

The issue is still pending for a resolution because of other high priority pending issues. We will try to perform an initial investigation against the issue and try to let you know, how soon it can be resolved in case you move the ticket to paid support. Please spare us little time.

Hello,

I can see that the ticket is not moved to paid support yet.

@PriyankaShelke

We are in process of performing an initial investigation against the issue and will let you know about possible ETA, in case you move this ticket to paid support. As soon as we have investigation results, we will share our feedback with you. Please spare us little time.

Please move this issue to paid support

@PriyankaShelke

In order to move this issue to paid support, you may please login to Paid Support Forums with the same email ID, which was used to subscribe the paid support and post there with the reference to this ticket. Your issue will definitely be escalated to paid support channel. In case you face any issue, please feel free to let us know. We will further proceed to help you out.

We are sorry for the delay and inconvenience caused.

The issues you have found earlier (filed as PDFNET-42590) have been fixed in Aspose.PDF for .NET 18.8.

The issues you have found earlier (filed as PDFNET-44963) have been fixed in Aspose.PDF for .NET 23.9.