Resize Page

Hi,

Is there an option for Resize Page to Drawing while saving pdf as svg?There exists one in Inkscape but I am using Aspose library in my WPF application.

Thanks,
Aruna

@arunasrathore

Thank you for contacting support.

You may Update Page Dimensions as per your requirements and then convert the PDF to SVG.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thank You for you Reply.

I have a drawing in the PDF.There is a margin between the page and the drawing border.Is there a way to get the dimensions of the drawing and then resize the page to it.
I don’t know the dimensions of drawing as It is a pdf exported from AutoCad.

Thanks,
Aruna

@arunasrathore

Would you please share source file and elaborate expected output so that we may investigate further to help you out.

Sample2.pdf (5.2 KB)
Hi,
PFA.
I am trying to to resize page to drawing after or before I convert to SVG i.e I don’t want the margin between the border and the pageI can do the same using Document properties in Inkscape.

Thanks

@arunasrathore

Thank you for sharing requested data.

You may trim white space on a page with below code snippet:

// load the source PDF document
Document document = new Document(dataDir + "Sample2.pdf");

// get page to trim white space
Page pdfPage = document.Pages[1];

// get the content boundaries
Aspose.Pdf.Rectangle contentBBox = pdfPage.CalculateContentBBox();

// set Page CropBox and MediaBox as per content boundries to tirm white
// space
pdfPage.CropBox = (contentBBox);
pdfPage.MediaBox = (contentBBox);

// save the resultant PDF
document.Save(dataDir + "sample2_19.6.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Hi,
Thank you so much for ur help.This works for the pdf.I am converting pdf to svg after this processing.The sample file that I provided works fine when I do that i.e the margins are not seen both in the pdf as well as the svg.But for some other files even though the pdf is updated ,still the converted svg was same with the margins.I am not sure why its not able to use the updated to be converted to svg for those files.
It works when I again import the pdf .

Here is the code for your reference

                           Document doc = new Document(filePath);
	      
	                doc.OptimizeSize = true;
	                doc.FitWindow = true;
	                doc.OptimizeResources();
	               

	                var docPageInfo = doc.PageInfo.Margin;
	                //replace text that might cause issues with the import
	                PdfContentEditor pdfContentEditor = new PdfContentEditor();
	                pdfContentEditor.BindPdf(doc);
	                //replace text on all pages


	                pdfContentEditor.ReplaceText("< ", "&#60; ");


                        // Get particular page
	                // get page to trim white space
	                Page pdfPage = doc.Pages[1];


                    // get the content boundaries
                    Aspose.Pdf.Rectangle contentBBox = pdfPage.CalculateContentBBox();

	                // set Page CropBox and MediaBox as per content boundries to tirm white
	                // space
	                pdfPage.CropBox = (contentBBox);
	                pdfPage.MediaBox = (contentBBox);
                           doc.Save(filePath);
	                
	                // Instantiate an object of SvgSaveOptions
                    
	                Aspose.Pdf.SvgSaveOptions saveOptions = new Aspose.Pdf.SvgSaveOptions();
	                // Do not compress SVG image to Zip archive
	                saveOptions.CompressOutputToZipArchive = false;
                         
	                doc.Save(Path.Combine(_SourceDirectory, fileName + PfdFileTypes.Svg), saveOptions);

@arunasrathore

Thank you for your kind feedback.

Would you please share source and generated ZIP files so that we may try to reproduce it in our environment.

HSample2.pdf (5.2 KB)
Sample2 (2).pdf (5.6 KB)
ello,
Thanks a lot for your support.There has been another issue which I am trying to troubleshoot.
The behaviour with the sample file has been inconsistent in my application.Though I am using the same code now it doesn’t work.I am attaching both the sample file as well as the output pdf.

It now removes the top and right margin only for this file.For doublechecking I downloaded the same which I provided you.

Thanks

@arunasrathore

We are looking into the scenario and will get back to you shortly.

Thank you.I appreciate your help.

Hi,
I would add this,when the fix is working for any file

pdfPage.CropBox = (contentBBox);
pdfPage.MediaBox = (contentBBox);

it seemed the values are not being set for both CropBox and MediaBox.And when it is working the value of CropBox gets set to the same as ContentBBox but the MediaBox is not set.

I am not able to understand this.I thought its almost the opposite behavior of what I expected.

Thanks again

@arunasrathore

Thank you for contacting support.

Would you please try an alternative approach to Trim White-space Around a Page and then share your kind feedback with us so that we may proceed accordingly.

Thank You so much.This solution works for my original files but doesn’t work still for the sample file that I provided you .I am curious as there is not a a fixed set of pdfs in my application and I am looking for a solution which works on any imported pdf.
On the sample file that I provided you,it still only removes the margin on Top and Right.

Thank You

Hi,

Also wanted to convert text to path in the converted svg.Is there a method in ASPOSE to achieve this?

Thank You

@arunasrathore

Thank you for elaborating further.

We have been able to notice problem with trimming on bottom and left side of the page. Therefore, a ticket with ID PDFNET-46562 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

About SVG, would you please create a separate topic while elaborating it so that we may assist you accordingly.

We are sorry for the inconvenience.

Thank youy so much.As you suggested I will create a separate topic for SVG.

@arunasrathore

Thank you for understanding. Please take your time and create the topic as per your convenience. We will take care of your concerns accordingly.

@arunasrathore

We were investigating the problem. If you look at the source file, then in the lower left area there is a graphic element - a dot (see attached image).
I.e., apparently, the cropping is being built correctly, according to the available elements of the image.

46562_pdf_fragment.png (1.6 KB)